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);
 }
 /**
  * Generate association type name for a given association set, 
  * this name is used as value of Name attribute of Association type node in the
  * metadata corresponding to the given association set.
  * 
  * Refer ./AssociationSetAndTypeNamingRules.txt for naming rules.
  * 
  * @param ResourceAssociationSet $resourceAssociationSet The association set
  * 
  * @return string The association type name
  */
 private function _getAssociationTypeName(ResourceAssociationSet $resourceAssociationSet)
 {
     $end1 = !is_null($resourceAssociationSet->getEnd1()->getResourceProperty()) ? $resourceAssociationSet->getEnd1() : $resourceAssociationSet->getEnd2();
     $end2 = $resourceAssociationSet->getRelatedResourceAssociationSetEnd($end1->getResourceSet(), $end1->getResourceType(), $end1->getResourceProperty());
     //e.g. Customer_Orders (w.r.t Northwind DB)
     $associationTypeName = $end1->getResourceType()->getName() . '_' . $end1->getResourceProperty()->getName();
     if (!is_null($end2->getResourceProperty())) {
         //Customer_Orders_Order_Customer
         $associationTypeName .= '_' . $end2->getResourceType()->getName() . '_' . $end2->getResourceProperty()->getName();
     }
     return $associationTypeName;
 }
Beispiel #3
0
 /**
  * Write both ends of the given association set.
  * 
  * @param ResourceAssociationSet $associationSet resource association set
  * 
  * @return void
  */
 private function _writeAssocationSetEnds(ResourceAssociationSet $associationSet)
 {
     $associationTypeEnd1 = $associationSet->resourceAssociationType->getResourceAssociationTypeEnd($associationSet->getEnd1()->getResourceType(), $associationSet->getEnd1()->getResourceProperty());
     $associationTypeEnd2 = $associationSet->resourceAssociationType->getResourceAssociationTypeEnd($associationSet->getEnd2()->getResourceType(), $associationSet->getEnd2()->getResourceProperty());
     $this->_xmlWriter->startElement(ODataConstants::END);
     $this->_xmlWriter->writeAttribute(ODataConstants::ROLE, $associationTypeEnd1->getName());
     $this->_xmlWriter->writeAttribute(ODataConstants::ENTITY_SET, $associationSet->getEnd1()->getResourceSet()->getName());
     $this->_xmlWriter->endElement();
     $this->_xmlWriter->startElement(ODataConstants::END);
     $this->_xmlWriter->writeAttribute(ODataConstants::ROLE, $associationTypeEnd2->getName());
     $this->_xmlWriter->writeAttribute(ODataConstants::ENTITY_SET, $associationSet->getEnd2()->getResourceSet()->getName());
     $this->_xmlWriter->endElement();
 }
 /**
  * Test ResourceAssociationSet class
  * Note: ResourceAssociationSet is an internal class used for metadata generation, not suppose to used by the developers 
  */
 public function testResourceAssociationSet()
 {
     $customerResType = $this->_getCustomerResourceType();
     $customerResourceSet = new ResourceSet('Customers', $customerResType);
     $orderResType = $this->_getOrderResourceType();
     $orderResourceSet = new ResourceSet('Orders', $orderResType);
     $customerReferenceProperty = new ResourceProperty('Customer', null, ResourcePropertyKind::RESOURCE_REFERENCE, $customerResType);
     $ordersReferenceSetProperty = new ResourceProperty('Orders', null, ResourcePropertyKind::RESOURCESET_REFERENCE, $orderResType);
     $customerResType->addProperty($ordersReferenceSetProperty);
     $orderResType->addProperty($customerReferenceProperty);
     $assoSetEnd1 = new ResourceAssociationSetEnd($customerResourceSet, $customerResType, $ordersReferenceSetProperty);
     $assoSetEnd2 = new ResourceAssociationSetEnd($orderResourceSet, $orderResType, $customerReferenceProperty);
     $assoSet = new ResourceAssociationSet('Orders_Customers', $assoSetEnd1, $assoSetEnd2);
     $this->assertEquals($assoSet->getName(), 'Orders_Customers');
     $this->assertSame($assoSet->getEnd1(), $assoSetEnd1);
     $this->assertSame($assoSet->getEnd2(), $assoSetEnd2);
     $actual = $assoSet->getResourceAssociationSetEnd($customerResourceSet, $customerResType, $ordersReferenceSetProperty);
     $this->assertSame($assoSetEnd1, $actual);
     $actual = $assoSet->getRelatedResourceAssociationSetEnd($customerResourceSet, $customerResType, $ordersReferenceSetProperty);
     $this->assertSame($assoSetEnd2, $actual);
 }