tests/UnitTests/POData/UriProcessor/UriProcessorTest.php
/**
     * $orderby option can be applied to $links resource set
     */
$orderby option can be applied to $links resource set
$orderby option can be applied to $links resource set
public function testUriProcessorForLinksResourceSet1()
    {
        $baseUri = 'http:localhost:8083/NorthWindDataService.svc/';
        $resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders';
        $hostInfo = array(
            'AbsoluteRequestUri' => new Url($baseUri . $resourcePath),
            'AbsoluteServiceUri' => new Url($baseUri),
            'QueryString' => '$orderby=ShipName asc, OrderDate desc',
            'DataServiceVersion' => new Version(2, 0),
            'MaxDataServiceVersion' => new Version(2, 0),
        );
        $host = new ServiceHostTestFake($hostInfo);
        $dataService = new NorthWindService2();
        $dataService->setHost($host);
        $uriProcessor = $dataService->handleRequest();
        $requestDescription = $uriProcessor->getRequest();
        $this->assertNotNull($requestDescription);
        $this->assertFalse($requestDescription->isSingleResult());
        $this->assertEquals($requestDescription->getTopCount(), 5);
        SELECT links(d.orderID) FROM Customers JOIN Orders WHERE CustomerID='ALFKI' AND
        CustomerGuid=guid'05b242e752eb46bd8f0e6568b72cd9a5' ORDER BY
        d.ShipName ASC, d.OrderDate DESC, d.OrderID ASC
        $internalOrderByInfo = $requestDescription->getInternalOrderByInfo();
        $this->assertNotNull($internalOrderByInfo);
        $pathSegments = $internalOrderByInfo->getOrderByPathSegments();
        $this->assertNotNull($pathSegments);
        $this->assertTrue(is_array($pathSegments));
        $this->assertEquals(count($pathSegments), 3);
        $this->assertTrue($pathSegments[0] instanceof OrderByPathSegment);
        $subPathSegments = $pathSegments[0]->getSubPathSegments();
        $this->assertTrue($pathSegments[0]->isAscending());
        $this->assertNotNull($subPathSegments);
        $this->assertTrue(is_array($subPathSegments));
        $this->assertEquals(count($subPathSegments), 1);
        $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
        $this->assertEquals($subPathSegments[0]->getName(), 'ShipName');
        $this->assertTrue($pathSegments[1] instanceof OrderByPathSegment);
        $this->assertFalse($pathSegments[1]->isAscending());
        $subPathSegments = $pathSegments[1]->getSubPathSegments();
        $this->assertNotNull($subPathSegments);
        $this->assertTrue(is_array($subPathSegments));
        $this->assertEquals(count($subPathSegments), 1);
        $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
        $this->assertEquals($subPathSegments[0]->getName(), 'OrderDate');
        $this->assertTrue($pathSegments[2] instanceof OrderByPathSegment);
        $this->assertTrue($pathSegments[2]->isAscending());
        $subPathSegments = $pathSegments[2]->getSubPathSegments();
        $this->assertNotNull($subPathSegments);
        $this->assertTrue(is_array($subPathSegments));
        $this->assertEquals(count($subPathSegments), 1);
        $this->assertTrue($subPathSegments[0] instanceof OrderBySubPathSegment);
        $this->assertEquals($subPathSegments[0]->getName(), 'OrderID');
    }
public function testUriProcessorForLinksResourceSet1 ( ) { $ baseUri = 'http://localhost:8083/NorthWindDataService.svc/' ; $ resourcePath = 'Customers(CustomerID=\'ALFKI\', CustomerGuid=guid\'05b242e752eb46bd8f0e6568b72cd9a5\')/$links/Orders' ; $ hostInfo = array ( 'AbsoluteRequestUri' => new Url ( $ baseUri . $ resourcePath ) , 'AbsoluteServiceUri' => new Url ( $ baseUri ) , 'QueryString' => '$orderby=ShipName asc, OrderDate desc' , 'DataServiceVersion' => new Version ( 2 , 0 ) , 'MaxDataServiceVersion' => new Version ( 2 , 0 ) , ) ; $ host = new ServiceHostTestFake ( $ hostInfo ) ; $ dataService = new NorthWindService2 ( ) ; $ dataService -> setHost ( $ host ) ; $ uriProcessor = $ dataService -> handleRequest ( ) ; $ requestDescription = $ uriProcessor -> getRequest ( ) ; $ this -> assertNotNull ( $ requestDescription ) ; $ this -> assertFalse ( $ requestDescription -> isSingleResult ( ) ) ; $ this -> assertEquals ( $ requestDescription -> getTopCount ( ) , 5 ) ; $ internalOrderByInfo = $ requestDescription -> getInternalOrderByInfo ( ) ; $ this -> assertNotNull ( $ internalOrderByInfo ) ; $ pathSegments = $ internalOrderByInfo -> getOrderByPathSegments ( ) ; $ this -> assertNotNull ( $ pathSegments ) ; $ this -> assertTrue ( is_array ( $ pathSegments ) ) ; $ this -> assertEquals ( count ( $ pathSegments ) , 3 ) ; $ this -> assertTrue ( $ pathSegments [ 0 ] instanceof OrderByPathSegment ) ; $ subPathSegments = $ pathSegments [ 0 ] -> getSubPathSegments ( ) ; $ this -> assertTrue ( $ pathSegments [ 0 ] -> isAscending ( ) ) ; $ this -> assertNotNull ( $ subPathSegments ) ; $ this -> assertTrue ( is_array ( $ subPathSegments ) ) ; $ this -> assertEquals ( count ( $ subPathSegments ) , 1 ) ; $ this -> assertTrue ( $ subPathSegments [ 0 ] instanceof OrderBySubPathSegment ) ; $ this -> assertEquals ( $ subPathSegments [ 0 ] -> getName ( ) , 'ShipName' ) ; $ this -> assertTrue ( $ pathSegments [ 1 ] instanceof OrderByPathSegment ) ; $ this -> assertFalse ( $ pathSegments [ 1 ] -> isAscending ( ) ) ; $ subPathSegments = $ pathSegments [ 1 ] -> getSubPathSegments ( ) ; $ this -> assertNotNull ( $ subPathSegments ) ; $ this -> assertTrue ( is_array ( $ subPathSegments ) ) ; $ this -> assertEquals ( count ( $ subPathSegments ) , 1 ) ; $ this -> assertTrue ( $ subPathSegments [ 0 ] instanceof OrderBySubPathSegment ) ; $ this -> assertEquals ( $ subPathSegments [ 0 ] -> getName ( ) , 'OrderDate' ) ; $ this -> assertTrue ( $ pathSegments [ 2 ] instanceof OrderByPathSegment ) ; $ this -> assertTrue ( $ pathSegments [ 2 ] -> isAscending ( ) ) ; $ subPathSegments = $ pathSegments [ 2 ] -> getSubPathSegments ( ) ; $ this -> assertNotNull ( $ subPathSegments ) ; $ this -> assertTrue ( is_array ( $ subPathSegments ) ) ; $ this -> assertEquals ( count ( $ subPathSegments ) , 1 ) ; $ this -> assertTrue ( $ subPathSegments [ 0 ] instanceof OrderBySubPathSegment ) ; $ this -> assertEquals ( $ subPathSegments [ 0 ] -> getName ( ) , 'OrderID' ) ; }
$orderby option can be applied to $links resource set
$orderby option can be applied to $links resource set
//Page size is 5, so take count is 5 means you will get only 5 links for a request //Paging requires ordering, the result should be ordered like //Note: additional ordering constraint // //SELECT links(d.orderID) FROM Customers JOIN Orders WHERE CustomerID='ALFKI' AND //CustomerGuid=guid'05b242e752eb46bd8f0e6568b72cd9a5' ORDER BY //d.ShipName ASC, d.OrderDate DESC, d.OrderID ASC