/**
  * 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);
 }