예제 #1
0
 /**
  * @covers \BackBee\NestedNode\Repository\NestedNodeRepository::moveAsLastChildOf
  */
 public function testMoveAsLastChildOf()
 {
     $source = $this->repository->find('d-child2');
     $target = $this->repository->find('d-child1');
     $this->repository->moveAsLastChildOf($source, $target);
     self::$em->flush();
     self::$em->clear();
     $this->root_desc = $this->repository->find('d-root');
     $dchild1 = $this->repository->find('d-child1');
     $dsubchild1 = $this->repository->find('d-subchild1');
     $dsubchild2 = $this->repository->find('d-subchild2');
     $dchild2 = $this->repository->find('d-child2');
     $this->assertEquals(1, $this->root_desc->getLeftnode());
     $this->assertEquals(2, $dchild1->getLeftnode());
     $this->assertEquals(3, $dsubchild2->getLeftnode());
     $this->assertEquals(4, $dsubchild2->getRightnode());
     $this->assertEquals(5, $dsubchild1->getLeftnode());
     $this->assertEquals(6, $dsubchild1->getRightnode());
     $this->assertEquals(7, $dchild2->getLeftnode());
     $this->assertEquals(8, $dchild2->getRightnode());
     $this->assertEquals(9, $dchild1->getRightnode());
     $this->assertEquals(10, $this->root_desc->getRightnode());
     $this->assertEquals($dchild1, $dchild2->getParent());
     $this->assertEquals(2, $dchild2->getLevel());
 }
 /**
  * @covers \BackBee\NestedNode\Repository\NestedNodeQueryBuilder::andIsSiblingsOf
  */
 public function testAndIsSiblingsOf()
 {
     $q = $this->repository->createQueryBuilder('n')->andIsSiblingsOf($this->root);
     $this->assertInstanceOf('BackBee\\NestedNode\\Repository\\NestedNodeQueryBuilder', $q);
     $this->assertEquals('SELECT n FROM BackBee\\NestedNode\\Tests\\Mock\\MockNestedNode n WHERE n._uid = :uid0 AND n._parent IS NULL ORDER BY n._leftnode asc', $q->getDql());
     $this->assertEquals($this->root->getUid(), $q->getParameter('uid0')->getValue());
     $q->resetDQLPart('where')->setParameters(array())->andIsSiblingsOf($this->root, true);
     $this->assertEquals('SELECT n FROM BackBee\\NestedNode\\Tests\\Mock\\MockNestedNode n WHERE n._uid != :uid0 AND n._uid = :uid1 AND n._parent IS NULL ORDER BY n._leftnode asc', $q->getDql());
     $this->assertEquals($this->root->getUid(), $q->getParameter('uid0')->getValue());
     $this->assertEquals($this->root->getUid(), $q->getParameter('uid1')->getValue());
     $q->resetDQLPart('where')->setParameters(array())->andIsSiblingsOf($this->root, null, array('_rightnode' => 'desc'));
     $this->assertEquals('SELECT n FROM BackBee\\NestedNode\\Tests\\Mock\\MockNestedNode n WHERE n._uid = :uid0 AND n._parent IS NULL ORDER BY n._rightnode desc', $q->getDql());
     $this->assertEquals($this->root->getUid(), $q->getParameter('uid0')->getValue());
     $child1 = $this->repository->find('child1');
     $q->resetDQLPart('where')->setParameters(array())->andIsSiblingsOf($child1);
     $this->assertEquals('SELECT n FROM BackBee\\NestedNode\\Tests\\Mock\\MockNestedNode n WHERE n._parent = :parent0 ORDER BY n._leftnode asc', $q->getDql());
     $this->assertEquals($this->root, $q->getParameter('parent0')->getValue());
     $q->resetDQLPart('where')->setParameters(array())->andIsSiblingsOf($child1, true);
     $this->assertEquals('SELECT n FROM BackBee\\NestedNode\\Tests\\Mock\\MockNestedNode n WHERE n._uid != :uid0 AND n._parent = :parent1 ORDER BY n._leftnode asc', $q->getDql());
     $this->assertEquals($child1->getUid(), $q->getParameter('uid0')->getValue());
     $this->assertEquals($this->root, $q->getParameter('parent1')->getValue());
     $q->resetDQLPart('where')->setParameters(array())->andIsSiblingsOf($child1, true, array('_rightnode' => 'desc'), 10);
     $this->assertEquals('SELECT n FROM BackBee\\NestedNode\\Tests\\Mock\\MockNestedNode n WHERE n._uid != :uid0 AND n._parent = :parent1 ORDER BY n._rightnode desc', $q->getDql());
     $this->assertEquals($child1->getUid(), $q->getParameter('uid0')->getValue());
     $this->assertEquals($this->root, $q->getParameter('parent1')->getValue());
     $this->assertEquals(10, $q->getMaxResults());
     $this->assertEquals(0, $q->getFirstResult());
     $q->resetDQLPart('where')->setParameters(array())->andIsSiblingsOf($child1, true, array('_rightnode' => 'desc'), 10, 5);
     $this->assertEquals('SELECT n FROM BackBee\\NestedNode\\Tests\\Mock\\MockNestedNode n WHERE n._uid != :uid0 AND n._parent = :parent1 ORDER BY n._rightnode desc', $q->getDql());
     $this->assertEquals($child1->getUid(), $q->getParameter('uid0')->getValue());
     $this->assertEquals($this->root, $q->getParameter('parent1')->getValue());
     $this->assertEquals(10, $q->getMaxResults());
     $this->assertEquals(5, $q->getFirstResult());
 }
 /**
  * @covers BackBee\NestedNode\AbstractNestedNode::setModified
  */
 public function testSetModified()
 {
     $now = new \Datetime();
     $this->assertEquals($this->mock, $this->mock->setModified($now));
     $this->assertEquals($now, $this->mock->getModified());
 }