View source
<?php
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 testNaturalSortUnicodeSymbols() {
module_load_include('inc', 'views_natural_sort', 'views_natural_sort');
variable_set('views_natural_sort_symbols_remove', "#…\",'\\()[]«?!»¡¿");
$titles = array(
'Cuando… se abre, ¿dará algún tipo de señal?',
);
$expected = array(
'Cuando se abre dará algún tipo de señal',
);
foreach ($titles as $key => $title) {
$this
->assertEqual(views_natural_sort_remove_symbols($title), $expected[$key]);
}
}
public function testNaturalSortNumbers() {
$titles = array(
'1 apple',
'2 apples',
'10 apples',
'-1 apples',
'-10 apples',
'-2 apples',
'-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',
));
}
public function testStoringLongUnicode() {
$node = $this
->drupalCreateNode(array(
'type' => 'views_natural_sort_test_content',
'title' => str_repeat('⌘', 255),
));
$content = db_select('views_natural_sort', 'vns')
->fields('vns', array(
'content',
))
->condition('vns.eid', $node->nid)
->condition('vns.entity_type', 'node')
->execute()
->fetchField();
$this
->assertEqual($content, str_repeat('⌘', 255));
}
}
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() {
module_load_include('inc', 'views_natural_sort', 'views_natural_sort');
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");
module_load_include('inc', 'views_natural_sort', 'views_natural_sort');
$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() {
module_load_include('inc', 'views_natural_sort', 'views_natural_sort');
$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);
}
}
}