From 5751295eb8672786ae8325f5015cd3f2e07a3cbe Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 17 Jul 2021 21:12:31 +0200 Subject: [PATCH] phpunit bug fixes --- Theme/Backend/qa-question.tpl.php | 2 +- tests/Models/2QACategoryMapperTest.php | 82 -------------------------- tests/Models/3QAQuestionMapperTest.php | 12 ++-- tests/Models/4QAAnswerMapperTest.php | 10 ++-- tests/Models/QAAnswerTest.php | 7 ++- tests/Models/QACategoryTest.php | 52 ---------------- tests/Models/QAQuestionTest.php | 7 +-- 7 files changed, 18 insertions(+), 154 deletions(-) delete mode 100755 tests/Models/2QACategoryMapperTest.php delete mode 100755 tests/Models/QACategoryTest.php diff --git a/Theme/Backend/qa-question.tpl.php b/Theme/Backend/qa-question.tpl.php index 2f456c8..5086e8b 100755 --- a/Theme/Backend/qa-question.tpl.php +++ b/Theme/Backend/qa-question.tpl.php @@ -44,7 +44,7 @@ echo $this->getData('nav')->render(); -
+
printHtml($question->name); ?>
question; ?>
diff --git a/tests/Models/2QACategoryMapperTest.php b/tests/Models/2QACategoryMapperTest.php deleted file mode 100755 index ce69f3c..0000000 --- a/tests/Models/2QACategoryMapperTest.php +++ /dev/null @@ -1,82 +0,0 @@ -setName('Test Category'); - - $id = QACategoryMapper::create($category); - self::assertGreaterThan(0, $category->getId()); - self::assertEquals($id, $category->getId()); - - $categoryR = QACategoryMapper::get($category->getId()); - self::assertEquals($category->getName(), $categoryR->getName()); - } - - /** - * @covers Modules\QA\Models\QACategoryMapper - * @group module - */ - public function testChildCRUD() : void - { - $category = new QACategory(); - - $category->setName('Test Category2'); - $category->parent = new NullQACategory(1); - - $id = QACategoryMapper::create($category); - self::assertGreaterThan(0, $category->getId()); - self::assertEquals($id, $category->getId()); - - $categoryR = QACategoryMapper::get($category->getId()); - self::assertEquals($category->getName(), $categoryR->getName()); - self::assertEquals($category->parent->getId(), $categoryR->parent->getId()); - } - - /** - * @covers Modules\QA\Models\QACategoryMapper - * @group volume - * @group module - * @coversNothing - */ - public function testVolume() : void - { - for ($i = 1; $i < 30; ++$i) { - $text = new Text(); - $category = new QACategory(); - - $category->setName($text->generateText(\mt_rand(1, 3))); - - $id = QACategoryMapper::create($category); - } - } -} diff --git a/tests/Models/3QAQuestionMapperTest.php b/tests/Models/3QAQuestionMapperTest.php index 16aee15..42664eb 100755 --- a/tests/Models/3QAQuestionMapperTest.php +++ b/tests/Models/3QAQuestionMapperTest.php @@ -14,8 +14,9 @@ declare(strict_types=1); namespace Modules\QA\tests\Models; +use Modules\Profile\Models\Profile; +use Modules\Profile\Models\NullProfile; use Modules\Admin\Models\NullAccount; -use Modules\QA\Models\NullQACategory; use Modules\QA\Models\QAQuestion; use Modules\QA\Models\QAQuestionMapper; use Modules\QA\Models\QAQuestionStatus; @@ -37,8 +38,7 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase $question->name = 'Question Name'; $question->question = 'Question content'; $question->setStatus(QAQuestionStatus::ACTIVE); - $question->setCategory(new NullQACategory(1)); - $question->createdBy = new NullAccount(1); + $question->createdBy = new Profile(new NullAccount(1)); $question->setLanguage('en'); $id = QAQuestionMapper::create($question); @@ -50,8 +50,7 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals($question->question, $questionR->question); self::assertEquals($question->getStatus(), $questionR->getStatus()); self::assertEquals($question->getLanguage(), $questionR->getLanguage()); - self::assertEquals($question->getCategory()->getId(), $questionR->getCategory()->getId()); - self::assertEquals($question->createdBy->getId(), $questionR->createdBy->getId()); + self::assertEquals($question->createdBy->account->getId(), $questionR->createdBy->account->getId()); } /** @@ -68,8 +67,7 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase $question->name = $text->generateText(\mt_rand(1, 3)); $question->question = $text->generateText(\mt_rand(100, 500)); $question->setStatus(QAQuestionStatus::ACTIVE); - $question->setCategory(new NullQACategory(\mt_rand(1, 9))); - $question->createdBy = new NullAccount(1); + $question->createdBy = new Profile(new NullAccount(1)); $question->setLanguage('en'); $id = QAQuestionMapper::create($question); diff --git a/tests/Models/4QAAnswerMapperTest.php b/tests/Models/4QAAnswerMapperTest.php index 1ccd62a..4e0eb15 100755 --- a/tests/Models/4QAAnswerMapperTest.php +++ b/tests/Models/4QAAnswerMapperTest.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace Modules\QA\tests\Models; +use Modules\Profile\Models\Profile; +use Modules\Profile\Models\NullProfile; use Modules\Admin\Models\NullAccount; use Modules\QA\Models\NullQAQuestion; use Modules\QA\Models\QAAnswer; @@ -36,7 +38,7 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase $answer->setAnswer('Answer content'); $answer->setStatus(QAAnswerStatus::ACTIVE); - $answer->createdBy = new NullAccount(1); + $answer->createdBy = new Profile(new NullAccount(1)); $answer->setQuestion(new NullQAQuestion(1)); $answer->setAccepted(true); @@ -48,8 +50,8 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase self::assertEquals($answer->getAnswer(), $answerR->getAnswer()); self::assertEquals($answer->getQuestion()->getId(), $answerR->getQuestion()->getId()); self::assertEquals($answer->getStatus(), $answerR->getStatus()); - self::assertEquals($answer->isAccepted(), $answerR->isAccepted()); - self::assertEquals($answer->createdBy->getId(), $answerR->createdBy->getId()); + self::assertEquals($answer->isAccepted, $answerR->isAccepted); + self::assertEquals($answer->createdBy->account->getId(), $answerR->createdBy->account->getId()); } /** @@ -64,7 +66,7 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase $answer = new QAAnswer(); $answer->setAnswer($text->generateText(\mt_rand(100, 500))); - $answer->createdBy = new NullAccount(1); + $answer->createdBy = new Profile(new NullAccount(1)); $answer->setStatus(QAAnswerStatus::ACTIVE); $answer->setQuestion(new NullQAQuestion(1)); diff --git a/tests/Models/QAAnswerTest.php b/tests/Models/QAAnswerTest.php index beb14c9..82afae2 100755 --- a/tests/Models/QAAnswerTest.php +++ b/tests/Models/QAAnswerTest.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\QA\tests\Models; +use Modules\Profile\Models\NullProfile; use Modules\Admin\Models\NullAccount; use Modules\QA\Models\NullQAQuestion; use Modules\QA\Models\QAAnswer; @@ -35,7 +36,7 @@ class QAAnswerTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $answer->getId()); self::assertEquals('', $answer->getAnswer()); self::assertEquals(0, $answer->getQuestion()->getId()); - self::assertFalse($answer->isAccepted()); + self::assertFalse($answer->isAccepted); self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus()); self::assertEquals(0, $answer->createdBy->getId()); self::assertInstanceOf('\DateTimeImmutable', $answer->createdAt); @@ -52,13 +53,13 @@ class QAAnswerTest extends \PHPUnit\Framework\TestCase $answer->setAnswer('Answer content'); $answer->setStatus(QAAnswerStatus::ACTIVE); $answer->setQuestion(new NullQAQuestion(3)); - $answer->createdBy = new NullAccount(1); + $answer->createdBy = new NullProfile(1); $answer->setAccepted(true); self::assertEquals('Answer content', $answer->getAnswer()); self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus()); self::assertEquals(1, $answer->createdBy->getId()); self::assertEquals(3, $answer->getQuestion()->getId()); - self::assertTrue($answer->isAccepted()); + self::assertTrue($answer->isAccepted); } } diff --git a/tests/Models/QACategoryTest.php b/tests/Models/QACategoryTest.php deleted file mode 100755 index 7585539..0000000 --- a/tests/Models/QACategoryTest.php +++ /dev/null @@ -1,52 +0,0 @@ -getId()); - self::assertEquals('', $category->getName()); - self::assertEquals(0, $category->parent->getId()); - } - - /** - * @covers Modules\QA\Models\QACategory - * @group module - */ - public function testSetGet() : void - { - $category = new QACategory(); - - $category->setName('Category Name'); - $category->parent = new NullQACategory(1); - - self::assertEquals('Category Name', $category->getName()); - self::assertEquals(1, $category->parent->getId()); - } -} diff --git a/tests/Models/QAQuestionTest.php b/tests/Models/QAQuestionTest.php index 46532e7..e16d50b 100755 --- a/tests/Models/QAQuestionTest.php +++ b/tests/Models/QAQuestionTest.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Modules\QA\tests\Models; +use Modules\Profile\Models\NullProfile; use Modules\Admin\Models\NullAccount; -use Modules\QA\Models\NullQACategory; use Modules\QA\Models\QAQuestion; use Modules\QA\Models\QAQuestionStatus; @@ -36,7 +36,6 @@ class QAQuestionTest extends \PHPUnit\Framework\TestCase self::assertEquals('', $question->name); self::assertEquals('', $question->question); self::assertEquals(QAQuestionStatus::ACTIVE, $question->getStatus()); - self::assertEquals(0, $question->getCategory()->getId()); self::assertEquals('', $question->getLanguage()); self::assertEquals(0, $question->createdBy->getId()); self::assertInstanceOf('\DateTimeImmutable', $question->createdAt); @@ -54,15 +53,13 @@ class QAQuestionTest extends \PHPUnit\Framework\TestCase $question->name = 'Question Name'; $question->question = 'Question content'; $question->setStatus(QAQuestionStatus::ACTIVE); - $question->setCategory(new NullQACategory(1)); - $question->createdBy = new NullAccount(1); + $question->createdBy = new NullProfile(1); $question->setLanguage('en'); self::assertEquals('Question Name', $question->name); self::assertEquals('Question content', $question->question); self::assertEquals(QAQuestionStatus::ACTIVE, $question->getStatus()); self::assertEquals('en', $question->getLanguage()); - self::assertEquals(1, $question->getCategory()->getId()); self::assertEquals(1, $question->createdBy->getId()); } }