1<?php 2require_once('strataquerytest.inc.php'); 3 4/** 5 * Tests queries - sorting optional. 6 * 7 * @group plugin_strata_optional 8 * @group plugins 9 */ 10class query_sort_optional_test extends Strata_Query_UnitTestCase { 11 12 function setup() { 13 parent::setup(); 14 } 15 16 function testPartiallyNumericSort() { 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' => 'tax rate' 29 ), 30 'object' => array ( 31 'type' => 'variable', 32 'text' => 'tax' 33 ) 34 ), 35 'projection' => array ( 36 'p', 37 'tax' 38 ), 39 'ordering' => array ( 40 array ( 41 'variable' => 'tax', 42 'direction' => 'asc' 43 ) 44 ) 45 ); 46 47 $expected = array ( 48 array ( 49 'p' => array('person:carol'), 50 'tax' => array('2%') 51 ), 52 array ( 53 'p' => array('person:alice'), 54 'tax' => array('10%') 55 ), 56 array ( 57 'p' => array('person:bob'), 58 'tax' => array('25%') 59 ) 60 ); 61 62 $this->assertQueryResult($query, $expected, 'Partial numeric sort (numbers first, text second) unsupported'); 63 } 64 65 function testNaturalSort() { 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' => 'has length' 78 ), 79 'object' => array ( 80 'type' => 'variable', 81 'text' => 'length' 82 ) 83 ), 84 'projection' => array ( 85 'p', 86 'length' 87 ), 88 'ordering' => array ( 89 array ( 90 'variable' => 'length', 91 'direction' => 'asc' 92 ) 93 ) 94 ); 95 96 $expected = array ( 97 array ( 98 'p' => array('person:carol'), 99 'length' => array('4 ft 11 in') 100 ), 101 array ( 102 'p' => array('person:alice'), 103 'length' => array('5 ft 5 in') 104 ), 105 array ( 106 'p' => array('person:bob'), 107 'length' => array('5 ft 10 in') 108 ) 109 ); 110 111 $this->assertQueryResult($query, $expected, 'Full natural sort unsupported'); 112 } 113 114 function testUnicodeSort() { 115 $query = array ( 116 'type' => 'select', 117 'grouping'=>array(), 118 'group' => array ( 119 'type' => 'triple', 120 'subject' => array ( 121 'type' => 'variable', 122 'text' => 'p' 123 ), 124 'predicate' => array ( 125 'type' => 'literal', 126 'text' => 'identifier' 127 ), 128 'object' => array ( 129 'type' => 'variable', 130 'text' => 'id' 131 ) 132 ), 133 'projection' => array ( 134 'p', 135 'id' 136 ), 137 'ordering' => array ( 138 array ( 139 'variable' => 'id', 140 'direction' => 'asc' 141 ) 142 ) 143 ); 144 145 $expected = array ( 146 array ( 147 'p' => array('person:alice'), 148 'id' => array('α') 149 ), 150 array ( 151 'p' => array('person:bob'), 152 'id' => array('Β') 153 ), 154 array ( 155 'p' => array('person:carol'), 156 'id' => array('γ') 157 ) 158 ); 159 160 $this->assertQueryResult($query, $expected, 'Case insensitive unicode sort unsupported'); 161 } 162 163} 164