summaryrefslogtreecommitdiffstats
path: root/views_natural_sort.test
blob: 42da5ac0494eeb2950a272fbe0df21ad7c59a6aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php

/**
 * @file
 */

module_load_include('test', 'views', 'tests/views_query');
/**
 *
 */
class ViewsNaturalSortBasicTest extends ViewsTestCase {

  /**
   *
   */
  public static function getInfo() {
    return array(
      'name' => 'Views Natural Sort Basic Test',
      'description' => 'Tests basic functionality of View Natural Sort',
      'group' => 'Views Natural Sort',
    );
  }

  /**
   *
   */
  protected function setUp() {
    parent::setUp('views', 'views_natural_sort', 'views_natural_sort_test');
  }

  /**
   *
   */
  public function testNaturalSortDefaultBeginningWords() {
    $titles = array(
      'A Stripped Zebra',
      'Oklahoma',
      'The King And I',
    );
    $nodes = array();
    foreach ($titles as $title) {
      $nodes[] = $this->drupalCreateNode(array(
        'type' => 'views_natural_sort_test_content',
        'title' => $title,
      ));
    }
    $view = views_get_view('views_natural_sort_test');
    $this->executeView($view);
    $this->assertIdenticalResultset(
      $view,
      array(
        array('title' => 'The King And I'),
        array('title' => 'Oklahoma'),
        array('title' => 'A Stripped Zebra'),
      ),
      array('node_title' => 'title')
    );
  }

  /**
   *
   */
  public function testNaturalSortDefaultSymbols() {
    $titles = array(
      'A(Z',
      'A[B',
      'A\\C',
    );
    foreach ($titles as $title) {
      $nodes[] = $this->drupalCreateNode(array(
        'type' => 'views_natural_sort_test_content',
        'title' => $title,
      ));
    }
    $view = views_get_view('views_natural_sort_test');
    $this->executeView($view);
    $this->assertIdenticalResultset(
      $view,
      array(
        array('title' => 'A[B'),
        array('title' => 'A\\C'),
        array('title' => 'A(Z'),
      ),
      array('node_title' => 'title')
    );
  }

  /**
   *
   */
  public function testNaturalSortNumbers() {
    $titles = array(
      '1 apple',
      '2 apples',
      '10 apples',
      '-1 apples',
      '-10 apples',
      '-2 appels',
      '-3.550 apples',
      '-3.5501 apples',
      '3.5501 apples',
      '3.550 apples',
    );
    foreach ($titles as $title) {
      $nodes[] = $this->drupalCreateNode(array(
        'type' => 'views_natural_sort_test_content',
        'title' => $title,
      ));
    }
    $view = views_get_view('views_natural_sort_test');
    $this->executeView($view);
    $this->assertIdenticalResultset(
      $view,
      array(
        array('title' => '-10 apples'),
        array('title' => '-3.5501 apples'),
        array('title' => '-3.550 apples'),
        array('title' => '-2 apples'),
        array('title' => '-1 apples'),
        array('title' => '1 apple'),
        array('title' => '2 apples'),
        array('title' => '3.550 apples'),
        array('title' => '3.5501 apples'),
        array('title' => '10 apples'),
      ),
      array('node_title' => 'title')
    );
  }

}
/**
 *
 */
class ViewsNaturalSortDaysOfTheWeekTest extends DrupalWebTestCase {

  /**
   *
   */
  public static function getInfo() {
    return array(
      'name' => 'Views Natural Sort Days of the Week',
      'description' => 'Tests Days of the Week Sorting',
      'group' => 'Views Natural Sort',
    );
  }

  /**
   *
   */
  protected function setUp() {
    parent::setUp('views', 'views_natural_sort');
    variable_set('views_natural_sort_days_of_the_week_enabled', TRUE);
  }

  /**
   *
   */
  public function testDefaultDayReplace() {
    foreach (views_natural_sort_days_of_the_week_get_default_days() as $replaced => $day) {
      $this->assertEqual(views_natural_sort_days_of_the_week_sort_days($day), $replaced);
    }
  }

  /**
   *
   */
  public function testFirstDayMonday() {
    variable_set("views_natural_sort_days_of_the_week_first_day_en", "Monday");
    $expected = array(
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday",
      "Sunday",
    );
    foreach ($expected as $replaced => $day) {
      $this->assertEqual(views_natural_sort_days_of_the_week_sort_days($day), $replaced);
    }
  }

  /**
   *
   */
  public function testAbbreviations() {
    $expected = array(
      "Sun",
      "Mon.",
      "Tues",
      "Wed",
      "Thur",
      "Fri.",
      "Sat",
    );
    foreach ($expected as $replaced => $day) {
      $this->assertEqual(views_natural_sort_days_of_the_week_sort_days($day), $replaced);
    }
  }

}