public function initialize(ServiceConfiguration $config) { $config->setEntitySetPageSize('*', $this->maxPageSize); $config->setEntitySetAccessRule('*', EntitySetRights::ALL); $config->setAcceptCountRequests(true); $config->setAcceptProjectionRequests(true); }
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')); }
/** * Test search InternalSkipTokenInfo::GetIndexOfFirstEntryInNextPage function */ public function testGetIndexOfFirstEntryInNextPage2() { $this->markTestSkipped("Skipped because it depends on a query provider that isn't mocked"); $northWindMetadata = NorthWindMetadata::Create(); $configuration = new ServiceConfiguration($northWindMetadata); $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL); $providersWrapper = new ProvidersWrapper($northWindMetadata, $this->mockQueryProvider, $configuration); $resourceSetWrapper = $providersWrapper->resolveResourceSet('Orders'); $resourceType = $resourceSetWrapper->getResourceType(); $orderBy = 'ShipName asc, Freight'; //Note: library will add prim key as last sort key $orderBy .= ', OrderID'; $qp = new NorthWindQueryProvider1(); $orders = $qp->getResourceSet($resourceSetWrapper->getResourceSet()); $internalOrderByInfo = OrderByParser::parseOrderByClause($resourceSetWrapper, $resourceType, $orderBy, $providersWrapper); $compFun = $internalOrderByInfo->getSorterFunction(); $fun = $compFun->getReference(); usort($orders, $fun); $numRecords = count($orders); //----------------------------------------------------------------- //Search with a key that exactly matches $skipToken = utf8_decode(urldecode("'Antonio%20Moreno%20Taquer%C3%ADa',22.0000M,10365")); $skipToken = urldecode($skipToken); $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($resourceType, $internalOrderByInfo, $skipToken); $nextIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($orders); $this->assertTrue($nextIndex > 1); $this->assertTrue($nextIndex < $numRecords); //$nextIndex is the index of order record next to the searched record $this->assertEquals($orders[$nextIndex - 1]->OrderID, 10365); $this->assertEquals($orders[$nextIndex - 1]->Freight, 22.0); //----------------------------------------------------------------- //Search with a key that partially matches, in the DB there is no //order with ShipName 'An', but there are records start with //'An', so partial match, since its a parial match other two //key wont be used for comparsion $skipToken = "'An',22.0000M,10365"; $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($resourceType, $internalOrderByInfo, $skipToken); $nextIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($orders); $this->assertTrue($nextIndex > 1); $this->assertTrue($nextIndex < $numRecords); //Make sure this is the most matching record by comparing with previous record $prevOrder = $orders[$nextIndex - 1]; $r = strcmp($prevOrder->ShipName, $orders[$nextIndex]->ShipName); $this->assertTrue($r < 0); //Make sure this is the most matching record by comparing with next record $nextOrder = $orders[$nextIndex + 1]; $r = strcmp($nextOrder->ShipName, $orders[$nextIndex]->ShipName); $this->assertTrue($r >= 0); //----------------------------------------------------------------- //Search with a key that does not exists $skipToken = "'XXX',11,10365"; $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($resourceType, $internalOrderByInfo, $skipToken); $nextIndex = $internalSkipTokenInfo->getIndexOfFirstEntryInTheNextPage($orders); $this->assertTrue($nextIndex == -1); //----------------------------------------------------------------- }
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); }
public function testConfiguration4() { $customersResourceSet = $this->_northWindMetadata->resolveResourceSet('Customers'); $this->assertNotNull($customersResourceSet); $this->AssertEquals($this->_dataServiceConfiguration->getEntitySetAccessRule($customersResourceSet), EntitySetRights::NONE); try { $this->_dataServiceConfiguration->setEntitySetAccessRule('Customers', EntitySetRights::ALL + 1); $this->fail('An expected InvalidOperationException for \'page size and max result per collection mutual exclusion\' was not thrown for month'); } catch (\InvalidArgumentException $exception) { $this->AssertEquals('The argument \'$rights\' of \'setEntitySetAccessRule\' should be EntitySetRights enum value', $exception->getMessage()); } $this->_dataServiceConfiguration->setEntitySetAccessRule('Customers', EntitySetRights::READ_ALL); $this->AssertEquals($this->_dataServiceConfiguration->getEntitySetAccessRule($customersResourceSet), EntitySetRights::READ_ALL); try { $this->_dataServiceConfiguration->setEntitySetAccessRule('NonExistEntitySet', EntitySetRights::READ_MULTIPLE); $this->fail('An expected InvalidArgumentException for \'non-exist entity set name\' was not thrown for month'); } catch (\InvalidArgumentException $exception) { $this->AssertEquals('The given name \'NonExistEntitySet\' was not found in the entity sets', $exception->getMessage()); } }
/** * 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()); }
public function testGetResourceSetsSecondOneIsNotVisible() { $fakeSets = array($this->mockResourceSet, $this->mockResourceSet2); Phockito::when($this->mockMetadataProvider->getResourceSets())->return($fakeSets); Phockito::when($this->mockResourceSet->getName())->return("fake name 1"); Phockito::when($this->mockResourceSet2->getName())->return("fake name 2"); Phockito::when($this->mockResourceSet->getResourceType())->return($this->mockResourceType); Phockito::when($this->mockResourceSet2->getResourceType())->return($this->mockResourceType); Phockito::when($this->mockServiceConfig->getEntitySetAccessRule($this->mockResourceSet))->return(EntitySetRights::NONE); Phockito::when($this->mockServiceConfig->getEntitySetAccessRule($this->mockResourceSet2))->return(EntitySetRights::READ_SINGLE); $wrapper = $this->getMockedWrapper(); $actual = $wrapper->getResourceSets(); $expected = array(new ResourceSetWrapper($this->mockResourceSet2, $this->mockServiceConfig)); $this->assertEquals($expected, $actual); }
/** * 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()); }
public function testGetResponseVersionConfigMaxVersion30RequestVersion30RequestMaxVersion30() { $requestVersion = "3.0"; $requestMaxVersion = "3.0"; $fakeConfigMaxVersion = Version::v3(); Phockito::when($this->mockServiceConfiguration->getMaxDataServiceVersion())->return($fakeConfigMaxVersion); $fakeURL = new Url("http://host/service.svc/Collection"); $fakeSegments = array(new SegmentDescriptor()); $request = new RequestDescription($fakeSegments, $fakeURL, $fakeConfigMaxVersion, $requestVersion, $requestMaxVersion); //This respects the max version $this->assertEquals(Version::v3(), $request->getResponseVersion()); $request->raiseResponseVersion(2, 0); //max is already 3, so this is allowed $this->assertEquals(Version::v3(), $request->getResponseVersion()); $request->raiseResponseVersion(3, 0); //max is already 3 ditto $this->assertEquals(Version::v3(), $request->getResponseVersion()); }
/** * If last sub path segment specified in the select clause does not appear in the prjection tree, * then parser will create 'ProjectionNode' for them */ public function testProjectionNodeCreation() { $northWindMetadata = NorthWindMetadata::Create(); $queryProvider = new NorthWindQueryProvider(); $configuration = new ServiceConfiguration($northWindMetadata); $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL); $providersWrapper = new ProvidersWrapper($northWindMetadata, $queryProvider, $configuration, false); $ordersResourceSetWrapper = $providersWrapper->resolveResourceSet('Orders'); $orderResourceType = $ordersResourceSetWrapper->getResourceType(); //test selection of properties which is not included in expand clause //1 primitve ('Order_Details/UnitPrice') and 1 link to navigation 'Customer' $projectionTreeRoot = ExpandProjectionParser::parseExpandAndSelectClause($ordersResourceSetWrapper, $orderResourceType, null, null, null, 'Order_Details', 'Order_Details/UnitPrice, Customer', $providersWrapper); //expand option is absent $this->assertTrue($projectionTreeRoot->isExpansionSpecified()); //select is applied $this->assertTrue($projectionTreeRoot->isSelectionSpecified()); $this->assertFalse($projectionTreeRoot->canSelectAllImmediateProperties()); $this->assertFalse($projectionTreeRoot->canSelectAllProperties()); //there are 2 child nodes for the root $this->assertEquals(count($projectionTreeRoot->getChildNodes()), 2); //The child nodes one 'ProjectionNode' Customer and one 'ExpandedProjectionNode' for 'Order' $childNodes = $projectionTreeRoot->getChildNodes(); $this->assertTrue(array_key_exists('Order_Details', $childNodes)); $this->assertTrue(array_key_exists('Customer', $childNodes)); $this->assertTrue($childNodes['Order_Details'] instanceof ExpandedProjectionNode); $this->assertTrue($childNodes['Customer'] instanceof ProjectionNode); //'Order_Detials' has a child node $childNodes = $childNodes['Order_Details']->getChildNodes(); $this->assertEquals(count($childNodes), 1); $this->assertTrue(array_key_exists('UnitPrice', $childNodes)); $this->assertTrue($childNodes['UnitPrice'] instanceof ProjectionNode); }
/** * Constructs a new instance of ResourceSetWrapper * * @param ResourceSet $resourceSet The resource set to wrap * @param ServiceConfiguration $configuration Configuration to take settings specific to wrapped resource set */ public function __construct(ResourceSet $resourceSet, ServiceConfiguration $configuration) { $this->_resourceSet = $resourceSet; $this->_resourceSetRights = $configuration->getEntitySetAccessRule($resourceSet); $this->_resourceSetPageSize = $configuration->getEntitySetPageSize($resourceSet); }
/** * For the given entry object compare it's eTag (if it has eTag properties) * with current eTag request headers (if it present). * * @param mixed &$entryObject entity resource for which etag * needs to be checked. * @param ResourceType &$resourceType Resource type of the entry * object. * @param boolean &$needToSerializeResponse On return, this will contain * True if response needs to be * serialized, False otherwise. * * @return string|null The ETag for the entry object if it has eTag properties * NULL otherwise. */ protected function compareETag(&$entryObject, ResourceType &$resourceType, &$needToSerializeResponse) { $needToSerializeResponse = true; $eTag = null; $ifMatch = $this->_serviceHost->getRequestIfMatch(); $ifNoneMatch = $this->_serviceHost->getRequestIfNoneMatch(); if (is_null($entryObject)) { if (!is_null($ifMatch)) { throw ODataException::createPreConditionFailedError(Messages::eTagNotAllowedForNonExistingResource()); } return null; } if ($this->config->getValidateETagHeader() && !$resourceType->hasETagProperties()) { if (!is_null($ifMatch) || !is_null($ifNoneMatch)) { // No eTag properties but request has eTag headers, bad request throw ODataException::createBadRequestError(Messages::noETagPropertiesForType()); } // We need write the response but no eTag header return null; } if (!$this->config->getValidateETagHeader()) { // Configuration says do not validate ETag so we will not write ETag header in the // response even though the requested resource support it return null; } if (is_null($ifMatch) && is_null($ifNoneMatch)) { // No request eTag header, we need to write the response // and eTag header } else { if (strcmp($ifMatch, '*') == 0) { // If-Match:* => we need to write the response and eTag header } else { if (strcmp($ifNoneMatch, '*') == 0) { // if-None-Match:* => Do not write the response (304 not modified), // but write eTag header $needToSerializeResponse = false; } else { $eTag = $this->getETagForEntry($entryObject, $resourceType); // Note: The following code for attaching the prefix W\" // and the suffix " can be done in getETagForEntry function // but that is causing an issue in Linux env where the // firefix browser is unable to parse the ETag in this case. // Need to follow up PHP core devs for this. $eTag = ODataConstants::HTTP_WEAK_ETAG_PREFIX . $eTag . '"'; if (!is_null($ifMatch)) { if (strcmp($eTag, $ifMatch) != 0) { // Requested If-Match value does not match with current // eTag Value then pre-condition error // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html throw ODataException::createPreConditionFailedError(Messages::eTagValueDoesNotMatch()); } } else { if (strcmp($eTag, $ifNoneMatch) == 0) { //304 not modified, but in write eTag header $needToSerializeResponse = false; } } } } } if (is_null($eTag)) { $eTag = $this->getETagForEntry($entryObject, $resourceType); // Note: The following code for attaching the prefix W\" // and the suffix " can be done in getETagForEntry function // but that is causing an issue in Linux env where the // firefix browser is unable to parse the ETag in this case. // Need to follow up PHP core devs for this. $eTag = ODataConstants::HTTP_WEAK_ETAG_PREFIX . $eTag . '"'; } return $eTag; }
public function testCreateSegments_NavigationSegment() { //Test navigation segment followed by primitve property $segments = array("Customers(CustomerID='ALFKI', CustomerGuid=guid'15b242e7-52eb-46bd-8f0e-6568b72cd9a6')", 'Orders(789)', 'Customer', 'CustomerName'); $segmentDescriptors = SegmentParser::parseRequestUriSegments($segments, $this->providersWrapper); $this->assertEquals(count($segmentDescriptors), 4); $this->assertEquals($segmentDescriptors[0]->getIdentifier(), 'Customers'); $this->assertEquals($segmentDescriptors[1]->getIdentifier(), 'Orders'); $this->assertEquals($segmentDescriptors[2]->getIdentifier(), 'Customer'); $this->assertEquals($segmentDescriptors[3]->getIdentifier(), 'CustomerName'); $keyDescriptor = $segmentDescriptors[0]->getKeyDescriptor(); $this->assertFalse(is_null($keyDescriptor)); $keyDescriptor = $segmentDescriptors[1]->getKeyDescriptor(); $this->assertFalse(is_null($keyDescriptor)); $keyDescriptor = $segmentDescriptors[2]->getKeyDescriptor(); $this->assertTrue(is_null($keyDescriptor)); $keyDescriptor = $segmentDescriptors[3]->getKeyDescriptor(); $this->assertTrue(is_null($keyDescriptor)); $keyDescriptor = $segmentDescriptors[0]->getKeyDescriptor(); $this->assertEquals($keyDescriptor->valueCount(), 2); $namedKeyValues = $keyDescriptor->getValidatedNamedValues(); $this->assertTrue(array_key_exists('CustomerID', $namedKeyValues)); $this->assertTrue(array_key_exists('CustomerGuid', $namedKeyValues)); $this->assertEquals($namedKeyValues['CustomerID'][0], '\'ALFKI\''); $this->assertEquals($namedKeyValues['CustomerGuid'][0], '\'15b242e7-52eb-46bd-8f0e-6568b72cd9a6\''); $keyDescriptor = $segmentDescriptors[1]->getKeyDescriptor(); $this->assertEquals($keyDescriptor->valueCount(), 1); $namedKeyValues = $keyDescriptor->getValidatedNamedValues(); $this->assertTrue(array_key_exists('OrderID', $namedKeyValues)); $this->assertEquals($namedKeyValues['OrderID'][0], 789); $this->assertEquals($segmentDescriptors[0]->getTargetKind(), TargetKind::RESOURCE()); $this->assertEquals($segmentDescriptors[1]->getTargetKind(), TargetKind::RESOURCE()); $this->assertEquals($segmentDescriptors[2]->getTargetKind(), TargetKind::RESOURCE()); $this->assertEquals($segmentDescriptors[3]->getTargetKind(), TargetKind::PRIMITIVE()); $this->assertEquals($segmentDescriptors[0]->getTargetSource(), TargetSource::ENTITY_SET); $this->assertEquals($segmentDescriptors[1]->getTargetSource(), TargetSource::PROPERTY); $this->assertEquals($segmentDescriptors[2]->getTargetSource(), TargetSource::PROPERTY); $this->assertEquals($segmentDescriptors[3]->getTargetSource(), TargetSource::PROPERTY); $resourceSetWrapper = $segmentDescriptors[0]->getTargetResourcesetWrapper(); $this->assertFalse(is_null($resourceSetWrapper)); $resourceSetWrapper = $segmentDescriptors[1]->getTargetResourcesetWrapper(); $this->assertFalse(is_null($resourceSetWrapper)); $resourceSetWrapper = $segmentDescriptors[2]->getTargetResourcesetWrapper(); $this->assertFalse(is_null($resourceSetWrapper)); $resourceSetWrapper = $segmentDescriptors[3]->getTargetResourcesetWrapper(); $this->assertTrue(is_null($resourceSetWrapper)); $this->assertTrue($segmentDescriptors[0]->isSingleResult()); $this->assertTrue($segmentDescriptors[0]->isSingleResult()); $this->assertTrue($segmentDescriptors[0]->isSingleResult()); $this->assertTrue($segmentDescriptors[0]->isSingleResult()); //Test invisible navigation segment //Creates a provider wrapper for NorthWind service with 'Orders' entity set as invisible $metadataProvider = NorthWindMetadata::Create(); $serviceConfiguration = new ServiceConfiguration($this->_metadataProvider); $serviceConfiguration->setEntitySetAccessRule('Customers', EntitySetRights::READ_ALL); $serviceConfiguration->setEntitySetAccessRule('Orders', EntitySetRights::NONE); $providersWrapper = new ProvidersWrapper($metadataProvider, $this->mockQueryProvider, $serviceConfiguration, false); $segments = array("Customers(CustomerID='ALFKI', CustomerGuid=guid'15b242e7-52eb-46bd-8f0e-6568b72cd9a6')", 'Orders(789)', 'OrderID'); try { SegmentParser::parseRequestUriSegments($segments, $providersWrapper); $this->fail('An expected ODataException for \'Orders\' resource not found error has not been thrown'); } catch (ODataException $exception) { $this->assertEquals('Resource not found for the segment \'Orders\'', $exception->getMessage()); } }
/** * test the creation of nextlink from an object. * Test building of link with guid sub-value */ public function testCreationOfNextLink4() { $northWindMetadata = NorthWindMetadata::Create(); $configuration = new ServiceConfiguration($northWindMetadata); $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL); $providersWrapper = new ProvidersWrapper($northWindMetadata, $this->mockQueryProvider, $configuration, false); $resourceSetWrapper = $providersWrapper->resolveResourceSet('Customers'); $resourceType = $resourceSetWrapper->getResourceType(); $orderBy = 'CustomerID, CustomerGuid'; $internalOrderByInfo = OrderByParser::parseOrderByClause($resourceSetWrapper, $resourceType, $orderBy, $providersWrapper); $skipToken = "null, guid'05b242e752eb46bd8f0e6568b72cd9a5'"; $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($resourceType, $internalOrderByInfo, $skipToken); $keyObject = $internalSkipTokenInfo->getKeyObject(); $lastObject = new Customer2(); $lastObject->CustomerID = 'ABC'; $lastObject->CustomerGuid = '{05b242e7-52eb-46bd-8f0e-6568b72cd9a5}'; $nextLink = $internalSkipTokenInfo->buildNextPageLink($lastObject); $this->assertEquals($nextLink, "'ABC', guid'%7B05b242e7-52eb-46bd-8f0e-6568b72cd9a5%7D'"); }
/** * One can expand a navigation property only if corresponding resource set is visible * */ public function testExpandWithNonVisibleResourceSet() { $northWindMetadata = NorthWindMetadata::Create(); $queryProvider = new NorthWindQueryProvider(); $configuration = new ServiceConfiguration($northWindMetadata); //Make 'Customers' and 'Orders' visible, make 'Order_Details' invisible $configuration->setEntitySetAccessRule('Customers', EntitySetRights::ALL); $configuration->setEntitySetAccessRule('Orders', EntitySetRights::ALL); $providersWrapper = new ProvidersWrapper($northWindMetadata, $queryProvider, $configuration, false); $customersResourceSetWrapper = $providersWrapper->resolveResourceSet('Customers'); $customerResourceType = $customersResourceSetWrapper->getResourceType(); $exceptionThrown = false; try { $projectionTree = ExpandProjectionParser::parseExpandAndSelectClause($customersResourceSetWrapper, $customerResourceType, null, null, null, 'Orders/Order_Details', null, $providersWrapper); $this->fail('An expected ODataException for navigation to invisible resource set has not been thrown'); } catch (ODataException $odataException) { $this->assertStringEndsWith("(Check the resource set of the navigation property 'Order_Details' is visible)", $odataException->getMessage()); } }
/** * Test whether order by parser identify and remove path duplication */ public function testOrderByWithPathDuplication() { $northWindMetadata = NorthWindMetadata::Create(); $configuration = new ServiceConfiguration($northWindMetadata); $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL); $providersWrapper = new ProvidersWrapper($northWindMetadata, $this->mockQueryProvider, $configuration, false); $resourceSetWrapper = $providersWrapper->resolveResourceSet('Order_Details'); $resourceType = $resourceSetWrapper->getResourceType(); $orderBy = 'Order/Price desc, Product/ProductName asc, Order/Price asc'; $internalOrderInfo = OrderByParser::parseOrderByClause($resourceSetWrapper, $resourceType, $orderBy, $providersWrapper); //The orderby path Order/Price appears twice, but parser will consider only first path $orderByInfo = $internalOrderInfo->getOrderByInfo(); //There are navigation (resource reference) properties in the orderby path so getNavigationPropertiesUsed should //not be null $naviUsed = $orderByInfo->getNavigationPropertiesUsed(); $this->assertFalse(is_null($naviUsed)); //3 path segment are there, but last one is duplicate of first one, so parser removes last one $this->assertEquals(count($naviUsed), 2); $this->assertTrue(is_array($naviUsed[0])); $this->assertTrue(is_array($naviUsed[1])); //one navgations used in first orderby 'Order' $this->assertEquals(count($naviUsed[0]), 1); //one navgations used in second orderby 'Prodcut' $this->assertEquals(count($naviUsed[1]), 1); $this->assertEquals($naviUsed[0][0]->getName(), 'Order'); $this->assertEquals($naviUsed[1][0]->getName(), 'Product'); $orderByPathSegments = $orderByInfo->getOrderByPathSegments(); $this->assertEquals(count($orderByPathSegments), 2); }
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()); }