diff --git a/tests/Entity/StructuralDBElementTest.php b/tests/Entity/Base/AbstractStructuralDBElementTest.php similarity index 84% rename from tests/Entity/StructuralDBElementTest.php rename to tests/Entity/Base/AbstractStructuralDBElementTest.php index 15770aaa..4b124053 100644 --- a/tests/Entity/StructuralDBElementTest.php +++ b/tests/Entity/Base/AbstractStructuralDBElementTest.php @@ -20,7 +20,7 @@ declare(strict_types=1); -namespace App\Tests\Entity; +namespace App\Tests\Entity\Base; use App\Entity\Attachments\AttachmentType; use App\Entity\Parts\Category; @@ -31,7 +31,7 @@ use PHPUnit\Framework\TestCase; * Test StructuralDBElement entities. * Note: Because StructuralDBElement is abstract we use AttachmentType here as a placeholder. */ -class StructuralDBElementTest extends TestCase +class AbstractStructuralDBElementTest extends TestCase { protected $root; protected $child1; @@ -59,6 +59,32 @@ class StructuralDBElementTest extends TestCase $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 { $this->assertTrue($this->root->isRoot()); diff --git a/tests/Repository/StructuralDBElementRepositoryTest.php b/tests/Repository/StructuralDBElementRepositoryTest.php index 071694a4..df0a3552 100644 --- a/tests/Repository/StructuralDBElementRepositoryTest.php +++ b/tests/Repository/StructuralDBElementRepositoryTest.php @@ -117,4 +117,61 @@ class StructuralDBElementRepositoryTest extends WebTestCase $this->assertSame('Node 1.1.1', $nodes[1]->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()); + } }