3fb1167e1f3bbabed204a162ca944467d1d4d55b
[yaffs-website] / web / core / modules / views_ui / tests / src / FunctionalJavascript / ViewsWizardTest.php
1 <?php
2
3 namespace Drupal\Tests\views_ui\FunctionalJavascript;
4
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
6
7 /**
8  * Tests views creation wizard.
9  *
10  * @see core/modules/views_ui/js/views-admin.js
11  * @group views_ui
12  */
13 class ViewsWizardTest extends JavascriptTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['node', 'views', 'views_ui', 'block', 'user'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     parent::setUp();
25
26     $admin_user = $this->drupalCreateUser([
27       'administer site configuration',
28       'administer views',
29     ]);
30     $this->drupalLogin($admin_user);
31   }
32
33   /**
34    * Tests creating a View using the wizard.
35    */
36   public function testCreateViewWizard() {
37     $this->drupalGet('admin/structure/views/add');
38     $page = $this->getSession()->getPage();
39
40     // Set a view name, this should be used to prepopulate a number of other
41     // fields when creating displays.
42     $label_value = 'test view';
43     $search_input = $page->findField('label');
44     $search_input->setValue($label_value);
45
46     $page->findField('page[create]')->click();
47
48     // Test if the title and path have been populated.
49     $this->assertEquals($label_value, $page->findField('page[title]')->getValue());
50     $this->assertEquals(str_replace(' ', '-', $label_value), $page->findField('page[path]')->getValue());
51
52     // Create a menu item.
53     $page->findField('page[link]')->click();
54     $this->assertEquals($label_value, $page->findField('page[link_properties][title]')->getValue());
55
56     // Add a block display.
57     $page->findField('block[create]')->click();
58     $this->assertEquals($label_value, $page->findField('block[title]')->getValue());
59
60     // Select the entity type to display and test that the type selector is
61     // shown when expected.
62     $page->selectFieldOption('show[wizard_key]', 'node');
63     $this->assertSession()->assertWaitOnAjaxRequest();
64     $this->assertNull($page->findField('show[type]'), 'The "of type" filter is not added for nodes when there are no node types.');
65     $this->assertEquals('teasers', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format shows the expected default value.');
66     $this->assertEquals('titles_linked', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format shows the expected default value.');
67
68     $page->selectFieldOption('show[wizard_key]', 'users');
69     $this->assertSession()->assertWaitOnAjaxRequest();
70     $this->assertNull($page->findField('show[type]'), 'The "of type" filter is not added for users.');
71     $this->assertEquals('fields', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format was updated to a valid value.');
72     $this->assertEquals('fields', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format was updated to a valid value.');
73
74     $this->drupalCreateContentType(['type' => 'page']);
75     $page->selectFieldOption('show[wizard_key]', 'node');
76     $this->assertSession()->assertWaitOnAjaxRequest();
77     $this->assertNotNull($page->findField('show[type]'), 'The "of type" filter is added for nodes when there is at least one node type.');
78     $this->assertEquals('fields', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format was not changed from a valid value.');
79     $this->assertEquals('fields', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format was not changed from a valid value.');
80   }
81
82 }