tests/UnitTests/POData/UriProcessor/QueryProcessor/OrderByParser/OrderByParserTest.php
/**
     * A primitive property of a resource reference type can be used as sort key
     */
A primitive property of a resource reference type can be used as sort key
A primitive property of a resource reference type can be used as sort key
public function testOrderByPrimitiveInAResourceReference()
    {
        $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/Customer/Rating';
        $internalOrderInfo = OrderByParser::parseOrderByClause($resourceSetWrapper, $resourceType, $orderBy, $providersWrapper);
        $dummyObject = $internalOrderInfo->getDummyObject();
        $this->assertTrue(is_object($dummyObject));
        $this->assertTrue($dummyObject instanceof Order_Details2);
        $this->assertTrue(isset($dummyObject->Order));
        $this->assertTrue(is_object($dummyObject->Order));
        $this->assertTrue($dummyObject->Order instanceof Order2);
        $this->assertTrue(isset($dummyObject->Order->Customer));
        $this->assertTrue(is_object($dummyObject->Order->Customer));
        $this->assertTrue($dummyObject->Order->Customer instanceof Customer2);
        $orderByInfo = $internalOrderInfo->getOrderByInfo();
        $naviUsed = $orderByInfo->getNavigationPropertiesUsed();
        $this->assertFalse(is_null($naviUsed));
        $this->assertEquals(count($naviUsed), 1);
        $this->assertTrue(is_array($naviUsed[0]));
        $this->assertEquals(count($naviUsed[0]), 2);
        $this->assertTrue($naviUsed[0][0] instanceof ResourceProperty);
        $this->assertTrue($naviUsed[0][1] instanceof ResourceProperty);
        $this->assertTrue($orderByInfo->requireInternalSorting());
        $orderByPathSegments = $orderByInfo->getOrderByPathSegments();
        $this->assertEquals(count($orderByPathSegments), 1);
        $this->assertTrue($orderByPathSegments[0]->isAscending());
        $subPathSegments = $orderByPathSegments[0]->getSubPathSegments();
        $this->assertTrue(!is_null($subPathSegments));
        $this->assertEquals(count($subPathSegments), 3);
        $this->assertEquals($subPathSegments[0]->getName(), 'Order');
        $this->assertEquals($subPathSegments[1]->getName(), 'Customer');
        $this->assertEquals($subPathSegments[2]->getName(), 'Rating');
        $this->assertTrue($subPathSegments[0]->getResourceProperty() instanceof ResourceProperty);
        $this->assertTrue($subPathSegments[1]->getResourceProperty() instanceof ResourceProperty);
        $this->assertTrue($subPathSegments[2]->getResourceProperty() instanceof ResourceProperty);
        $subSorters = $internalOrderInfo->getSubSorterFunctions();
        $this->assertTrue(!is_null($subSorters));
        $this->assertEquals(count($subSorters), 1);
        $this->assertEquals($subSorters[0]->getParametersAsString(), '$Order_DetailsA, $Order_DetailsB');
        $subSorterName = $subSorters[0]->getReference();
        $sorter = $internalOrderInfo->getSorterFunction();
        $this->assertTrue(!is_null($sorter));
        $mainSorterName = $sorter->getReference();
        $this->assertEquals($subSorterName, $mainSorterName);
    }
public function testOrderByPrimitiveInAResourceReference ( ) { $ 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/Customer/Rating' ; $ internalOrderInfo = OrderByParser :: parseOrderByClause ( $ resourceSetWrapper , $ resourceType , $ orderBy , $ providersWrapper ) ; $ dummyObject = $ internalOrderInfo -> getDummyObject ( ) ; $ this -> assertTrue ( is_object ( $ dummyObject ) ) ; $ this -> assertTrue ( $ dummyObject instanceof Order_Details2 ) ; $ this -> assertTrue ( isset ( $ dummyObject -> Order ) ) ; $ this -> assertTrue ( is_object ( $ dummyObject -> Order ) ) ; $ this -> assertTrue ( $ dummyObject -> Order instanceof Order2 ) ; $ this -> assertTrue ( isset ( $ dummyObject -> Order -> Customer ) ) ; $ this -> assertTrue ( is_object ( $ dummyObject -> Order -> Customer ) ) ; $ this -> assertTrue ( $ dummyObject -> Order -> Customer instanceof Customer2 ) ; $ orderByInfo = $ internalOrderInfo -> getOrderByInfo ( ) ; $ naviUsed = $ orderByInfo -> getNavigationPropertiesUsed ( ) ; $ this -> assertFalse ( is_null ( $ naviUsed ) ) ; $ this -> assertEquals ( count ( $ naviUsed ) , 1 ) ; $ this -> assertTrue ( is_array ( $ naviUsed [ 0 ] ) ) ; $ this -> assertEquals ( count ( $ naviUsed [ 0 ] ) , 2 ) ; $ this -> assertTrue ( $ naviUsed [ 0 ] [ 0 ] instanceof ResourceProperty ) ; $ this -> assertTrue ( $ naviUsed [ 0 ] [ 1 ] instanceof ResourceProperty ) ; $ this -> assertTrue ( $ orderByInfo -> requireInternalSorting ( ) ) ; $ orderByPathSegments = $ orderByInfo -> getOrderByPathSegments ( ) ; $ this -> assertEquals ( count ( $ orderByPathSegments ) , 1 ) ; $ this -> assertTrue ( $ orderByPathSegments [ 0 ] -> isAscending ( ) ) ; $ subPathSegments = $ orderByPathSegments [ 0 ] -> getSubPathSegments ( ) ; $ this -> assertTrue ( ! is_null ( $ subPathSegments ) ) ; $ this -> assertEquals ( count ( $ subPathSegments ) , 3 ) ; $ this -> assertEquals ( $ subPathSegments [ 0 ] -> getName ( ) , 'Order' ) ; $ this -> assertEquals ( $ subPathSegments [ 1 ] -> getName ( ) , 'Customer' ) ; $ this -> assertEquals ( $ subPathSegments [ 2 ] -> getName ( ) , 'Rating' ) ; $ this -> assertTrue ( $ subPathSegments [ 0 ] -> getResourceProperty ( ) instanceof ResourceProperty ) ; $ this -> assertTrue ( $ subPathSegments [ 1 ] -> getResourceProperty ( ) instanceof ResourceProperty ) ; $ this -> assertTrue ( $ subPathSegments [ 2 ] -> getResourceProperty ( ) instanceof ResourceProperty ) ; $ subSorters = $ internalOrderInfo -> getSubSorterFunctions ( ) ; $ this -> assertTrue ( ! is_null ( $ subSorters ) ) ; $ this -> assertEquals ( count ( $ subSorters ) , 1 ) ; $ this -> assertEquals ( $ subSorters [ 0 ] -> getParametersAsString ( ) , '$Order_DetailsA, $Order_DetailsB' ) ; $ subSorterName = $ subSorters [ 0 ] -> getReference ( ) ; $ sorter = $ internalOrderInfo -> getSorterFunction ( ) ; $ this -> assertTrue ( ! is_null ( $ sorter ) ) ; $ mainSorterName = $ sorter -> getReference ( ) ; $ this -> assertEquals ( $ subSorterName , $ mainSorterName ) ; }
A primitive property of a resource reference type can be used as sort key
A primitive property of a resource reference type can be used as sort key
//IMetadataProvider implementation //Service configuuration //Check the dummy object is initialized properly //There are navigation (resource reference) properties in the orderby path so getNavigationPropertiesUsed should //not be null //Only one main segment so one element in main collection //two navgations used in first orderby path segment 'Order' and 'Customer' //default to library sorting //There should be one orderby path segment with three sub path segments //no sort order, so default to asc //there are two sub path 'Order', 'Customer' and 'Rating' //There is only one sub sorter function //Parmater to this sub sort must be Order_DetailsA, Order_DetailsB //since there is only one sub sorter, that will be the main sorter //asset this by comapring the anonymous function names