1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Definition of ViewsHandlersTest.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Tests abstract handlers of views.
|
10 |
|
|
*/
|
11 |
|
|
class ViewsHandlersTest extends ViewsSqlTest {
|
12 |
|
|
public static function getInfo() {
|
13 |
|
|
return array(
|
14 |
|
|
'name' => 'Handlers test',
|
15 |
|
|
'description' => 'test abstract handler definitions',
|
16 |
|
|
'group' => 'Views',
|
17 |
|
|
);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
protected function setUp() {
|
21 |
|
|
parent::setUp('views', 'views_ui');
|
22 |
|
|
module_enable(array('views_ui'));
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
function testFilterInOperatorUi() {
|
26 |
|
|
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
27 |
|
|
$this->drupalLogin($admin_user);
|
28 |
|
|
menu_rebuild();
|
29 |
|
|
|
30 |
|
|
$path = 'admin/structure/views/nojs/config-item/test_filter_in_operator_ui/default/filter/type';
|
31 |
|
|
$this->drupalGet($path);
|
32 |
|
|
$this->assertFieldByName('options[expose][reduce]', FALSE);
|
33 |
|
|
|
34 |
|
|
$edit = array(
|
35 |
|
|
'options[expose][reduce]' => TRUE,
|
36 |
|
|
);
|
37 |
|
|
$this->drupalPost($path, $edit, t('Apply'));
|
38 |
|
|
$this->drupalGet($path);
|
39 |
|
|
$this->assertFieldByName('options[expose][reduce]', TRUE);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
/**
|
43 |
|
|
* Tests views_break_phrase_string function.
|
44 |
|
|
*/
|
45 |
|
|
function test_views_break_phrase_string() {
|
46 |
|
|
$empty_stdclass = new stdClass();
|
47 |
|
|
$empty_stdclass->operator = 'or';
|
48 |
|
|
$empty_stdclass->value = array();
|
49 |
|
|
|
50 |
|
|
$null = NULL;
|
51 |
|
|
// check defaults
|
52 |
|
|
$this->assertEqual($empty_stdclass, views_break_phrase_string('', $null));
|
53 |
|
|
|
54 |
|
|
$handler = views_get_handler('node', 'title', 'argument');
|
55 |
|
|
$this->assertEqual($handler, views_break_phrase_string('', $handler));
|
56 |
|
|
|
57 |
|
|
// test ors
|
58 |
|
|
$handler = views_break_phrase_string('word1 word2+word');
|
59 |
|
|
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
|
60 |
|
|
$this->assertEqual('or', $handler->operator);
|
61 |
|
|
$handler = views_break_phrase_string('word1+word2+word');
|
62 |
|
|
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
|
63 |
|
|
$this->assertEqual('or', $handler->operator);
|
64 |
|
|
$handler = views_break_phrase_string('word1 word2 word');
|
65 |
|
|
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
|
66 |
|
|
$this->assertEqual('or', $handler->operator);
|
67 |
|
|
$handler = views_break_phrase_string('word-1+word-2+word');
|
68 |
|
|
$this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
|
69 |
|
|
$this->assertEqual('or', $handler->operator);
|
70 |
|
|
$handler = views_break_phrase_string('wõrd1+wõrd2+wõrd');
|
71 |
|
|
$this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
|
72 |
|
|
$this->assertEqual('or', $handler->operator);
|
73 |
|
|
|
74 |
|
|
// test ands.
|
75 |
|
|
$handler = views_break_phrase_string('word1,word2,word');
|
76 |
|
|
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
|
77 |
|
|
$this->assertEqual('and', $handler->operator);
|
78 |
|
|
$handler = views_break_phrase_string('word1 word2,word');
|
79 |
|
|
$this->assertEqualValue(array('word1 word2', 'word'), $handler);
|
80 |
|
|
$this->assertEqual('and', $handler->operator);
|
81 |
|
|
$handler = views_break_phrase_string('word1,word2 word');
|
82 |
|
|
$this->assertEqualValue(array('word1', 'word2 word'), $handler);
|
83 |
|
|
$this->assertEqual('and', $handler->operator);
|
84 |
|
|
$handler = views_break_phrase_string('word-1,word-2,word');
|
85 |
|
|
$this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
|
86 |
|
|
$this->assertEqual('and', $handler->operator);
|
87 |
|
|
$handler = views_break_phrase_string('wõrd1,wõrd2,wõrd');
|
88 |
|
|
$this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
|
89 |
|
|
$this->assertEqual('and', $handler->operator);
|
90 |
|
|
|
91 |
|
|
// test a single word
|
92 |
|
|
$handler = views_break_phrase_string('word');
|
93 |
|
|
$this->assertEqualValue(array('word'), $handler);
|
94 |
|
|
$this->assertEqual('and', $handler->operator);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Tests views_break_phrase function.
|
99 |
|
|
*/
|
100 |
|
|
function test_views_break_phrase() {
|
101 |
|
|
$empty_stdclass = new stdClass();
|
102 |
|
|
$empty_stdclass->operator = 'or';
|
103 |
|
|
$empty_stdclass->value = array();
|
104 |
|
|
|
105 |
|
|
$null = NULL;
|
106 |
|
|
// check defaults
|
107 |
|
|
$this->assertEqual($empty_stdclass, views_break_phrase('', $null));
|
108 |
|
|
|
109 |
|
|
$handler = views_get_handler('node', 'title', 'argument');
|
110 |
|
|
$this->assertEqual($handler, views_break_phrase('', $handler));
|
111 |
|
|
|
112 |
|
|
// Generate three random numbers which can be used below;
|
113 |
|
|
$n1 = rand(0, 100);
|
114 |
|
|
$n2 = rand(0, 100);
|
115 |
|
|
$n3 = rand(0, 100);
|
116 |
|
|
// test ors
|
117 |
|
|
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2+$n3", $handler));
|
118 |
|
|
$this->assertEqual('or', $handler->operator);
|
119 |
|
|
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1+$n2+$n3", $handler));
|
120 |
|
|
$this->assertEqual('or', $handler->operator);
|
121 |
|
|
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2 $n3", $handler));
|
122 |
|
|
$this->assertEqual('or', $handler->operator);
|
123 |
|
|
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2++$n3", $handler));
|
124 |
|
|
$this->assertEqual('or', $handler->operator);
|
125 |
|
|
|
126 |
|
|
// test ands.
|
127 |
|
|
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1,$n2,$n3", $handler));
|
128 |
|
|
$this->assertEqual('and', $handler->operator);
|
129 |
|
|
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1,,$n2,$n3", $handler));
|
130 |
|
|
$this->assertEqual('and', $handler->operator);
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
/**
|
134 |
|
|
* Check to see if two values are equal.
|
135 |
|
|
*
|
136 |
|
|
* @param $first
|
137 |
|
|
* The first value to check.
|
138 |
|
|
* @param views_handler $handler
|
139 |
|
|
* @param string $message
|
140 |
|
|
* The message to display along with the assertion.
|
141 |
|
|
* @param string $group
|
142 |
|
|
* The type of assertion - examples are "Browser", "PHP".
|
143 |
|
|
*
|
144 |
|
|
* @return bool
|
145 |
|
|
* TRUE if the assertion succeeded, FALSE otherwise.
|
146 |
|
|
*/
|
147 |
|
|
protected function assertEqualValue($first, $handler, $message = '', $group = 'Other') {
|
148 |
|
|
return $this->assert($first == $handler->value, $message ? $message : t('First value is equal to second value'), $group);
|
149 |
|
|
}
|
150 |
|
|
} |