Added some tests

This commit is contained in:
Jan Böhmer 2023-01-30 22:42:07 +01:00
parent 60446edd68
commit 25be76b311
2 changed files with 85 additions and 2 deletions

View file

@ -20,7 +20,7 @@
declare(strict_types=1); declare(strict_types=1);
namespace App\Tests\Entity; namespace App\Tests\Entity\Base;
use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\AttachmentType;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
@ -31,7 +31,7 @@ use PHPUnit\Framework\TestCase;
* Test StructuralDBElement entities. * Test StructuralDBElement entities.
* Note: Because StructuralDBElement is abstract we use AttachmentType here as a placeholder. * Note: Because StructuralDBElement is abstract we use AttachmentType here as a placeholder.
*/ */
class StructuralDBElementTest extends TestCase class AbstractStructuralDBElementTest extends TestCase
{ {
protected $root; protected $root;
protected $child1; protected $child1;
@ -59,6 +59,32 @@ class StructuralDBElementTest extends TestCase
$this->child1_2->setName('child1_2')->setParent($this->child1); $this->child1_2->setName('child1_2')->setParent($this->child1);
} }
public function testSetParent(): void
{
$el1 = new AttachmentType();
$el2 = new AttachmentType();
$el2->setParent($el1);
//Check if parent was set correctly
$this->assertSame($el1, $el2->getParent());
//El2 must now be a child of el1
$this->assertTrue($el1->getChildren()->contains($el2));
}
public function testAddChild(): void
{
$el1 = new AttachmentType();
$el2 = new AttachmentType();
$el1->addChild($el2);
//Check if parent was set correctly
$this->assertSame($el1, $el2->getParent());
//El2 must now be a child of el1
$this->assertTrue($el1->getChildren()->contains($el2));
}
public function testIsRoot(): void public function testIsRoot(): void
{ {
$this->assertTrue($this->root->isRoot()); $this->assertTrue($this->root->isRoot());

View file

@ -117,4 +117,61 @@ class StructuralDBElementRepositoryTest extends WebTestCase
$this->assertSame('Node 1.1.1', $nodes[1]->getName()); $this->assertSame('Node 1.1.1', $nodes[1]->getName());
$this->assertSame('Node 1.2', $nodes[2]->getName()); $this->assertSame('Node 1.2', $nodes[2]->getName());
} }
public function testGetNewEntityFromDB(): void
{
$path = 'Node 1/ Node 1.1 /Node 1.1.1';
$nodes = $this->repo->getNewEntityFromPath($path, '/');
$this->assertSame('Node 1', $nodes[0]->getName());
//Node must be from DB
$this->assertNotNull( $nodes[0]->getID());
$this->assertSame('Node 1.1', $nodes[1]->getName());
//Node must be from DB
$this->assertNotNull( $nodes[1]->getID());
$this->assertSame('Node 1.1.1', $nodes[2]->getName());
//Node must be from DB
$this->assertNotNull( $nodes[2]->getID());
}
public function testGetNewEntityNew(): void
{
$path = 'Element 1-> Element 1.1 ->Element 1.1.1';
$nodes = $this->repo->getNewEntityFromPath($path);
$this->assertSame('Element 1', $nodes[0]->getName());
//Node must not be from DB
$this->assertNull( $nodes[0]->getID());
$this->assertSame('Element 1.1', $nodes[1]->getName());
//Node must not be from DB
$this->assertNull( $nodes[1]->getID());
$this->assertSame('Element 1.1.1', $nodes[2]->getName());
//Node must not be from DB
$this->assertNull( $nodes[2]->getID());
}
public function testGetNewEntityMixed(): void
{
$path = 'Node 1-> Node 1.1 -> New Node';
$nodes = $this->repo->getNewEntityFromPath($path);
$this->assertSame('Node 1', $nodes[0]->getName());
//Node must be from DB
$this->assertNotNull( $nodes[0]->getID());
$this->assertSame('Node 1.1', $nodes[1]->getName());
//Node must be from DB
$this->assertNotNull( $nodes[1]->getID());
$this->assertSame('New Node', $nodes[2]->getName());
//Node must not be from DB
$this->assertNull( $nodes[2]->getID());
}
} }