mirror of
https://github.com/Karaka-Management/oms-Knowledgebase.git
synced 2026-01-24 15:28:40 +00:00
add tests
This commit is contained in:
parent
be700eae0c
commit
7ce28c4038
26
tests/Admin/AdminTest.php
Normal file
26
tests/Admin/AdminTest.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Knowledgebase\Admin;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class AdminTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected const MODULE_NAME = 'Knowledgebase';
|
||||
protected const URI_LOAD = 'http://127.0.0.1/en/backend/wiki';
|
||||
|
||||
use \Modules\tests\ModuleTestTrait;
|
||||
}
|
||||
63
tests/Models/WikiAppMapperTest.php
Normal file
63
tests/Models/WikiAppMapperTest.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Knowledgebase\Models;
|
||||
|
||||
use Modules\Knowledgebase\Models\WikiApp;
|
||||
use Modules\Knowledgebase\Models\WikiAppMapper;
|
||||
use phpOMS\Utils\RnG\Text;
|
||||
|
||||
/**
|
||||
* @testdox Modules\tests\Knowledgebase\Models\WikiAppMapperTest: Wiki application mapper
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class WikiAppMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The model can be created and read from the database
|
||||
* @covers Modules\Knowledgebase\Models\WikiAppMapper
|
||||
* @group module
|
||||
*/
|
||||
public function testCR() : void
|
||||
{
|
||||
$app = new WikiApp();
|
||||
|
||||
$app->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
tests/Models/WikiAppTest.php
Normal file
54
tests/Models/WikiAppTest.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Knowledgebase\Models;
|
||||
|
||||
use Modules\Knowledgebase\Models\WikiApp;
|
||||
|
||||
/**
|
||||
* @testdox Modules\tests\Knowledgebase\Models\WikiAppTest: Wiki application
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class WikiAppTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected WikiApp $app;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
}
|
||||
88
tests/Models/WikiCategoryMapperTest.php
Normal file
88
tests/Models/WikiCategoryMapperTest.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Knowledgebase\Models;
|
||||
|
||||
use Modules\Knowledgebase\Models\NullWikiCategory;
|
||||
use Modules\Knowledgebase\Models\WikiCategory;
|
||||
use Modules\Knowledgebase\Models\WikiCategoryMapper;
|
||||
use phpOMS\Utils\RnG\Text;
|
||||
|
||||
/**
|
||||
* @testdox Modules\tests\Knowledgebase\Models\WikiCategoryMapperTest: Wiki category mapper
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class WikiCategoryMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected WikiCategory $category;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
93
tests/Models/WikiCategoryTest.php
Normal file
93
tests/Models/WikiCategoryTest.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Knowledgebase\Models;
|
||||
|
||||
use Modules\Knowledgebase\Models\NullWikiApp;
|
||||
use Modules\Knowledgebase\Models\NullWikiCategory;
|
||||
use Modules\Knowledgebase\Models\WikiCategory;
|
||||
|
||||
/**
|
||||
* @testdox Modules\tests\Knowledgebase\Models\WikiCateboryTest: Wiki category
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class WikiCategoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected WikiCategory $category;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
}
|
||||
77
tests/Models/WikiDocMapperTest.php
Normal file
77
tests/Models/WikiDocMapperTest.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Knowledgebase\Models;
|
||||
|
||||
use Modules\Knowledgebase\Models\NullWikiCategory;
|
||||
use Modules\Knowledgebase\Models\WikiDoc;
|
||||
use Modules\Knowledgebase\Models\WikiDocMapper;
|
||||
use Modules\Knowledgebase\Models\WikiStatus;
|
||||
use phpOMS\Utils\RnG\Text;
|
||||
|
||||
/**
|
||||
* @testdox Modules\tests\Knowledgebase\Models\WikiDocMapperTest: Wiki document mapper
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class WikiDocMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The model can be created and read from the database
|
||||
* @covers Modules\Knowledgebase\Models\WikiDocMapper
|
||||
* @group module
|
||||
*/
|
||||
public function testCR() : void
|
||||
{
|
||||
$doc = new WikiDoc();
|
||||
|
||||
$doc->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
142
tests/Models/WikiDocTest.php
Normal file
142
tests/Models/WikiDocTest.php
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\tests\Knowledgebase\Models;
|
||||
|
||||
use Modules\Knowledgebase\Models\NullWikiApp;
|
||||
use Modules\Knowledgebase\Models\NullWikiCategory;
|
||||
use Modules\Knowledgebase\Models\WikiDoc;
|
||||
use Modules\Knowledgebase\Models\WikiStatus;
|
||||
use Modules\Tag\Models\NullTag;
|
||||
|
||||
/**
|
||||
* @testdox Modules\tests\Knowledgebase\Models\WikiDocTest: Wiki document
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class WikiDocTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected WikiDoc $doc;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->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());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user