1<?php
2require_once('strataquerytest.inc.php');
3
4/**
5 * Tests queries - sorting.
6 *
7 * @group plugin_strata
8 * @group plugins
9 */
10class query_sort_test extends Strata_Query_UnitTestCase {
11
12    function setup() {
13        parent::setup();
14    }
15
16    function testNumericSort() {
17        $query = array (
18            'type' => 'select',
19            'grouping'=>array(),
20            'group' => array (
21                'type' => 'triple',
22                'subject' => array (
23                    'type' => 'variable',
24                    'text' => 'p'
25                ),
26                'predicate' => array (
27                    'type' => 'literal',
28                    'text' => 'is rated'
29                ),
30                'object' => array (
31                    'type' => 'variable',
32                    'text' => 'rating'
33                )
34            ),
35            'projection' => array (
36                'p',
37                'rating'
38            ),
39            'ordering' => array (
40                array (
41                    'variable' => 'rating',
42                    'direction' => 'asc'
43                )
44            )
45        );
46
47        $expected = array (
48            array (
49                'p' => array('person:carol'),
50                'rating' => array('1')
51            ),
52            array (
53                'p' => array('person:bob'),
54                'rating' => array('8')
55            ),
56            array (
57                'p' => array('person:alice'),
58                'rating' => array('10')
59            )
60        );
61
62        $this->assertQueryResult($query, $expected);
63    }
64
65    function testPartiallyNumericSort() {
66        $query = array (
67            'type' => 'select',
68            'grouping'=>array(),
69            'group' => array (
70                'type' => 'triple',
71                'subject' => array (
72                    'type' => 'variable',
73                    'text' => 'p'
74                ),
75                'predicate' => array (
76                    'type' => 'literal',
77                    'text' => 'tax rate'
78                ),
79                'object' => array (
80                    'type' => 'variable',
81                    'text' => 'tax'
82                )
83            ),
84            'projection' => array (
85                'p',
86                'tax'
87            ),
88            'ordering' => array (
89                array (
90                    'variable' => 'tax',
91                    'direction' => 'asc'
92                )
93            )
94        );
95
96        // Result might vary depending on database backed, only require that it does not fail
97        $this->assertTrue($this->_triples->queryRelations($query));
98    }
99
100}
101