Example #1
0
 /**
  * @test
  */
 public function getFirstReturnsNullIfResultSetIsEmptyAndQueryIsNotInitialized()
 {
     $initializedQueryResult = array();
     $queryResult = $this->getAccessibleMock('TYPO3\\FLOW3\\Persistence\\Generic\\QueryResult', array('dummy'), array($this->query));
     $this->query->expects($this->once())->method('setLimit')->with(1);
     $queryResult->injectPersistenceManager($this->persistenceManager);
     $mockDataMapper = $this->getMock('TYPO3\\FLOW3\\Persistence\\Generic\\DataMapper');
     $mockDataMapper->expects($this->once())->method('mapToObjects')->with(array('one', 'two'))->will($this->returnValue($initializedQueryResult));
     $queryResult->injectDataMapper($mockDataMapper);
     $this->assertNull($queryResult->getFirst());
 }
 /**
  * Builds a QOM constraint object for one single constraint expression
  *
  * @param array $constraintDefinition The constraint expression
  * @param \TYPO3\FLOW3\Persistence\QueryInterface $query The query object to build the constraint with
  * @return \TYPO3\FLOW3\Persistence\Generic\Qom\Constraint The build constraint object
  * @throws \TYPO3\FLOW3\Security\Exception\InvalidQueryRewritingConstraintException
  */
 protected function getQomConstraintForSingleConstraintDefinition(array $constraintDefinition, \TYPO3\FLOW3\Persistence\QueryInterface $query)
 {
     if (!is_array($constraintDefinition['leftValue']) && strpos($constraintDefinition['leftValue'], 'this.') === 0) {
         $propertyName = substr($constraintDefinition['leftValue'], 5);
         $operand = $this->getValueForOperand($constraintDefinition['rightValue']);
     } else {
         if (!is_array($constraintDefinition['rightValue']) && strpos($constraintDefinition['rightValue'], 'this.') === 0) {
             $propertyName = substr($constraintDefinition['rightValue'], 5);
             $operand = $this->getValueForOperand($constraintDefinition['leftValue']);
         } else {
             throw new \TYPO3\FLOW3\Security\Exception\InvalidQueryRewritingConstraintException('An entity constraint has to have one operand that references to "this.". Got: "' . $constraintDefinition['leftValue'] . '" and "' . $constraintDefinition['rightValue'] . '"', 1267881842);
         }
     }
     switch ($constraintDefinition['operator']) {
         case '==':
             return $query->equals($propertyName, $operand);
             break;
         case '!=':
             return $query->logicalNot($query->equals($propertyName, $operand));
             break;
         case '<':
             return $query->lessThan($propertyName, $operand);
             break;
         case '>':
             return $query->greaterThan($propertyName, $operand);
             break;
         case '<=':
             return $query->lessThanOrEqual($propertyName, $operand);
             break;
         case '>=':
             return $query->greaterThanOrEqual($propertyName, $operand);
             break;
         case 'in':
             return $query->in($propertyName, $operand);
             break;
         case 'contains':
             return $query->contains($propertyName, $operand);
             break;
         case 'matches':
             $compositeConstraint = NULL;
             foreach ($operand as $operandEntry) {
                 $currentConstraint = $query->contains($propertyName, $operandEntry);
                 if ($compositeConstraint === NULL) {
                     $compositeConstraint = $currentConstraint;
                     continue;
                 }
                 $compositeConstraint = $query->logicalAnd($currentConstraint, $compositeConstraint);
             }
             return $compositeConstraint;
             break;
     }
     throw new \TYPO3\FLOW3\Security\Exception\InvalidQueryRewritingConstraintException('The configured operator of the entity constraint is not valid. Got: ' . $constraintDefinition['operator'], 1270483540);
 }
 /**
  *
  * @param \MongoCollection $collection
  * @param \TYPO3\FLOW3\Persistence\QueryInterface $query
  * @return array
  */
 protected function queryCollection(\MongoCollection $collection, \TYPO3\FLOW3\Persistence\QueryInterface $query)
 {
     $mongoDbQuery = array();
     if ($query->getConstraint() !== NULL) {
         $this->convertConstraint($query->getConstraint(), $mongoDbQuery);
     }
     var_dump($mongoDbQuery);
     return $collection->find($mongoDbQuery);
 }
Example #4
0
 /**
  * Sets up this test case
  *
  */
 public function setUp()
 {
     $this->query = $this->getMockBuilder('TYPO3\\FLOW3\\Persistence\\Doctrine\\Query')->disableOriginalConstructor()->disableOriginalClone()->getMock();
     $this->query->expects($this->any())->method('getResult')->will($this->returnValue(array()));
     $this->queryResult = new \TYPO3\FLOW3\Persistence\Doctrine\QueryResult($this->query);
 }