3 namespace Drupal\Tests\views_ui\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
8 * Tests views creation wizard.
10 * @see core/modules/views_ui/js/views-admin.js
13 class ViewsWizardTest extends JavascriptTestBase {
18 public static $modules = ['node', 'views', 'views_ui', 'block', 'user'];
23 protected function setUp() {
26 $admin_user = $this->drupalCreateUser([
27 'administer site configuration',
30 $this->drupalLogin($admin_user);
34 * Tests creating a View using the wizard.
36 public function testCreateViewWizard() {
37 $this->drupalGet('admin/structure/views/add');
38 $page = $this->getSession()->getPage();
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);
46 $page->findField('page[create]')->click();
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());
52 // Create a menu item.
53 $page->findField('page[link]')->click();
54 $this->assertEquals($label_value, $page->findField('page[link_properties][title]')->getValue());
56 // Add a block display.
57 $page->findField('block[create]')->click();
58 $this->assertEquals($label_value, $page->findField('block[title]')->getValue());
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.');
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.');
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.');