tests/UnitTests/POData/UriProcessor/QueryProcessor/ExpressionParser/PHPExpressionProviderTest.php
/**     
     * Test expression provider using real data
     */
Test expression provider using real data
Test expression provider using real data
public function testAnonymousFunction()
    {
        $data = $this->createTestData();
        $result = $this->executeExpression('indexof(CustomerID, \'L\') eq 1',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(1, count($result));
        $this->assertEquals('ALFKI', $result[0]->CustomerID);
        $result = $this->executeExpression('Country eq \'Germany\'',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(2, count($result));
        $this->assertEquals('Germany', $result[0]->Country);
        $this->assertEquals('Germany', $result[1]->Country);
        $result = $this->executeExpression('Address eq null',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(1, count($result));
        $this->assertEquals('15b242e7-52eb-46bd-8f0e-6568b72cd9a6', $result[0]->CustomerGuid);
        $result = $this->executeExpression('Address/Address2/IsPrimary eq false',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(1, count($result));
        $this->assertEquals('Ann Devon', $result[0]->CustomerName);
        $result = $this->executeExpression('CustomerID eq \'ALFKI\' or CustomerID eq \'EASTC\'',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(2, count($result));
        $this->assertEquals('ALFKI', $result[0]->CustomerID);
        $this->assertEquals('EASTC', $result[1]->CustomerID);
        $result = $this->executeExpression('1 add 2 eq 5',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(0, count($result));
        $result = $this->executeExpression('true',
                                            $this->northWindMetadata->resolveResourceSet('Orders')->getResourceType(),
                                            $data['Orders']);
        $this->assertEquals(5, count($result));
        $result = $this->executeExpression('ShipName eq \'Speedy Express\'',
                                            $this->northWindMetadata->resolveResourceSet('Orders')->getResourceType(),
                                            $data['Orders']);
        $this->assertEquals(2, count($result));
        foreach($result as $order) {
            $this->assertEquals($order->ShipName, 'Speedy Express');
        }
        $result = $this->executeExpression('Customer/CustomerID eq \'DUMON\'',
                                            $this->northWindMetadata->resolveResourceSet('Orders')->getResourceType(),
                                            $data['Orders']);
        $this->assertEquals(3, count($result));
        $result = $this->executeExpression('year(OrderDate) eq 1999 or year(OrderDate) add 4 eq 1999',
                                            $this->northWindMetadata->resolveResourceSet('Orders')->getResourceType(),
                                            $data['Orders']);
        foreach($result as $order) {
            $this->assertContains($order->OrderDate, array(1999, 1995));
        }
        $result = $this->executeExpression('OrderDate ge datetime\'2000-11-11\'',
                                            $this->northWindMetadata->resolveResourceSet('Orders')->getResourceType(),
                                            $data['Orders']);
        foreach($result as $order) {
            $this->assertGreaterThanOrEqual(0, DateTime::dateTimeCmp($order->OrderDate, '2000-11-11'));
        }
        $result = $this->executeExpression('CustomerGuid eq guid\'15b242e7-52eb-46bd-8f0e-6568b72cd9a6\'',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(1, count($result));
        $customer1 = $result[0];
        $result = $this->executeExpression('CustomerGuid eq guid\'{15b242e7-52eb-46bd-8f0e-6568b72cd9a6}\'',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(1, count($result));
        $customer2 = $result[0];
        $result = $this->executeExpression('CustomerGuid eq guid\'(15b242e7-52eb-46bd-8f0e-6568b72cd9a6)\'',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(1, count($result));
        $customer3 = $result[0];
        $result = $this->executeExpression('CustomerGuid eq guid\'15b242e752eb46bd8f0e6568b72cd9a6\'',
                                            $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                                            $data['Customers']);
        $this->assertEquals(1, count($result));
        $customer4 = $result[0];
        $this->assertEquals($customer1->CustomerID, $customer2->CustomerID);
        $this->assertEquals($customer3->CustomerID, $customer4->CustomerID);
        $this->assertEquals($customer1->CustomerID, $customer4->CustomerID);
    }
public function testAnonymousFunction ( ) { $ data = $ this -> createTestData ( ) ; $ result = $ this -> executeExpression ( 'indexof(CustomerID, \'L\') eq 1' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 1 , count ( $ result ) ) ; $ this -> assertEquals ( 'ALFKI' , $ result [ 0 ] -> CustomerID ) ; $ result = $ this -> executeExpression ( 'Country eq \'Germany\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 2 , count ( $ result ) ) ; $ this -> assertEquals ( 'Germany' , $ result [ 0 ] -> Country ) ; $ this -> assertEquals ( 'Germany' , $ result [ 1 ] -> Country ) ; $ result = $ this -> executeExpression ( 'Address eq null' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 1 , count ( $ result ) ) ; $ this -> assertEquals ( '15b242e7-52eb-46bd-8f0e-6568b72cd9a6' , $ result [ 0 ] -> CustomerGuid ) ; $ result = $ this -> executeExpression ( 'Address/Address2/IsPrimary eq false' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 1 , count ( $ result ) ) ; $ this -> assertEquals ( 'Ann Devon' , $ result [ 0 ] -> CustomerName ) ; $ result = $ this -> executeExpression ( 'CustomerID eq \'ALFKI\' or CustomerID eq \'EASTC\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 2 , count ( $ result ) ) ; $ this -> assertEquals ( 'ALFKI' , $ result [ 0 ] -> CustomerID ) ; $ this -> assertEquals ( 'EASTC' , $ result [ 1 ] -> CustomerID ) ; $ result = $ this -> executeExpression ( '1 add 2 eq 5' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 0 , count ( $ result ) ) ; $ result = $ this -> executeExpression ( 'true' , $ this -> northWindMetadata -> resolveResourceSet ( 'Orders' ) -> getResourceType ( ) , $ data [ 'Orders' ] ) ; $ this -> assertEquals ( 5 , count ( $ result ) ) ; $ result = $ this -> executeExpression ( 'ShipName eq \'Speedy Express\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Orders' ) -> getResourceType ( ) , $ data [ 'Orders' ] ) ; $ this -> assertEquals ( 2 , count ( $ result ) ) ; foreach ( $ result as $ order ) { $ this -> assertEquals ( $ order -> ShipName , 'Speedy Express' ) ; } $ result = $ this -> executeExpression ( 'Customer/CustomerID eq \'DUMON\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Orders' ) -> getResourceType ( ) , $ data [ 'Orders' ] ) ; $ this -> assertEquals ( 3 , count ( $ result ) ) ; $ result = $ this -> executeExpression ( 'year(OrderDate) eq 1999 or year(OrderDate) add 4 eq 1999' , $ this -> northWindMetadata -> resolveResourceSet ( 'Orders' ) -> getResourceType ( ) , $ data [ 'Orders' ] ) ; foreach ( $ result as $ order ) { $ this -> assertContains ( $ order -> OrderDate , array ( 1999 , 1995 ) ) ; } $ result = $ this -> executeExpression ( 'OrderDate ge datetime\'2000-11-11\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Orders' ) -> getResourceType ( ) , $ data [ 'Orders' ] ) ; foreach ( $ result as $ order ) { $ this -> assertGreaterThanOrEqual ( 0 , DateTime :: dateTimeCmp ( $ order -> OrderDate , '2000-11-11' ) ) ; } $ result = $ this -> executeExpression ( 'CustomerGuid eq guid\'15b242e7-52eb-46bd-8f0e-6568b72cd9a6\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 1 , count ( $ result ) ) ; $ customer1 = $ result [ 0 ] ; $ result = $ this -> executeExpression ( 'CustomerGuid eq guid\'{15b242e7-52eb-46bd-8f0e-6568b72cd9a6}\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 1 , count ( $ result ) ) ; $ customer2 = $ result [ 0 ] ; $ result = $ this -> executeExpression ( 'CustomerGuid eq guid\'(15b242e7-52eb-46bd-8f0e-6568b72cd9a6)\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 1 , count ( $ result ) ) ; $ customer3 = $ result [ 0 ] ; $ result = $ this -> executeExpression ( 'CustomerGuid eq guid\'15b242e752eb46bd8f0e6568b72cd9a6\'' , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , $ data [ 'Customers' ] ) ; $ this -> assertEquals ( 1 , count ( $ result ) ) ; $ customer4 = $ result [ 0 ] ; $ this -> assertEquals ( $ customer1 -> CustomerID , $ customer2 -> CustomerID ) ; $ this -> assertEquals ( $ customer3 -> CustomerID , $ customer4 -> CustomerID ) ; $ this -> assertEquals ( $ customer1 -> CustomerID , $ customer4 -> CustomerID ) ; }
Test expression provider using real data
Test expression provider using real data
//Creates test data //Query for Customers with 'L' as second letter of CustomerID //Query for Customers with country as Germany //Query for Customers with no address //Query for Customers with non-primary address //Query for Customers with ID 'ALFKI' or 'EASTC' //Query for Customers with an expression which evaluates to false //Query for all Orders //Query for Order with ShipName as 'Speedy Express' //Query for Order with CustomerID as 'DUMON' //Query for Orders with year of order as 1999 or 1995 //Query for Orders with date greater than 2000-11-11 //Query for Customer using different flavours of guid