Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / tests / src / Functional / Form / ElementsVerticalTabsTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Form;
4
5 use Drupal\Component\Render\FormattableMarkup;
6 use Drupal\Component\Serialization\Json;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Tests the vertical_tabs form element for expected behavior.
11  *
12  * @group Form
13  */
14 class ElementsVerticalTabsTest extends BrowserTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['form_test'];
22
23   /**
24    * A user with permission to access vertical_tab_test_tabs.
25    *
26    * @var \Drupal\user\UserInterface
27    */
28   protected $adminUser;
29
30   /**
31    * A normal user.
32    *
33    * @var \Drupal\user\UserInterface
34    */
35   protected $webUser;
36
37   protected function setUp() {
38     parent::setUp();
39
40     $this->adminUser = $this->drupalCreateUser(['access vertical_tab_test tabs']);
41     $this->webUser = $this->drupalCreateUser();
42     $this->drupalLogin($this->adminUser);
43   }
44
45   /**
46    * Ensures that vertical-tabs.js is included before collapse.js.
47    *
48    * Otherwise, collapse.js adds "SHOW" or "HIDE" labels to the tabs.
49    */
50   public function testJavaScriptOrdering() {
51     $this->drupalGet('form_test/vertical-tabs');
52     $content = $this->getSession()->getPage()->getContent();
53     $position1 = strpos($content, 'core/misc/vertical-tabs.js');
54     $position2 = strpos($content, 'core/misc/collapse.js');
55     $this->assertTrue($position1 !== FALSE && $position2 !== FALSE && $position1 < $position2, 'vertical-tabs.js is included before collapse.js');
56   }
57
58   /**
59    * Ensures that vertical tab markup is not shown if user has no tab access.
60    */
61   public function testWrapperNotShownWhenEmpty() {
62     // Test admin user can see vertical tabs and wrapper.
63     $this->drupalGet('form_test/vertical-tabs');
64     $wrapper = $this->xpath("//div[@data-vertical-tabs-panes]");
65     $this->assertTrue(isset($wrapper[0]), 'Vertical tab panes found.');
66
67     // Test wrapper markup not present for non-privileged web user.
68     $this->drupalLogin($this->webUser);
69     $this->drupalGet('form_test/vertical-tabs');
70     $wrapper = $this->xpath("//div[@data-vertical-tabs-panes]");
71     $this->assertFalse(isset($wrapper[0]), 'Vertical tab wrappers are not displayed to unprivileged users.');
72   }
73
74   /**
75    * Ensures that default vertical tab is correctly selected.
76    */
77   public function testDefaultTab() {
78     $this->drupalGet('form_test/vertical-tabs');
79
80     $value = $this->assertSession()
81       ->elementExists('css', 'input[name="vertical_tabs__active_tab"]')
82       ->getValue();
83
84     $this->assertSame('edit-tab3', $value, t('The default vertical tab is correctly selected.'));
85   }
86
87   /**
88    * Ensures that vertical tab form values are cleaned.
89    */
90   public function testDefaultTabCleaned() {
91     $values = Json::decode($this->drupalPostForm('form_test/form-state-values-clean', [], t('Submit')));
92     $this->assertFalse(isset($values['vertical_tabs__active_tab']), new FormattableMarkup('%element was removed.', ['%element' => 'vertical_tabs__active_tab']));
93   }
94
95 }