1 views_ui.test | ViewsUIWizardBasicTestCase::testViewsWizardAndListing() |
File
- core/
modules/ views/ tests/ views_ui.test, line 25 - Tests Views UI Wizard.
Class
- ViewsUIWizardBasicTestCase
- Tests creating views with the wizard and viewing them on the listing page.
Code
function testViewsWizardAndListing() {
// Check if we can access the main views admin page.
$this->backdropGet('admin/structure/views');
$this->assertLinkByHref(url('admin/config/development/configuration/single/export'));
$this->assertText(t('Add view'));
// Create a simple and not at all useful view.
$view1 = array();
$view1['human_name'] = $this->randomName(16);
$view1['name'] = strtolower($this->randomName(16));
$view1['description'] = $this->randomName(16);
$view1['page[create]'] = FALSE;
$this->backdropPost('admin/structure/views/add', $view1, t('Save view'));
$this->assertText(t('Your view was saved. You may configure it from the list below.'));
$this->assertText($view1['human_name']);
$this->assertText($view1['description']);
foreach (array('/delete', '/clone', '') as $operation) {
$this->assertLinkByHref(url('admin/structure/views/view/' . $view1['name'] . $operation));
}
$this->assertLinkByHref(url('admin/config/development/configuration/single/export'));
// This view should not have a block.
$this->backdropGet('admin/structure/block');
$this->assertNoText('View: ' . $view1['human_name']);
// Create two nodes.
$node1 = $this->backdropCreateNode(array('type' => 'page'));
$node2 = $this->backdropCreateNode(array('type' => 'post'));
// Now create a page with simple node listing and an attached feed.
$view2 = array();
$view2['human_name'] = $this->randomName(16);
$view2['name'] = strtolower($this->randomName(16));
$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);
$this->backdropPost('admin/structure/views/add', $view2, t('Save view'));
// Since the view has a page, we expect to be automatically redirected to
// it.
$this->assertUrl($view2['page[path]']);
$this->assertText($view2['page[title]']);
$this->assertText($node1->title);
$this->assertText($node2->title);
// Check if we have the feed.
$link = $this->xpath('/html/head/link[@type="application/rss+xml"][@href=:url]', array(
':url' => url($view2['page[feed_properties][path]'], array('absolute' => TRUE)),
));
$this->assertEqual(count($link), 1, 'RSS Feed found in page header.');
$this->backdropGet($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)));
$this->assertText($node1->title);
$this->assertRaw(url('node/' . $node2->nid, array('absolute' => TRUE)));
$this->assertText($node2->title);
// Go back to the views page and check if this view is there.
$this->backdropGet('admin/structure/views');
$this->assertText($view2['human_name']);
$this->assertText($view2['description']);
$this->assertLinkByHref(url($view2['page[path]']));
// This view should not have a block.
$this->backdropGet('admin/structure/block');
$this->assertNoText('View: ' . $view2['human_name']);
// Create a view with a page and a block, and filter the listing.
$view3 = array();
$view3['human_name'] = $this->randomName(16);
$view3['name'] = strtolower($this->randomName(16));
$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);
$this->backdropPost('admin/structure/views/add', $view3, t('Save view'));
// Make sure the view only displays the node we expect.
$this->assertUrl($view3['page[path]']);
$this->assertText($view3['page[title]']);
$this->assertText($node1->title);
$this->assertNoText($node2->title);
// Go back to the views page and check if this view is there.
$this->backdropGet('admin/structure/views');
$this->assertText($view3['human_name']);
$this->assertText($view3['description']);
$this->assertLinkByHref(url($view3['page[path]']));
views_invalidate_cache();
$layout = layout_load('default');
$layout->addBlock('views', $view3['name'] . '-block', 'sidebar');
$layout->save();
// Visit a random page (not the one that displays the view itself) and look
// for the expected node title in the block.
$this->backdropGet('user');
$this->assertText($node1->title);
$this->assertNoText($node2->title);
}