Пример #1
0
 /**
  * test the creation of nextlink from an object.
  * Test building of link with guid sub-value
  */
 public function testCreationOfNextLink4()
 {
     try {
         $northWindMetadata = CreateNorthWindMetadata3::Create();
         $configuration = new DataServiceConfiguration($northWindMetadata);
         $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($northWindMetadata, null, $configuration, false);
         $resourceSetWrapper = $metaQueryProverWrapper->resolveResourceSet('Customers');
         $resourceType = $resourceSetWrapper->getResourceType();
         $orderBy = 'CustomerID, CustomerGuid';
         $internalOrderByInfo = OrderByParser::parseOrderByClause($resourceSetWrapper, $resourceType, $orderBy, $metaQueryProverWrapper);
         $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'");
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised.' . $exception->getMessage());
     }
 }
Пример #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 targetted by the request uri
  *                          (2) If paging is not enabled for the resource
  *                              targetted by the request uri
  *                          (3) If parsing of $skiptoken fails
  *                          (4) If capability negotiation over version fails
  */
 private function _processSkipToken()
 {
     $skipToken = $this->_dataService->getHost()->getQueryStringItem(ODataConstants::HTTPQUERY_STRING_SKIPTOKEN);
     if (!is_null($skipToken)) {
         if (!$this->_pagingApplicable) {
             ODataException::createBadRequestError(Messages::queryProcessorSkipTokenNotAllowed());
         }
         if (!$this->_isSSPagingRequired()) {
             ODataException::createBadRequestError(Messages::queryProcessorSkipTokenCannotBeAppliedForNonPagedResourceSet());
         }
         $internalOrderByInfo = $this->_requestDescription->getInternalOrderByInfo();
         //assert($internalOrderByInfo != null)
         $targetResourceType = $this->_requestDescription->getTargetResourceType();
         //assert($targetResourceType != null)
         try {
             $internalSkipTokenInfo = SkipTokenParser::parseSkipTokenClause($targetResourceType, $internalOrderByInfo, $skipToken);
             $this->_requestDescription->setInternalSkipTokenInfo($internalSkipTokenInfo);
             $this->_requestDescription->raiseMinimumVersionRequirement(2, 0, $this->_dataService);
             $this->_requestDescription->raiseResponseVersion(2, 0, $this->_dataService);
         } catch (ODataException $odataException) {
             throw $odataException;
         }
     }
 }
Пример #3
0
 /**
  * Test search InternalSkipToeknInfo::GetIndexOfFirstEntryInNextPage function
  */
 public function testGetIndexOfFirstEntryInNextPage2()
 {
     try {
         $northWindMetadata = CreateNorthWindMetadata1::Create();
         $configuration = new DataServiceConfiguration($northWindMetadata);
         $configuration->setEntitySetAccessRule('*', EntitySetRights::ALL);
         $metaQueryProverWrapper = new MetadataQueryProviderWrapper($northWindMetadata, null, $configuration, false);
         $resourceSetWrapper = $metaQueryProverWrapper->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, $metaQueryProverWrapper);
         $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);
         //-----------------------------------------------------------------
     } catch (\Exception $exception) {
         $this->fail('An unexpected Exception has been raised.' . $exception->getMessage());
     }
 }