/**
  * @covers \BackBee\NestedNode\Repository\PageQueryBuilder::hasJoinCriteria
  */
 public function testHasJoinCriteria()
 {
     $this->assertFalse(PageQueryBuilder::hasJoinCriteria());
     $this->assertFalse(PageQueryBuilder::hasJoinCriteria(array('_unknown' => 'fake')));
     $this->assertTrue(PageQueryBuilder::hasJoinCriteria(array('_root' => 'fake')));
     $this->assertTrue(PageQueryBuilder::hasJoinCriteria(array('_parent' => 'fake')));
     $this->assertTrue(PageQueryBuilder::hasJoinCriteria(array('_leftnode' => 'fake')));
     $this->assertTrue(PageQueryBuilder::hasJoinCriteria(array('_rightnode' => 'fake')));
     $this->assertTrue(PageQueryBuilder::hasJoinCriteria(array('_site' => 'fake')));
 }
示例#2
0
 /**
  * Finds a single entity by a set of criteria with automatic join on section if need due to retro-compatibility.
  *
  * @param  array                $criteria           An array of criteria.
  * @param  array|null           $orderBy            Optional, an array of ordering criteria.
  *
  * @return object|null                              The page instance or null if the entity can not be found.
  */
 public function findOneBy(array $criteria, array $orderBy = null)
 {
     if (false === PageQueryBuilder::hasJoinCriteria($criteria) && false === PageQueryBuilder::hasJoinCriteria($orderBy)) {
         return parent::findOneBy($criteria, $orderBy);
     }
     $query = $this->createQueryBuilder('p')->addSearchCriteria($criteria);
     if (false === empty($orderBy)) {
         $query->addMultipleOrderBy($orderBy);
     }
     return $query->getQuery()->getOneOrNullResult();
 }