diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php new file mode 100644 index 0000000..02933e7 --- /dev/null +++ b/tests/Admin/AdminTest.php @@ -0,0 +1,26 @@ +setName('Test Category'); + + $id = WikiAppMapper::create($app); + self::assertGreaterThan(0, $app->getId()); + self::assertEquals($id, $app->getId()); + + $appR = WikiAppMapper::get($app->getId()); + self::assertEquals($app->getName(), $appR->getName()); + } + + /** + * @group volume + * @group module + * @coversNothing + */ + public function testVolume() : void + { + for ($i = 1; $i < 3; ++$i) { + $text = new Text(); + $app = new WikiApp(); + + $app->setName($text->generateText(\mt_rand(1, 3))); + + $id = WikiAppMapper::create($app); + } + } +} diff --git a/tests/Models/WikiAppTest.php b/tests/Models/WikiAppTest.php new file mode 100644 index 0000000..7a30c9f --- /dev/null +++ b/tests/Models/WikiAppTest.php @@ -0,0 +1,54 @@ +app = new WikiApp(); + } + + /** + * @testdox The model has the expected default values after initialization + * @covers Modules\Knowledgebase\Models\WikiApp + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->app->getId()); + self::assertEquals('', $this->app->getName()); + } + + /** + * @testdox The name can be correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiApp + * @group module + */ + public function testNameInputOutput() : void + { + $this->app->setName('Test name'); + self::assertEquals('Test name', $this->app->getName()); + } +} diff --git a/tests/Models/WikiCategoryMapperTest.php b/tests/Models/WikiCategoryMapperTest.php new file mode 100644 index 0000000..a112a6e --- /dev/null +++ b/tests/Models/WikiCategoryMapperTest.php @@ -0,0 +1,88 @@ +category = new WikiCategory(); + } + + /** + * @testdox The model can be created and read from the database + * @covers Modules\Knowledgebase\Models\WikiAppMapper + * @group module + */ + public function testCR() : void + { + $this->category->setName('Test Category'); + + $id = WikiCategoryMapper::create($this->category); + self::assertGreaterThan(0, $this->category->getId()); + self::assertEquals($id, $this->category->getId()); + + $categoryR = WikiCategoryMapper::get($this->category->getId()); + self::assertEquals($this->category->getName(), $categoryR->getName()); + } + + /** + * @testdox The model can be created and read from the database with a parent category + * @covers Modules\Knowledgebase\Models\WikiAppMapper + * @group module + */ + public function testChildCR() : void + { + $this->category->setName('Test Category2'); + $this->category->setParent(new NullWikiCategory(1)); + + $id = WikiCategoryMapper::create($this->category); + self::assertGreaterThan(0, $this->category->getId()); + self::assertEquals($id, $this->category->getId()); + + $categoryR = WikiCategoryMapper::get($this->category->getId()); + self::assertEquals($this->category->getName(), $categoryR->getName()); + self::assertEquals($this->category->getParent()->getId(), $categoryR->getParent()->getId()); + } + + /** + * @group volume + * @group module + * @coversNothing + */ + public function testVolume() : void + { + for ($i = 1; $i < 30; ++$i) { + $text = new Text(); + $category = new WikiCategory(); + + $category->setName($text->generateText(\mt_rand(1, 3))); + + $id = WikiCategoryMapper::create($category); + } + } +} diff --git a/tests/Models/WikiCategoryTest.php b/tests/Models/WikiCategoryTest.php new file mode 100644 index 0000000..3507c97 --- /dev/null +++ b/tests/Models/WikiCategoryTest.php @@ -0,0 +1,93 @@ +category = new WikiCategory(); + } + + + /** + * @testdox The model has the expected default values after initialization + * @covers Modules\Knowledgebase\Models\WikiApp + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->category->getId()); + self::assertEquals(0, $this->category->getApp()->getId()); + self::assertEquals('', $this->category->getName()); + self::assertEquals('/', $this->category->getPath()); + self::assertEquals(0, $this->category->getParent()->getId()); + } + + /** + * @testdox The application can correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiApp + * @group module + */ + public function testAppInputOutput() : void + { + $this->category->setApp(new NullWikiApp(2)); + self::assertEquals(2, $this->category->getApp()->getId()); + } + + /** + * @testdox The name can correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiApp + * @group module + */ + public function testNameInputOutput() : void + { + $this->category->setName('Category Name'); + self::assertEquals('Category Name', $this->category->getName()); + } + + /** + * @testdox The path can correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiApp + * @group module + */ + public function testPathInputOutput() : void + { + $this->category->setPath('/test/path'); + self::assertEquals('/test/path', $this->category->getPath()); + } + + /** + * @testdox The parent can correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiApp + * @group module + */ + public function testParentInputOutput() : void + { + $this->category->setParent(new NullWikiCategory(2)); + self::assertEquals(2, $this->category->getParent()->getId()); + } +} diff --git a/tests/Models/WikiDocMapperTest.php b/tests/Models/WikiDocMapperTest.php new file mode 100644 index 0000000..3e67694 --- /dev/null +++ b/tests/Models/WikiDocMapperTest.php @@ -0,0 +1,77 @@ +setName('Doc Name'); + $doc->setDoc('Doc content'); + $doc->setStatus(WikiStatus::DRAFT); + $doc->setCategory(new NullWikiCategory(1)); + $doc->setLanguage('en'); + + $id = WikiDocMapper::create($doc); + self::assertGreaterThan(0, $doc->getId()); + self::assertEquals($id, $doc->getId()); + + $docR = WikiDocMapper::get($doc->getId()); + self::assertEquals($doc->getName(), $docR->getName()); + self::assertEquals($doc->getDoc(), $docR->getDoc()); + self::assertEquals($doc->getStatus(), $docR->getStatus()); + self::assertEquals($doc->getLanguage(), $docR->getLanguage()); + self::assertEquals($doc->getCategory()->getId(), $docR->getCategory()->getId()); + } + + /** + * @group volume + * @group module + * @coversNothing + */ + public function testVolume() : void + { + for ($i = 1; $i < 30; ++$i) { + $text = new Text(); + $doc = new WikiDoc(); + + $doc->setName($text->generateText(\mt_rand(1, 3))); + $doc->setDoc($text->generateText(\mt_rand(100, 500))); + $doc->setStatus(WikiStatus::ACTIVE); + $doc->setCategory(new NullWikiCategory(\mt_rand(1, 9))); + $doc->setLanguage('en'); + + $id = WikiDocMapper::create($doc); + } + } +} diff --git a/tests/Models/WikiDocTest.php b/tests/Models/WikiDocTest.php new file mode 100644 index 0000000..429021b --- /dev/null +++ b/tests/Models/WikiDocTest.php @@ -0,0 +1,142 @@ +doc = new WikiDoc(); + } + + /** + * @testdox The model has the expected default values after initialization + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function testDefault() : void + { + self::assertEquals(0, $this->doc->getId()); + self::assertEquals(0, $this->doc->getApp()->getId()); + self::assertEquals('', $this->doc->getName()); + self::assertEquals('', $this->doc->getDoc()); + self::assertEquals('', $this->doc->getDocRaw()); + self::assertEquals(WikiStatus::ACTIVE, $this->doc->getStatus()); + self::assertEquals(0, $this->doc->getCategory()->getId()); + self::assertEquals('en', $this->doc->getLanguage()); + self::assertEquals([], $this->doc->getTags()); + } + + /** + * @testdox The application can be correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function tesAppInputOutput() : void + { + $this->doc->setApp(new NullWikiApp(2)); + self::assertEquals(2, $this->doc->getApp()->getId()); + } + + /** + * @testdox The name can be correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function testNameInputOutput() : void + { + $this->doc->setName('Test name'); + self::assertEquals('Test name', $this->doc->getName()); + } + + /** + * @testdox The content can be correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function testDocInputOutput() : void + { + $this->doc->setDoc('Test content'); + self::assertEquals('Test content', $this->doc->getDoc()); + } + + /** + * @testdox The raw content can be correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function testDocRawInputOutput() : void + { + $this->doc->setDocRaw('Test content'); + self::assertEquals('Test content', $this->doc->getDocRaw()); + } + + /** + * @testdox The status can be correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function testStatusInputOutput() : void + { + $this->doc->setStatus(WikiStatus::DRAFT); + self::assertEquals(WikiStatus::DRAFT, $this->doc->getStatus()); + } + + /** + * @testdox The category can be correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function testCategoryInputOutput() : void + { + $this->doc->setCategory(new NullWikiCategory(3)); + self::assertEquals(3, $this->doc->getCategory()->getId()); + } + + /** + * @testdox The language can be correctly set and returned + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function testLanguageInputOutput() : void + { + $this->doc->setLanguage('de'); + self::assertEquals('de', $this->doc->getLanguage()); + } + + /** + * @testdox A tag can be correctly added and returned + * @covers Modules\Knowledgebase\Models\WikiDoc + * @group module + */ + public function testTagInputOutput() : void + { + $this->doc->addTag(new NullTag(5)); + self::assertEquals([new NullTag(5)], $this->doc->getTags()); + } +}