Version 1
[yaffs-website] / web / core / modules / views / tests / src / Functional / Handler / ArgumentStringTest.php
1 <?php
2
3 namespace Drupal\Tests\views\Functional\Handler;
4
5 use Drupal\Tests\views\Functional\ViewTestBase;
6 use Drupal\views\Views;
7
8 /**
9  * Tests the core Drupal\views\Plugin\views\argument\StringArgument handler.
10  *
11  * @group views
12  */
13 class ArgumentStringTest extends ViewTestBase {
14
15   /**
16    * Views used by this test.
17    *
18    * @var array
19    */
20   public static $testViews = ['test_glossary'];
21
22   /**
23    * Modules to enable.
24    *
25    * @var array
26    */
27   public static $modules = ['node'];
28
29   /**
30    * Tests the glossary feature.
31    */
32   public function testGlossary() {
33     // Setup some nodes, one with a, two with b and three with c.
34     $counter = 1;
35     foreach (['a', 'b', 'c'] as $char) {
36       for ($i = 0; $i < $counter; $i++) {
37         $edit = [
38           'title' => $char . $this->randomMachineName(),
39         ];
40         $this->drupalCreateNode($edit);
41       }
42     }
43
44     $view = Views::getView('test_glossary');
45     $this->executeView($view);
46
47     $count_field = 'nid';
48     foreach ($view->result as &$row) {
49       if (strpos($view->field['title']->getValue($row), 'a') === 0) {
50         $this->assertEqual(1, $row->{$count_field});
51       }
52       if (strpos($view->field['title']->getValue($row), 'b') === 0) {
53         $this->assertEqual(2, $row->{$count_field});
54       }
55       if (strpos($view->field['title']->getValue($row), 'c') === 0) {
56         $this->assertEqual(3, $row->{$count_field});
57       }
58     }
59   }
60
61 }