Skip to content

Commit 908eaee

Browse files
committed
Add failing rootless insert test
1 parent a7f7243 commit 908eaee

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/Gedmo/Tree/NestedTreePositionTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,65 @@ public function testRootTreePositionedInserts()
333333
$this->assertTrue($repo->verify());
334334
}
335335

336+
public function testRootlessTreeTopLevelInserts()
337+
{
338+
$repo = $this->em->getRepository(self::CATEGORY);
339+
340+
// test top level positioned inserts
341+
$fruits = new Category();
342+
$fruits->setTitle('Fruits');
343+
344+
$vegetables = new Category();
345+
$vegetables->setTitle('Vegetables');
346+
347+
$milk = new Category();
348+
$milk->setTitle('Milk');
349+
350+
$meat = new Category();
351+
$meat->setTitle('Meat');
352+
353+
$repo
354+
->persistAsFirstChild($fruits)
355+
->persistAsFirstChild($vegetables)
356+
->persistAsLastChild($milk)
357+
->persistAsLastChild($meat);
358+
359+
$this->em->flush();
360+
361+
$this->assertEquals(3, $fruits->getLeft());
362+
$this->assertEquals(4, $fruits->getRight());
363+
364+
$this->assertEquals(1, $vegetables->getLeft());
365+
$this->assertEquals(2, $vegetables->getRight());
366+
367+
$this->assertEquals(5, $milk->getLeft());
368+
$this->assertEquals(6, $milk->getRight());
369+
370+
$this->assertEquals(7, $meat->getLeft());
371+
$this->assertEquals(8, $meat->getRight());
372+
373+
// test sibling positioned inserts
374+
$cookies = new Category();
375+
$cookies->setTitle('Cookies');
376+
377+
$drinks = new Category();
378+
$drinks->setTitle('Drinks');
379+
380+
$repo
381+
->persistAsNextSiblingOf($cookies, $milk)
382+
->persistAsPrevSiblingOf($drinks, $milk);
383+
384+
$this->em->flush();
385+
386+
$this->assertEquals(5, $drinks->getLeft());
387+
$this->assertEquals(6, $drinks->getRight());
388+
389+
$this->assertEquals(9, $cookies->getLeft());
390+
$this->assertEquals(10, $cookies->getRight());
391+
392+
$this->assertTrue($repo->verify());
393+
}
394+
336395
public function testSimpleTreePositionedInserts()
337396
{
338397
$repo = $this->em->getRepository(self::CATEGORY);

0 commit comments

Comments
 (0)