Newer
Older
Damian Lee
committed
<?php
/**
* @file
* Definition of Drupal\views\Tests\Wizard\BasicTest.
Damian Lee
committed
*/
namespace Drupal\views\Tests\Wizard;
Damian Lee
committed
/**
* Tests creating views with the wizard and viewing them on the listing page.
*/
class BasicTest extends WizardTestBase {
Damian Lee
committed
public static function getInfo() {
return array(
'name' => 'Basic functionality',
Damian Lee
committed
'description' => 'Test creating basic views with the wizard and viewing them on the listing page.',
'group' => 'Views Wizard',
Damian Lee
committed
);
}
function testViewsWizardAndListing() {
Tim Plunkett
committed
$this->drupalCreateContentType(array('type' => 'article'));
$this->drupalCreateContentType(array('type' => 'page'));
Damian Lee
committed
// Check if we can access the main views admin page.
$this->drupalGet('admin/structure/views');
$this->assertText(t('Add new view'));
// Create a simple and not at all useful view.
$view1 = array();
Angie Byron
committed
$view1['label'] = $this->randomName(16);
Angie Byron
committed
$view1['id'] = strtolower($this->randomName(16));
Damian Lee
committed
$view1['description'] = $this->randomName(16);
$view1['page[create]'] = FALSE;
Dries Buytaert
committed
$this->drupalPost('admin/structure/views/add', $view1, t('Save and edit'));
Tim Plunkett
committed
$this->assertResponse(200);
Dries Buytaert
committed
$this->drupalGet('admin/structure/views');
Angie Byron
committed
$this->assertText($view1['label']);
Damian Lee
committed
$this->assertText($view1['description']);
$this->assertLinkByHref(url('admin/structure/views/view/' . $view1['id']));
$this->assertLinkByHref(url('admin/structure/views/view/' . $view1['id'] . '/delete'));
$this->assertLinkByHref(url('admin/structure/views/view/' . $view1['id'] . '/clone'));
Damian Lee
committed
// This view should not have a block.
$this->drupalGet('admin/structure/block');
Angie Byron
committed
$this->assertNoText('View: ' . $view1['label']);
Damian Lee
committed
// Create two nodes.
$node1 = $this->drupalCreateNode(array('type' => 'page'));
$node2 = $this->drupalCreateNode(array('type' => 'article'));
// Now create a page with simple node listing and an attached feed.
$view2 = array();
Angie Byron
committed
$view2['label'] = $this->randomName(16);
Angie Byron
committed
$view2['id'] = strtolower($this->randomName(16));
Damian Lee
committed
$view2['description'] = $this->randomName(16);
$view2['page[create]'] = 1;
$view2['page[title]'] = $this->randomName(16);
$view2['page[path]'] = $this->randomName(16);
$view2['page[feed]'] = 1;
$view2['page[feed_properties][path]'] = $this->randomName(16);
Dries Buytaert
committed
$this->drupalPost('admin/structure/views/add', $view2, t('Save and edit'));
$this->drupalGet($view2['page[path]']);
Tim Plunkett
committed
$this->assertResponse(200);
Damian Lee
committed
// Since the view has a page, we expect to be automatically redirected to
// it.
$this->assertUrl($view2['page[path]']);
$this->assertText($view2['page[title]']);
Daniel Wehner
committed
$this->assertText($node1->label());
$this->assertText($node2->label());
Damian Lee
committed
// Check if we have the feed.
$this->assertLinkByHref(url($view2['page[feed_properties][path]']));
$this->drupalGet($view2['page[feed_properties][path]']);
$this->assertRaw('<rss version="2.0"');
// The feed should have the same title and nodes as the page.
$this->assertText($view2['page[title]']);
$this->assertRaw(url('node/' . $node1->nid, array('absolute' => TRUE)));
Daniel Wehner
committed
$this->assertText($node1->label());
Damian Lee
committed
$this->assertRaw(url('node/' . $node2->nid, array('absolute' => TRUE)));
Daniel Wehner
committed
$this->assertText($node2->label());
Damian Lee
committed
// Go back to the views page and check if this view is there.
$this->drupalGet('admin/structure/views');
Angie Byron
committed
$this->assertText($view2['label']);
Damian Lee
committed
$this->assertText($view2['description']);
$this->assertLinkByHref(url($view2['page[path]']));
// This view should not have a block.
$this->drupalGet('admin/structure/block');
Angie Byron
committed
$this->assertNoText('View: ' . $view2['label']);
Damian Lee
committed
// Create a view with a page and a block, and filter the listing.
$view3 = array();
Angie Byron
committed
$view3['label'] = $this->randomName(16);
Angie Byron
committed
$view3['id'] = strtolower($this->randomName(16));
Damian Lee
committed
$view3['description'] = $this->randomName(16);
$view3['show[wizard_key]'] = 'node';
$view3['show[type]'] = 'page';
$view3['page[create]'] = 1;
$view3['page[title]'] = $this->randomName(16);
$view3['page[path]'] = $this->randomName(16);
$view3['block[create]'] = 1;
$view3['block[title]'] = $this->randomName(16);
Dries Buytaert
committed
$this->drupalPost('admin/structure/views/add', $view3, t('Save and edit'));
$this->drupalGet($view3['page[path]']);
Tim Plunkett
committed
$this->assertResponse(200);
Damian Lee
committed
// Make sure the view only displays the node we expect.
$this->assertUrl($view3['page[path]']);
$this->assertText($view3['page[title]']);
Daniel Wehner
committed
$this->assertText($node1->label());
$this->assertNoText($node2->label());
Damian Lee
committed
// Go back to the views page and check if this view is there.
$this->drupalGet('admin/structure/views');
Angie Byron
committed
$this->assertText($view3['label']);
Damian Lee
committed
$this->assertText($view3['description']);
$this->assertLinkByHref(url($view3['page[path]']));
Angie Byron
committed
// Confirm that the block is available in the block administration UI.
$this->drupalGet('admin/structure/block/list/block_plugin_ui:' . config('system.theme')->get('default') . '/add');
Angie Byron
committed
$this->assertText('View: ' . $view3['label']);
Angie Byron
committed
// Place the block.
Angie Byron
committed
$this->drupalPlaceBlock("views_block:{$view3['id']}-block_1");
Damian Lee
committed
// Visit a random page (not the one that displays the view itself) and look
// for the expected node title in the block.
$this->drupalGet('user');
Daniel Wehner
committed
$this->assertText($node1->label());
$this->assertNoText($node2->label());
Damian Lee
committed
// Make sure the listing page doesn't show disabled default views.
Jennifer Hodgdon
committed
$this->assertNoText('tracker', 'Default tracker view does not show on the listing page.');
Damian Lee
committed
}
/**
* Tests the actual wizard form.
*
* @see \Drupal\views_ui\ViewAddFormController::form()
*/
protected function testWizardForm() {
$this->drupalGet('admin/structure/views/add');
Angie Byron
committed
$result = $this->xpath('//small[@id = "edit-label-machine-name-suffix"]');
$this->assertTrue(count($result), 'Ensure that the machine name is applied to the name field.');
}
Alex Pott
committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* Tests default plugin values are populated from the wizard form.
*
* @see \Drupal\views\Plugin\views\display\DisplayPluginBase::mergeDefaults().
*/
public function testWizardDefaultValues() {
$random_id = strtolower($this->randomName(16));
// Create a basic view.
$view = array();
$view['label'] = $this->randomName(16);
$view['id'] = $random_id;
$view['description'] = $this->randomName(16);
$view['page[create]'] = FALSE;
$this->drupalPost('admin/structure/views/add', $view, t('Save and edit'));
// Make sure the plugin types that should not have empty options don't have.
// Test against all values is unit tested.
// @see \Drupal\views\Tests\Plugin\DisplayUnitTest
$view = views_get_view($random_id);
$displays = $view->storage->get('display');
foreach (array('query', 'exposed_form', 'pager', 'style', 'row') as $type) {
foreach ($displays as $display) {
$this->assertFalse(empty($display['display_options'][$type]['options']), format_string('Default options found for @plugin.', array('@plugin' => $type)));
}
}
}