views_exposed_groups.test in Views exposed groups 7.2
Views Exposed Groups UI Test.
File
tests/views_exposed_groups.testView source
<?php
/**
* @file
* Views Exposed Groups UI Test.
*/
/**
* Base test class for views_exposed_groups module tests.
*/
abstract class ViewsExposedGroupsTestBase extends DrupalWebTestCase {
/**
* A user account that can create and edit views.
*
* @var object
*/
protected $privilegedUser;
/**
* A user account that can access content.
*
* @var object
*/
protected $unprivilegedUser;
/**
* Content used in the test, keyed by the entity ID.
*
* @var array
*/
protected $testNodes = [];
/**
* A default view to use for testing.
*
* @var \view
*/
protected $defaultView;
/**
* {@inheritdoc}
*/
public function setUp(array $modules = []) {
$default_modules = [
'ctools',
'views',
'views_ui',
'views_exposed_groups',
];
$modules = array_merge($modules, $default_modules);
parent::setUp($modules);
// Creates several random nodes for the view.
$this->testNodes = $this
->createNodes();
// Creates some user accounts to test with.
$this->privilegedUser = $this
->drupalCreateUser([
'access administration pages',
'access content',
'administer site configuration',
'administer views',
'bypass node access',
]);
$this->unprivilegedUser = $this
->drupalCreateUser([
'access content',
]);
// Sets some nice-to-have views configuration.
variable_set('views_ui_show_advanced_help_warning', '0');
variable_set('views_ui_show_master_display', '1');
variable_set('views_ui_show_advanced_column', '1');
// Adds a view to use for testing.
$this->defaultView = $this
->makeDefaultView();
views_save_view($this->defaultView);
}
/**
* Create multiple nodes for the test.
*
* @param int $count
* The number of nodes to create.
*
* @return array
* An array of node objects keyed by entity ID.
*/
public function createNodes($count = 5) {
$content = [];
for ($i = 0; $i < $count; $i++) {
$node = $this
->drupalCreateNode();
$content[$node->nid] = $node;
}
return $content;
}
/**
* Asserts the number of table rows in the rendered view.
*
* @param int $expected
* The expected number of rows.
* @param string $message
* A message to use.
* @param string $group
* The assertion group.
*/
public function assertViewsTableResultCount($expected = 0, $message = '', $group = 'Browser') {
$message = $message ? $message : 'Found the correct number of views results in the table display.';
$rows = $this
->xpath('//table[contains(@class, :class)]/tbody/tr', [
':class' => 'views-table',
]);
$this
->assertEqual($expected, count($rows), $message, $group);
}
/**
* Follows the exposed form options link by name.
*
* Views wraps some links in spans, which means that clickLink is not possible
* to use.
*
* @param $label
* Text between the anchor tags.
* @param $index
* Link position counting from zero.
* @return mixed
* Page contents on success, or FALSE on failure.
*/
public function clickExposedFormOptionsLink($label = '', $index = 0) {
$url_before = $this
->getUrl();
$urls = $this
->xpath('//a/span[normalize-space(text())=:label]/..', [
':label' => 'Grouped form',
]);
if (isset($urls[$index])) {
$url_target = $this
->getAbsoluteUrl($urls[$index]['href']);
$this
->pass(t('Clicked link %label (@url_target) from @url_before', array(
'%label' => $label,
'@url_target' => $url_target,
'@url_before' => $url_before,
)), 'Browser');
return $this
->drupalGet($url_target);
}
$this
->fail(t('Link %label does not exist on @url_before', array(
'%label' => $label,
'@url_before' => $url_before,
)), 'Browser');
return FALSE;
}
/**
* Creates a default view.
*
* @return \view
* A page displaying content in a table.
*/
protected function makeDefaultView() {
views_include('view');
$view = new view();
$view->name = 'views_exposed_groups_test';
$view->description = 'A basic view to test views_exposed_groups module.';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Views Exposed Groups Test';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE;
/* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view
->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'title' => 'title',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
'title' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
);
$handler->display->display_options['style_options']['empty_table'] = TRUE;
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['empty'] = TRUE;
$handler->display->display_options['empty']['area']['content'] = 'There are no results for your search.';
$handler->display->display_options['empty']['area']['format'] = 'plain_text';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['link_to_node'] = FALSE;
/* Field: Content: Delete link */
$handler->display->display_options['fields']['delete_node']['id'] = 'delete_node';
$handler->display->display_options['fields']['delete_node']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['delete_node']['field'] = 'delete_node';
/* Field: Content: Edit link */
$handler->display->display_options['fields']['edit_node']['id'] = 'edit_node';
$handler->display->display_options['fields']['edit_node']['table'] = 'views_entity_node';
$handler->display->display_options['fields']['edit_node']['field'] = 'edit_node';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Nid */
$handler->display->display_options['filters']['nid']['id'] = 'nid';
$handler->display->display_options['filters']['nid']['table'] = 'node';
$handler->display->display_options['filters']['nid']['field'] = 'nid';
$handler->display->display_options['filters']['nid']['exposed'] = TRUE;
$handler->display->display_options['filters']['nid']['expose']['operator_id'] = 'nid_op';
$handler->display->display_options['filters']['nid']['expose']['label'] = 'Nid';
$handler->display->display_options['filters']['nid']['expose']['operator'] = 'nid_op';
$handler->display->display_options['filters']['nid']['expose']['identifier'] = 'nid';
$handler->display->display_options['filters']['nid']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
);
/* Filter criterion: Content: Title */
$handler->display->display_options['filters']['title']['id'] = 'title';
$handler->display->display_options['filters']['title']['table'] = 'node';
$handler->display->display_options['filters']['title']['field'] = 'title';
$handler->display->display_options['filters']['title']['operator'] = 'contains';
$handler->display->display_options['filters']['title']['exposed'] = TRUE;
$handler->display->display_options['filters']['title']['expose']['operator_id'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['label'] = 'Title';
$handler->display->display_options['filters']['title']['expose']['operator'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['identifier'] = 'title';
$handler->display->display_options['filters']['title']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
);
/* Filter criterion: Content: Author uid */
$handler->display->display_options['filters']['uid']['id'] = 'uid';
$handler->display->display_options['filters']['uid']['table'] = 'node';
$handler->display->display_options['filters']['uid']['field'] = 'uid';
$handler->display->display_options['filters']['uid']['value'] = '';
$handler->display->display_options['filters']['uid']['exposed'] = TRUE;
$handler->display->display_options['filters']['uid']['expose']['operator_id'] = 'uid_op';
$handler->display->display_options['filters']['uid']['expose']['label'] = 'Author uid';
$handler->display->display_options['filters']['uid']['expose']['operator'] = 'uid_op';
$handler->display->display_options['filters']['uid']['expose']['identifier'] = 'uid';
$handler->display->display_options['filters']['uid']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
);
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
/* Display: Page */
$handler = $view
->new_display('page', 'Page', 'page_1');
$handler->display->display_options['path'] = 'views-exposed-group-test';
$handler->display->display_options['menu']['title'] = 'Content List';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['name'] = 'main-menu';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;
return $view;
}
}
Classes
Name | Description |
---|---|
ViewsExposedGroupsTestBase | Base test class for views_exposed_groups module tests. |