Esempio n. 1
0
 public function testRegisterWritersV3()
 {
     /** @var BaseService $service */
     $service = Phockito::spy('\\POData\\BaseService');
     $service->setHost($this->mockHost);
     //TODO: have to do this since the registry & config is actually only instantiated during a handleRequest
     //will change this once that request pipeline is cleaned up
     Phockito::when($service->getODataWriterRegistry())->return($this->mockRegistry);
     $fakeConfig = new ServiceConfiguration($this->mockMetaProvider);
     $fakeConfig->setMaxDataServiceVersion(ProtocolVersion::V3());
     Phockito::when($service->getConfiguration())->return($fakeConfig);
     //fake the service url
     $fakeUrl = "http://host/service.svc/Collection";
     Phockito::when($this->mockHost->getAbsoluteServiceUri())->return(new Url($fakeUrl));
     Phockito::verify($this->mockRegistry, 0)->register(anything());
     //nothing should be registered at first
     $service->registerWriters();
     //only 2 writers for v1
     Phockito::verify($this->mockRegistry, 6)->register(anything());
     Phockito::verify($this->mockRegistry, 1)->register(anInstanceOf('\\POData\\Writers\\Atom\\AtomODataWriter'));
     Phockito::verify($this->mockRegistry, 5)->register(anInstanceOf('\\POData\\Writers\\Json\\JsonODataV1Writer'));
     //since v2 & light derives from this,,it's 1+1+3 times
     Phockito::verify($this->mockRegistry, 4)->register(anInstanceOf('\\POData\\Writers\\Json\\JsonODataV2Writer'));
     //since light derives from this it's 1+3 times
     Phockito::verify($this->mockRegistry, 3)->register(anInstanceOf('\\POData\\Writers\\Json\\JsonLightODataWriter'));
 }
Esempio n. 2
0
 /**
  * This method is called only once to initialize service-wide policies
  * 
  * @param ServiceConfiguration $config Data service configuration object
  * 
  * @return void
  */
 public function initialize(ServiceConfiguration $config)
 {
     $config->setEntitySetPageSize('*', 5);
     $config->setEntitySetAccessRule('*', EntitySetRights::ALL);
     $config->setAcceptCountRequests(true);
     $config->setAcceptProjectionRequests(true);
     $config->setMaxDataServiceVersion(ProtocolVersion::V3());
 }
Esempio n. 3
0
 /**
  * This method is called only once to initialize service-wide policies
  * 
  * @param ServiceConfiguration $config
  */
 public function initialize(ServiceConfiguration $config)
 {
     $config->setEntitySetAccessRule('*', EntitySetRights::ALL);
     //we are using V1 protocol, but still we set page size because with
     //a top value which is less than pagesize we can use V1 protocol
     //even though paging is enabled.
     $config->setEntitySetPageSize('*', 5);
     $config->setAcceptCountRequests(true);
     $config->setAcceptProjectionRequests(true);
     $config->setMaxDataServiceVersion(ProtocolVersion::V1());
 }
Esempio n. 4
0
 public function testWriteMetadata()
 {
     $northWindMetadata = NorthWindMetadata::Create();
     $configuration = new ServiceConfiguration($northWindMetadata);
     $configuration->setEntitySetAccessRule("*", EntitySetRights::ALL);
     $configuration->setMaxDataServiceVersion(ProtocolVersion::V3());
     $providersWrapper = new ProvidersWrapper($northWindMetadata, $this->mockQueryProvider, $configuration, false);
     $metadataWriter = new MetadataWriter($providersWrapper);
     $metadata = $metadataWriter->writeMetadata();
     $this->assertNotNull($metadata);
     $this->assertEquals($providersWrapper->getContainerName(), 'NorthWindEntities');
     $this->assertEquals($providersWrapper->getContainerNamespace(), 'NorthWind');
     $this->assertStringStartsWith('<edmx:Edmx Version="1.0"', $metadata);
     $customerResourceSet = $providersWrapper->resolveResourceSet('Customers');
     $this->assertEquals($customerResourceSet->getName(), 'Customers');
     $this->assertEquals($customerResourceSet->getResourceType()->getName(), 'Customer');
     $customerEntityType = $providersWrapper->resolveResourceType('Customer');
     $this->assertEquals($customerEntityType->getResourceTypeKind(), ResourceTypeKind::ENTITY);
 }
Esempio n. 5
0
 public function testProcessRequestForCollectionWithInlineCountProviderHandlesPaging()
 {
     $requestURI = new Url('http://host.com/data.svc/Collection/?$inlinecount=allpages');
     Phockito::when($this->mockServiceHost->getAbsoluteRequestUri())->return($requestURI);
     //mock inline count as all pages
     Phockito::when($this->mockServiceHost->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_INLINECOUNT))->return("allpages");
     $this->fakeServiceConfig->setAcceptCountRequests(true);
     $this->fakeServiceConfig->setMaxDataServiceVersion(ProtocolVersion::V2());
     $uriProcessor = UriProcessor::process($this->mockService);
     $fakeQueryResult = new QueryResult();
     $fakeQueryResult->results = array(1, 2, 3);
     $fakeQueryResult->count = 10;
     Phockito::when($this->mockProvidersWrapper->getResourceSet(QueryType::ENTITIES_WITH_COUNT(), $this->mockCollectionResourceSetWrapper, null, null, null, null))->return($fakeQueryResult);
     //indicate that the Provider performs the paging (thus it will use the count in the QueryResult)
     Phockito::when($this->mockProvidersWrapper->handlesOrderedPaging())->return(true);
     $uriProcessor->execute();
     $request = $uriProcessor->getRequest();
     $actual = $request->getTargetResult();
     $this->assertEquals(array(1, 2, 3), $actual);
     $this->assertEquals(10, $request->getCountValue());
 }