Backup of db before drupal security update
[yaffs-website] / web / core / modules / system / src / Tests / Database / SelectTableSortDefaultTest.php
1 <?php
2
3 namespace Drupal\system\Tests\Database;
4
5 /**
6  * Tests the tablesort query extender.
7  *
8  * @group Database
9  */
10 class SelectTableSortDefaultTest extends DatabaseWebTestBase {
11
12   /**
13    * Confirms that a tablesort query returns the correct results.
14    *
15    * Note that we have to make an HTTP request to a test page handler
16    * because the pager depends on GET parameters.
17    */
18   public function testTableSortQuery() {
19     $sorts = [
20       ['field' => t('Task ID'), 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'],
21       ['field' => t('Task ID'), 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'],
22       ['field' => t('Task'), 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'],
23       ['field' => t('Task'), 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'],
24       // more elements here
25
26     ];
27
28     foreach ($sorts as $sort) {
29       $this->drupalGet('database_test/tablesort/', ['query' => ['order' => $sort['field'], 'sort' => $sort['sort']]]);
30       $data = json_decode($this->getRawContent());
31
32       $first = array_shift($data->tasks);
33       $last = array_pop($data->tasks);
34
35       $this->assertEqual($first->task, $sort['first'], 'Items appear in the correct order.');
36       $this->assertEqual($last->task, $sort['last'], 'Items appear in the correct order.');
37     }
38   }
39
40   /**
41    * Confirms precedence of tablesorts headers.
42    *
43    * If a tablesort's orderByHeader is called before another orderBy, then its
44    * header happens first.
45    */
46   public function testTableSortQueryFirst() {
47     $sorts = [
48       ['field' => t('Task ID'), 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'],
49       ['field' => t('Task ID'), 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'],
50       ['field' => t('Task'), 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'],
51       ['field' => t('Task'), 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'],
52       // more elements here
53
54     ];
55
56     foreach ($sorts as $sort) {
57       $this->drupalGet('database_test/tablesort_first/', ['query' => ['order' => $sort['field'], 'sort' => $sort['sort']]]);
58       $data = json_decode($this->getRawContent());
59
60       $first = array_shift($data->tasks);
61       $last = array_pop($data->tasks);
62
63       $this->assertEqual($first->task, $sort['first'], format_string('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']]));
64       $this->assertEqual($last->task, $sort['last'], format_string('Items appear in the correct order sorting by @field @sort.', ['@field' => $sort['field'], '@sort' => $sort['sort']]));
65     }
66   }
67
68   /**
69    * Confirms that tableselect is rendered without error.
70    *
71    * Specifically that no sort is set in a tableselect, and that header links
72    * are correct.
73    */
74   public function testTableSortDefaultSort() {
75     $this->drupalGet('database_test/tablesort_default_sort');
76
77     // Verify that the table was displayed. Just the header is checked for
78     // because if there were any fatal errors or exceptions in displaying the
79     // sorted table, it would not print the table.
80     $this->assertText(t('Username'));
81
82     // Verify that the header links are built properly.
83     $this->assertLinkByHref('database_test/tablesort_default_sort');
84     $this->assertPattern('/\<a.*title\=\"' . t('sort by Username') . '\".*\>/');
85   }
86
87 }