tests/UnitTests/POData/UriProcessor/QueryProcessor/ExpressionParser/PHPExpressionProviderTest.php
/**     
     * Test the possible string operators defined for filter option 
     */
Test the possible string operators defined for filter option
Test the possible string operators defined for filter option
public function testStringFunctions()
    {
        $odataUriExpression = 'CustomerID ge \'ALFKI\'';
        $parser = new ExpressionParser2($odataUriExpression,
                        $this->northWindMetadata->resolveResourceSet('Customers')->getResourceType(),
                        true);
        $expressionTree = $parser->parseFilter();
        $expressionProcessor = new ExpressionProcessor(new \POData\Providers\Expression\PHPExpressionProvider('$lt'));
        $actualPHPExpression = $expressionProcessor->processExpression($expressionTree);
        $expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strcmp($lt->CustomerID, \'ALFKI\') >= 0))';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'endswith(CustomerID, \'KI\')';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strcmp(substr($lt->CustomerID, strlen($lt->CustomerID) - strlen(\'KI\')), \'KI\') === 0))';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'indexof(CustomerID, \'LFK\') eq 2';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strpos($lt->CustomerID, \'LFK\') == 2))';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'replace(CustomerID, \'LFK\', \'RTT\') eq \'ARTTI\'';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strcmp(str_replace(\'LFK\', \'RTT\', $lt->CustomerID), \'ARTTI\') == 0))';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'startswith(CustomerID, \'AL\')';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strpos($lt->CustomerID, \'AL\') === 0))';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'tolower(\'PeRsIsTeNt\') eq \'persistent\'';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(strcmp(strtolower(\'PeRsIsTeNt\'), \'persistent\') == 0)';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'toupper(\'mICRosoFT\') eq \'MICROSOFT\'';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(strcmp(strtoupper(\'mICRosoFT\'), \'MICROSOFT\') == 0)';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'trim(\'  ODataPHP Producer   \') eq null';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = 'is_null(trim(\'  ODataPHP Producer   \'))';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'substring(\'Red_Black_Tree\', 3) ne \'Black_Tree\'';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(strcmp(substr(\'Red_Black_Tree\', 3), \'Black_Tree\') != 0)';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'substring(\'Red_Black_Tree\', 3, 5) ne \'Black\'';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(strcmp(substr(\'Red_Black_Tree\', 3, 5), \'Black\') != 0)';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'substringof(CustomerID, \'MRR\')';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strpos(\'MRR\', $lt->CustomerID) !== false))';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
        $odataUriExpression = 'length(\'Red_Black_Tree\') eq 8';
        $parser->resetParser($odataUriExpression);
        $actualPHPExpression = $expressionProcessor->processExpression($parser->parseFilter());
        $expectedPHPExpression = '(strlen(\'Red_Black_Tree\') == 8)';
        $this->assertEquals($expectedPHPExpression, $actualPHPExpression);
    }
public function testStringFunctions ( ) { $ odataUriExpression = 'CustomerID ge \'ALFKI\'' ; $ parser = new ExpressionParser2 ( $ odataUriExpression , $ this -> northWindMetadata -> resolveResourceSet ( 'Customers' ) -> getResourceType ( ) , true ) ; $ expressionTree = $ parser -> parseFilter ( ) ; $ expressionProcessor = new ExpressionProcessor ( new \ POData \ Providers \ Expression \ PHPExpressionProvider ( '$lt' ) ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ expressionTree ) ; $ expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strcmp($lt->CustomerID, \'ALFKI\') >= 0))' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'endswith(CustomerID, \'KI\')' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strcmp(substr($lt->CustomerID, strlen($lt->CustomerID) - strlen(\'KI\')), \'KI\') === 0))' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'indexof(CustomerID, \'LFK\') eq 2' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strpos($lt->CustomerID, \'LFK\') == 2))' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'replace(CustomerID, \'LFK\', \'RTT\') eq \'ARTTI\'' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strcmp(str_replace(\'LFK\', \'RTT\', $lt->CustomerID), \'ARTTI\') == 0))' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'startswith(CustomerID, \'AL\')' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strpos($lt->CustomerID, \'AL\') === 0))' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'tolower(\'PeRsIsTeNt\') eq \'persistent\'' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(strcmp(strtolower(\'PeRsIsTeNt\'), \'persistent\') == 0)' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'toupper(\'mICRosoFT\') eq \'MICROSOFT\'' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(strcmp(strtoupper(\'mICRosoFT\'), \'MICROSOFT\') == 0)' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'trim(\'  ODataPHP Producer   \') eq null' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = 'is_null(trim(\'  ODataPHP Producer   \'))' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'substring(\'Red_Black_Tree\', 3) ne \'Black_Tree\'' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(strcmp(substr(\'Red_Black_Tree\', 3), \'Black_Tree\') != 0)' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'substring(\'Red_Black_Tree\', 3, 5) ne \'Black\'' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(strcmp(substr(\'Red_Black_Tree\', 3, 5), \'Black\') != 0)' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'substringof(CustomerID, \'MRR\')' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(!(is_null($lt->CustomerID)) && (strpos(\'MRR\', $lt->CustomerID) !== false))' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; $ odataUriExpression = 'length(\'Red_Black_Tree\') eq 8' ; $ parser -> resetParser ( $ odataUriExpression ) ; $ actualPHPExpression = $ expressionProcessor -> processExpression ( $ parser -> parseFilter ( ) ) ; $ expectedPHPExpression = '(strlen(\'Red_Black_Tree\') == 8)' ; $ this -> assertEquals ( $ expectedPHPExpression , $ actualPHPExpression ) ; }
Test the possible string operators defined for filter option
Test the possible string operators defined for filter option