Пример #1
0
 /**
  * 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'");
 }
Пример #2
0
 /**
  * Process the $skiptoken option in the request and update the request 
  * description, this function requires _processOrderBy method to be
  * already invoked.
  * 
  * @return void
  * 
  * @throws ODataException Throws bad request error in the following cases
  *                          (1) If $skiptoken cannot be applied to the 
  *                              resource targeted by the request uri
  *                          (2) If paging is not enabled for the resource
  *                              targeted by the request uri
  *                          (3) If parsing of $skiptoken fails
  *                          (4) If capability negotiation over version fails
  */
 private function _processSkipToken()
 {
     $skipToken = $this->service->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_SKIPTOKEN);
     if (is_null($skipToken)) {
         return;
     }
     if (!$this->_pagingApplicable) {
         throw ODataException::createBadRequestError(Messages::queryProcessorSkipTokenNotAllowed());
     }
     if (!$this->_isSSPagingRequired()) {
         throw ODataException::createBadRequestError(Messages::queryProcessorSkipTokenCannotBeAppliedForNonPagedResourceSet($this->request->getTargetResourceSetWrapper()));
     }
     $internalOrderByInfo = $this->request->getInternalOrderByInfo();
     //assert($internalOrderByInfo != null)
     $targetResourceType = $this->request->getTargetResourceType();
     //assert($targetResourceType != null)
     $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($targetResourceType, $internalOrderByInfo, $skipToken);
     $this->request->setInternalSkipTokenInfo($internalSkipTokenInfo);
     $this->request->raiseMinVersionRequirement(2, 0);
     $this->request->raiseResponseVersion(2, 0);
 }
Пример #3
0
 /**
  * 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);
     //-----------------------------------------------------------------
 }