Beispiel #1
0
 /**
  * Gets the ResourceAssociationSet instance for the given source association end,
  * Note: Wrapper for IMetadataProvider::getResourceAssociationSet
  * method implementation
  * 
  * @param ResourceSet $set Resource set of the source association end
  * @param ResourceType       $type       Resource type of the source association end
  * @param ResourceProperty   $property   Resource property of the source association end
  *
  * 
  * @return ResourceAssociationSet|null Returns ResourceAssociationSet for the source
  *                                             association end, NULL if no such 
  *                                             association end or resource set in the
  *                                             other end of the association is invisible
  */
 public function getResourceAssociationSet(ResourceSet $set, ResourceType $type, ResourceProperty $property)
 {
     $type = $this->_getResourceTypeWherePropertyIsDeclared($type, $property);
     $cacheKey = $set->getName() . '_' . $type->getName() . '_' . $property->getName();
     if (array_key_exists($cacheKey, $this->associationSetCache)) {
         return $this->associationSetCache[$cacheKey];
     }
     $associationSet = $this->metaProvider->getResourceAssociationSet($set, $type, $property);
     if (!is_null($associationSet)) {
         $thisAssociationSetEnd = $associationSet->getResourceAssociationSetEnd($set, $type, $property);
         $relatedAssociationSetEnd = $associationSet->getRelatedResourceAssociationSetEnd($set, $type, $property);
         //If $thisAssociationSetEnd or $relatedAssociationSetEnd
         //is null means the associationset
         //we got from the IDSMP::getResourceAssociationSet is invalid.
         //AssociationSet::getResourceAssociationSetEnd
         //return null, if AssociationSet's End1 or End2's resourceset name
         //is not matching with the name of
         //resource set wrapper (param1) and resource type is not assignable
         //from given resource type (param2)
         if (is_null($thisAssociationSetEnd) || is_null($relatedAssociationSetEnd)) {
             throw new ODataException(Messages::providersWrapperIDSMPGetResourceSetReturnsInvalidResourceSet($set->getName(), $type->getFullName(), $property->getName()), 500);
         }
         $relatedResourceSetWrapper = $this->_validateResourceSetAndGetWrapper($relatedAssociationSetEnd->getResourceSet());
         if ($relatedResourceSetWrapper === null) {
             $associationSet = null;
         } else {
             $this->_validateResourceType($thisAssociationSetEnd->getResourceType());
             $this->_validateResourceType($relatedAssociationSetEnd->getResourceType());
         }
     }
     $this->associationSetCache[$cacheKey] = $associationSet;
     return $associationSet;
 }
 public function testGetResourceAssociationSetEndIsNotVisible()
 {
     $fakePropName = "Fake Prop";
     Phockito::when($this->mockResourceProperty->getName())->return($fakePropName);
     Phockito::when($this->mockResourceType->resolvePropertyDeclaredOnThisType($fakePropName))->return($this->mockResourceProperty);
     $fakeTypeName = "Fake Type";
     Phockito::when($this->mockResourceType->getName())->return($fakeTypeName);
     $fakeSetName = "Fake Set";
     Phockito::when($this->mockResourceSet->getName())->return($fakeSetName);
     Phockito::when($this->mockResourceSet->getResourceType())->return($this->mockResourceType);
     Phockito::when($this->mockResourceSet2->getResourceType())->return($this->mockResourceType2);
     //Indicate the resource set is visible
     Phockito::when($this->mockServiceConfig->getEntitySetAccessRule($this->mockResourceSet))->return(EntitySetRights::READ_SINGLE);
     //Indicate the resource set is visible
     Phockito::when($this->mockServiceConfig->getEntitySetAccessRule($this->mockResourceSet2))->return(EntitySetRights::NONE);
     Phockito::when($this->mockMetadataProvider->getResourceAssociationSet($this->mockResourceSet, $this->mockResourceType, $this->mockResourceProperty))->return($this->mockResourceAssociationSet);
     Phockito::when($this->mockResourceAssociationSet->getResourceAssociationSetEnd($this->mockResourceSet, $this->mockResourceType, $this->mockResourceProperty))->return($this->mockResourceAssociationSetEnd);
     Phockito::when($this->mockResourceAssociationSet->getRelatedResourceAssociationSetEnd($this->mockResourceSet, $this->mockResourceType, $this->mockResourceProperty))->return($this->mockResourceAssociationSetEnd);
     Phockito::when($this->mockResourceAssociationSetEnd->getResourceSet())->return($this->mockResourceSet2);
     Phockito::when($this->mockResourceAssociationSetEnd->getResourceType())->return($this->mockResourceType2);
     $wrapper = $this->getMockedWrapper();
     $actual = $wrapper->getResourceAssociationSet($this->mockResourceSet, $this->mockResourceType, $this->mockResourceProperty);
     $this->assertNull($actual);
 }