コード例 #1
0
 public function testGetResourceAssociationSet1()
 {
     try {
         //Get the association set where resource set in both ends are visible
         $configuration = null;
         $metadataProvider = $this->_createMetadataAndConfiguration1($configuration);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($metadataProvider, null, $configuration, false);
         $configuration->setEntitySetAccessRule('Customers', EntitySetRights::ALL);
         $configuration->setEntitySetAccessRule('Orders', EntitySetRights::ALL);
         $customersEntitySetWrapper = $metaQueryProverWrapper->resolveResourceSet('Customers');
         $this->assertNotNull($customersEntitySetWrapper);
         $customerEntityType = $metaQueryProverWrapper->resolveResourceType('Customer');
         $this->assertNotNull($customerEntityType);
         $ordersProperty = $customerEntityType->tryResolvePropertyTypeByName('Orders');
         $this->assertNotNull($ordersProperty);
         $associationSet = $metaQueryProverWrapper->getResourceAssociationSet($customersEntitySetWrapper, $customerEntityType, $ordersProperty);
         $this->assertNotNull($associationSet);
         $associationSetEnd1 = $associationSet->getEnd1();
         $this->assertNotNull($associationSetEnd1);
         $associationSetEnd2 = $associationSet->getEnd2();
         $this->assertNotNull($associationSetEnd2);
         $this->assertEquals($associationSetEnd1->getResourceSet()->getName(), 'Customers');
         $this->assertEquals($associationSetEnd2->getResourceSet()->getName(), 'Orders');
         $this->assertEquals($associationSetEnd1->getResourceType()->getName(), 'Customer');
         $this->assertEquals($associationSetEnd2->getResourceType()->getName(), 'Order');
         //Try to get the association set where resource set in one end is invisible
         $configuration = null;
         $metadataProvider = $this->_createMetadataAndConfiguration1($configuration);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($metadataProvider, null, $configuration, false);
         $configuration->setEntitySetAccessRule('Customers', EntitySetRights::ALL);
         //Set orders entity set as invisible
         $configuration->setEntitySetAccessRule('Orders', EntitySetRights::NONE);
         $customersEntitySetWrapper = $metaQueryProverWrapper->resolveResourceSet('Customers');
         $this->assertNotNull($customersEntitySetWrapper);
         $customerEntityType = $metaQueryProverWrapper->resolveResourceType('Customer');
         $this->assertNotNull($customerEntityType);
         $ordersProperty = $customerEntityType->tryResolvePropertyTypeByName('Orders');
         $this->assertNotNull($ordersProperty);
         $associationSet = $metaQueryProverWrapper->getResourceAssociationSet($customersEntitySetWrapper, $customerEntityType, $ordersProperty);
         $this->assertNull($associationSet);
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised' . $exception->getMessage());
     }
 }