Ejemplo n.º 1
0
 /**
  * true if the clause returns results when applied
  * to the attributes of the authenticated user
  * false if not
  *
  * @param int $userId
  * @param string $clause
  *
  * @return boolean
  */
 private function evaluateSingleClause($userId, $clause)
 {
     /*
      * run dependency check
      */
     $this->checkDependencies();
     $entityManager = $this->entityManager;
     /*
      * apply the standard integer input filter to $userId
      */
     $userId = $this->filterIntegerInput($userId);
     /*
      * apply the standard string input filter to the $clause
      */
     $clause = $this->filterStringInput($clause);
     if (empty($clause)) {
         return true;
     } else {
         /*
          * build the dql expression to pass to the entity manager
          */
         $dql = sprintf("SELECT a FROM %s a JOIN a.user u WHERE u.status = %s AND u.id = %s AND a.removed is null AND ( %s )", Attribute::getEntityClass(), User::STATUS_ACTIVE, $userId, $clause);
         $query = $entityManager->createQuery($dql);
         $results = $query->getResult();
         /*
          * append the results to the $cachedAttributes
          */
         $this->cachedAttributes = array_merge($this->cachedAttributes, $results);
         return count($results) > 0;
     }
 }
Ejemplo n.º 2
0
 /**
  * asserts that the User is being passed to the Attribute by reference
  * by making changes to the behavior of the User after it is injected
  * into the Attribute
  *
  * @param string $methodName
  * @param string $expectedValue
  *
  * @dataProvider providerTestThatUserPropertyIsPassedByReference
  */
 public function testThatUserPropertyIsPassedByReference($methodName, $expectedValue)
 {
     /*
      * create a mock User
      */
     $user = $this->getMockBuilder('Acl\\Entity\\User')->getMock();
     /*
      * instatiate the Attribute and inject the mock User
      */
     $attribute = new Attribute();
     $attribute->setUser($user);
     /*
      * change the behavior of the original mock User
      */
     $user->expects($this->once())->method($methodName)->will($this->returnValue($expectedValue));
     $actualValue = $attribute->getUser()->{$methodName}();
     $errorMessage = sprintf("call to User::%s on user injected into Attribute is not consistent with the test value ofg injected", $methodName);
     $this->assertEquals($expectedValue, $actualValue, $errorMessage);
 }
Ejemplo n.º 3
0
 /**
  *
  * @param Attribute $attribute
  *
  * @return $this
  */
 public function addAttribute(Attribute $attribute)
 {
     $this->attributes[] = $attribute;
     $attribute->setUser($this);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * data sets for $this::testCollectionPropertyAccessors()
  *
  * @return array
  */
 public function providerTestCollectionPropertyAccessors()
 {
     $attribute = new Attribute();
     $session = new Session();
     return array(array('Attribute', $attribute), array('Attribute', $attribute->setName('TestProperty')), array('Attribute', $attribute->setValue('TestPropteryValue')), array('Session', $session));
 }