Example #1
0
 protected function findObjectByUid($dataType, $uid)
 {
     $query = $this->queryFactory->create($dataType);
     $query->getQuerySettings()->setRespectSysLanguage(FALSE);
     $query->getQuerySettings()->setRespectStoragePage(FALSE);
     return $query->matching($query->equals('uid', intval($uid)))->execute()->getFirst();
 }
 /**
  * Finds an object from the repository by searching for its technical UID.
  *
  * @param int $uid The object's uid
  * @return mixed Either the object matching the uid or, if none or more than one object was found, FALSE
  */
 protected function findObjectByUid($uid)
 {
     $query = $this->queryFactory->create($this->dataType);
     $query->getQuerySettings()->setRespectSysLanguage(FALSE);
     $result = $query->matching($query->equals('uid', $uid))->execute();
     $object = NULL;
     if (count($result) > 0) {
         $object = current($result);
     }
     return $object;
 }
 /**
  * @test
  */
 public function findByUidQueriesObjectAndRegistersItIfItWasNotFoundInIdentityMap()
 {
     $fakeUid = '123';
     $object = new stdClass();
     $this->repository->_set('objectType', 'someObjectType');
     $mockQuerySettings = $this->getMock('Tx_Extbase_Persistence_QuerySettingsInterface');
     $this->mockQuery->expects($this->atLeastOnce())->method('getQuerySettings')->will($this->returnValue($mockQuerySettings));
     $mockQueryResult = $this->getMock('Tx_Extbase_Persistence_QueryResultInterface');
     $this->mockQuery->expects($this->once())->method('equals')->with('uid', $fakeUid)->will($this->returnValue('matchingConstraint'));
     $this->mockQuery->expects($this->once())->method('matching')->with('matchingConstraint')->will($this->returnValue($this->mockQuery));
     $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
     $mockQueryResult->expects($this->once())->method('getFirst')->will($this->returnValue($object));
     $this->mockIdentityMap->expects($this->once())->method('hasIdentifier')->with($fakeUid, 'someObjectType')->will($this->returnValue(FALSE));
     $this->mockIdentityMap->expects($this->once())->method('registerObject')->with($object, $fakeUid);
     $this->mockQueryFactory->expects($this->once())->method('create')->with('someObjectType')->will($this->returnValue($this->mockQuery));
     $expectedResult = $object;
     $actualResult = $this->repository->findByUid($fakeUid);
     $this->assertSame($expectedResult, $actualResult);
 }