first import
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of viewsHandlerArgumentCommentUserUidTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the argument_comment_user_uid handler.
|
||||
*/
|
||||
class viewsHandlerArgumentCommentUserUidTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests handler argument_comment_user_uid',
|
||||
'description' => 'Tests the user posted or commented argument handler',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post comment.
|
||||
*
|
||||
* @param $node
|
||||
* Node to post comment on.
|
||||
* @param $comment
|
||||
* Comment to save
|
||||
*/
|
||||
function postComment($node, $comment = array()) {
|
||||
$comment += array(
|
||||
'uid' => $this->loggedInUser->uid,
|
||||
'nid' => $node->nid,
|
||||
'cid' => '',
|
||||
'pid' => '',
|
||||
);
|
||||
return comment_save((object) $comment);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Add two users, create a node with the user1 as author and another node with user2 as author.
|
||||
// For the second node add a comment from user1.
|
||||
$this->account = $this->drupalCreateUser();
|
||||
$this->account2 = $this->drupalCreateUser();
|
||||
$this->drupalLogin($this->account);
|
||||
$this->node_user_posted = $this->drupalCreateNode();
|
||||
$this->node_user_commented = $this->drupalCreateNode(array('uid' => $this->account2->uid));
|
||||
$this->postComment($this->node_user_commented);
|
||||
}
|
||||
|
||||
function testCommentUserUidTest() {
|
||||
$view = $this->view_comment_user_uid();
|
||||
|
||||
|
||||
$this->executeView($view, array($this->account->uid));
|
||||
$resultset = array(
|
||||
array(
|
||||
'nid' => $this->node_user_posted->nid,
|
||||
),
|
||||
array(
|
||||
'nid' => $this->node_user_commented->nid,
|
||||
),
|
||||
);
|
||||
$this->column_map = array('nid' => 'nid');
|
||||
debug($view->result);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function view_comment_user_uid() {
|
||||
$view = new view;
|
||||
$view->name = 'test_comment_user_uid';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'test_comment_user_uid';
|
||||
$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['access']['type'] = 'perm';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
/* Field: Content: nid */
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'nid';
|
||||
/* Contextual filter: Content: User posted or commented */
|
||||
$handler->display->display_options['arguments']['uid_touch']['id'] = 'uid_touch';
|
||||
$handler->display->display_options['arguments']['uid_touch']['table'] = 'node';
|
||||
$handler->display->display_options['arguments']['uid_touch']['field'] = 'uid_touch';
|
||||
$handler->display->display_options['arguments']['uid_touch']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['uid_touch']['default_argument_skip_url'] = 0;
|
||||
$handler->display->display_options['arguments']['uid_touch']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['uid_touch']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['uid_touch']['summary_options']['items_per_page'] = '25';
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of viewsHandlerFilterCommentUserUidTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the filter_comment_user_uid handler.
|
||||
*
|
||||
* The actual stuff is done in the parent class.
|
||||
*/
|
||||
class viewsHandlerFilterCommentUserUidTest extends viewsHandlerArgumentCommentUserUidTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests handler filter_comment_user_uid',
|
||||
'description' => 'Tests the user posted or commented filter handler',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the view from the argument test case to remove the argument and
|
||||
* add filter with the uid as the value.
|
||||
*/
|
||||
function view_comment_user_uid() {
|
||||
$view = parent::view_comment_user_uid();
|
||||
// Remove the argument.
|
||||
$view->set_item('default', 'argument', 'uid_touch', NULL);
|
||||
|
||||
$options = array(
|
||||
'id' => 'uid_touch',
|
||||
'table' => 'node',
|
||||
'field' => 'uid_touch',
|
||||
'value' => array($this->loggedInUser->uid),
|
||||
);
|
||||
$view->add_item('default', 'filter', 'node', 'uid_touch', $options);
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
494
sites/all/modules/views/tests/field/views_fieldapi.test
Normal file
494
sites/all/modules/views/tests/field/views_fieldapi.test
Normal file
@@ -0,0 +1,494 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests the fieldapi integration of viewsdata.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
* - Test on a generic entity not on a node.
|
||||
*
|
||||
* What has to be tested:
|
||||
* - Take sure that every wanted field is added to the according entity type.
|
||||
* - Take sure the joins are done correct.
|
||||
* - Use basic fields and take sure that the full wanted object is build.
|
||||
* - Use relationships between different entity types, for example node and the node author(user).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides some helper methods for testing fieldapi integration into views.
|
||||
*/
|
||||
class ViewsFieldApiTestHelper extends ViewsSqlTest {
|
||||
/**
|
||||
* Stores the field definitions used by the test.
|
||||
* @var array
|
||||
*/
|
||||
public $fields;
|
||||
/**
|
||||
* Stores the instances of the fields. They have
|
||||
* the same keys as the fields.
|
||||
* @var array
|
||||
*/
|
||||
public $instances;
|
||||
|
||||
protected function CreateUser($extra_edit = array()) {
|
||||
$permissions = array('access comments', 'access content', 'post comments', 'skip comment approval');
|
||||
// Create a role with the given permission set.
|
||||
if (!($rid = $this->drupalCreateRole($permissions))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Create a user assigned to that role.
|
||||
$edit = array();
|
||||
$edit['name'] = $this->randomName();
|
||||
$edit['mail'] = $edit['name'] . '@example.com';
|
||||
$edit['roles'] = array($rid => $rid);
|
||||
$edit['pass'] = user_password();
|
||||
$edit['status'] = 1;
|
||||
$edit += $extra_edit;
|
||||
|
||||
$account = user_save(drupal_anonymous_user(), $edit);
|
||||
|
||||
$this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login'));
|
||||
if (empty($account->uid)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Add the raw password so that we can log in as this user.
|
||||
$account->pass_raw = $edit['pass'];
|
||||
return $account;
|
||||
}
|
||||
|
||||
function setUpFields($amount = 3) {
|
||||
// Create three fields.
|
||||
$field_names = array();
|
||||
for ($i = 0; $i < $amount; $i++) {
|
||||
$field_names[$i] = 'field_name_' . $i;
|
||||
$field = array('field_name' => $field_names[$i], 'type' => 'text');
|
||||
|
||||
$this->fields[$i] = $field = field_create_field($field);
|
||||
}
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
function setUpInstances($bundle = 'page') {
|
||||
foreach ($this->fields as $key => $field) {
|
||||
$instance = array(
|
||||
'field_name' => $field['field_name'],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
);
|
||||
$this->instances[$key] = field_create_instance($instance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all views caches and static caches which are required for the patch.
|
||||
*/
|
||||
function clearViewsCaches() {
|
||||
// Reset views data cache.
|
||||
drupal_static_reset('_views_fetch_data_cache');
|
||||
drupal_static_reset('_views_fetch_data_recursion_protected');
|
||||
drupal_static_reset('_views_fetch_data_fully_loaded');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the produced views_data.
|
||||
*/
|
||||
class viewsFieldApiDataTest extends ViewsFieldApiTestHelper {
|
||||
/**
|
||||
* Stores the fields for this test case.
|
||||
*/
|
||||
var $fields;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Fieldapi: Views Data',
|
||||
'description' => 'Tests the fieldapi views data.',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$langcode = LANGUAGE_NONE;
|
||||
|
||||
|
||||
$field_names = $this->setUpFields();
|
||||
|
||||
// The first one will be attached to nodes only.
|
||||
$instance = array(
|
||||
'field_name' => $field_names[0],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
|
||||
// The second one will be attached to users only.
|
||||
$instance = array(
|
||||
'field_name' => $field_names[1],
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
|
||||
// The third will be attached to both nodes and users.
|
||||
$instance = array(
|
||||
'field_name' => $field_names[2],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
$instance = array(
|
||||
'field_name' => $field_names[2],
|
||||
'entity_type' => 'user',
|
||||
'bundle' => 'user',
|
||||
);
|
||||
field_create_instance($instance);
|
||||
|
||||
// Now create some example nodes/users for the view result.
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$edit = array(
|
||||
// @TODO Write a helper method to create such values.
|
||||
'field_name_0' => array($langcode => array((array('value' => $this->randomName())))),
|
||||
'field_name_2' => array($langcode => array((array('value' => $this->randomName())))),
|
||||
);
|
||||
$this->nodes[] = $this->drupalCreateNode($edit);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$edit = array(
|
||||
'field_name_1' => array($langcode => array((array('value' => $this->randomName())))),
|
||||
'field_name_2' => array($langcode => array((array('value' => $this->randomName())))),
|
||||
);
|
||||
$this->users[] = $this->CreateUser($edit);
|
||||
}
|
||||
|
||||
// Reset views data cache.
|
||||
$this->clearViewsCaches();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit testing the views data structure.
|
||||
*
|
||||
* We check data structure for both node and node revision tables.
|
||||
*/
|
||||
function testViewsData() {
|
||||
$data = views_fetch_data();
|
||||
|
||||
// Check the table and the joins of the first field.
|
||||
// Attached to node only.
|
||||
$field = $this->fields[0];
|
||||
$current_table = _field_sql_storage_tablename($field);
|
||||
$revision_table = _field_sql_storage_revision_tablename($field);
|
||||
|
||||
$this->assertTrue(isset($data[$current_table]));
|
||||
$this->assertTrue(isset($data[$revision_table]));
|
||||
// The node field should join against node.
|
||||
$this->assertTrue(isset($data[$current_table]['table']['join']['node']));
|
||||
$this->assertTrue(isset($data[$revision_table]['table']['join']['node_revision']));
|
||||
|
||||
$expected_join = array(
|
||||
'left_field' => 'nid',
|
||||
'field' => 'entity_id',
|
||||
'extra' => array(
|
||||
array('field' => 'entity_type', 'value' => 'node'),
|
||||
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
|
||||
),
|
||||
);
|
||||
$this->assertEqual($expected_join, $data[$current_table]['table']['join']['node']);
|
||||
$expected_join = array(
|
||||
'left_field' => 'vid',
|
||||
'field' => 'revision_id',
|
||||
'extra' => array(
|
||||
array('field' => 'entity_type', 'value' => 'node'),
|
||||
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
|
||||
),
|
||||
);
|
||||
$this->assertEqual($expected_join, $data[$revision_table]['table']['join']['node_revision']);
|
||||
|
||||
|
||||
// Check the table and the joins of the second field.
|
||||
// Attached to both node and user.
|
||||
$field_2 = $this->fields[2];
|
||||
$current_table_2 = _field_sql_storage_tablename($field_2);
|
||||
$revision_table_2 = _field_sql_storage_revision_tablename($field_2);
|
||||
|
||||
$this->assertTrue(isset($data[$current_table_2]));
|
||||
$this->assertTrue(isset($data[$revision_table_2]));
|
||||
// The second field should join against both node and users.
|
||||
$this->assertTrue(isset($data[$current_table_2]['table']['join']['node']));
|
||||
$this->assertTrue(isset($data[$revision_table_2]['table']['join']['node_revision']));
|
||||
$this->assertTrue(isset($data[$current_table_2]['table']['join']['users']));
|
||||
|
||||
$expected_join = array(
|
||||
'left_field' => 'nid',
|
||||
'field' => 'entity_id',
|
||||
'extra' => array(
|
||||
array('field' => 'entity_type', 'value' => 'node'),
|
||||
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
|
||||
)
|
||||
);
|
||||
$this->assertEqual($expected_join, $data[$current_table_2]['table']['join']['node']);
|
||||
$expected_join = array(
|
||||
'left_field' => 'vid',
|
||||
'field' => 'revision_id',
|
||||
'extra' => array(
|
||||
array('field' => 'entity_type', 'value' => 'node'),
|
||||
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
|
||||
)
|
||||
);
|
||||
$this->assertEqual($expected_join, $data[$revision_table_2]['table']['join']['node_revision']);
|
||||
$expected_join = array(
|
||||
'left_field' => 'uid',
|
||||
'field' => 'entity_id',
|
||||
'extra' => array(
|
||||
array('field' => 'entity_type', 'value' => 'user'),
|
||||
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
|
||||
)
|
||||
);
|
||||
$this->assertEqual($expected_join, $data[$current_table_2]['table']['join']['users']);
|
||||
|
||||
// Check the fields
|
||||
// @todo
|
||||
|
||||
// Check the arguments
|
||||
// @todo
|
||||
|
||||
// Check the sort criterias
|
||||
// @todo
|
||||
|
||||
// Check the relationships
|
||||
// @todo
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the field_field handler.
|
||||
* @TODO
|
||||
* Check a entity-type with bundles
|
||||
* Check a entity-type without bundles
|
||||
* Check locale:disabled, locale:enabled and locale:enabled with another language
|
||||
* Check revisions
|
||||
*/
|
||||
class viewsHandlerFieldFieldTest extends ViewsFieldApiTestHelper {
|
||||
public $nodes;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Fieldapi: Field handler',
|
||||
'description' => 'Tests the field itself of the fieldapi integration',
|
||||
'group' => 'Views Modules'
|
||||
);
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Setup basic fields.
|
||||
$this->setUpFields(3);
|
||||
|
||||
// Setup a field with cardinality > 1.
|
||||
$this->fields[3] = $field = field_create_field(array('field_name' => 'field_name_3', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED));
|
||||
// Setup a field that will have no value.
|
||||
$this->fields[4] = $field = field_create_field(array('field_name' => 'field_name_4', 'type' => 'text', 'cardinality' => FIELD_CARDINALITY_UNLIMITED));
|
||||
|
||||
$this->setUpInstances();
|
||||
|
||||
$this->clearViewsCaches();
|
||||
|
||||
// Create some nodes.
|
||||
$this->nodes = array();
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$edit = array('type' => 'page');
|
||||
|
||||
for ($key = 0; $key < 3; $key++) {
|
||||
$field = $this->fields[$key];
|
||||
$edit[$field['field_name']][LANGUAGE_NONE][0]['value'] = $this->randomName(8);
|
||||
}
|
||||
for ($j = 0; $j < 5; $j++) {
|
||||
$edit[$this->fields[3]['field_name']][LANGUAGE_NONE][$j]['value'] = $this->randomName(8);
|
||||
}
|
||||
// Set this field to be empty.
|
||||
$edit[$this->fields[4]['field_name']] = array();
|
||||
|
||||
$this->nodes[$i] = $this->drupalCreateNode($edit);
|
||||
}
|
||||
}
|
||||
|
||||
public function testFieldRender() {
|
||||
$this->_testSimpleFieldRender();
|
||||
$this->_testFormatterSimpleFieldRender();
|
||||
$this->_testMultipleFieldRender();
|
||||
}
|
||||
|
||||
public function _testSimpleFieldRender() {
|
||||
$view = $this->getFieldView();
|
||||
$this->executeView($view);
|
||||
|
||||
// Tests that the rendered fields match the actual value of the fields.
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
for ($key = 0; $key < 2; $key++) {
|
||||
$field = $this->fields[$key];
|
||||
$rendered_field = $view->style_plugin->get_field($i, $field['field_name']);
|
||||
$expected_field = $this->nodes[$i]->{$field['field_name']}[LANGUAGE_NONE][0]['value'];
|
||||
$this->assertEqual($rendered_field, $expected_field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that fields with formatters runs as expected.
|
||||
*/
|
||||
public function _testFormatterSimpleFieldRender() {
|
||||
$view = $this->getFieldView();
|
||||
$view->display['default']->display_options['fields'][$this->fields[0]['field_name']]['type'] = 'text_trimmed';
|
||||
$view->display['default']->display_options['fields'][$this->fields[0]['field_name']]['settings'] = array(
|
||||
'trim_length' => 3,
|
||||
);
|
||||
$this->executeView($view);
|
||||
|
||||
// Take sure that the formatter works as expected.
|
||||
// @TODO: actually there should be a specific formatter.
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$rendered_field = $view->style_plugin->get_field($i, $this->fields[0]['field_name']);
|
||||
$this->assertEqual(strlen($rendered_field), 3);
|
||||
}
|
||||
}
|
||||
|
||||
public function _testMultipleFieldRender() {
|
||||
$view = $this->getFieldView();
|
||||
|
||||
// Test delta limit.
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3;
|
||||
$this->executeView($view);
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']);
|
||||
$items = array();
|
||||
$pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
|
||||
$pure_items = array_splice($pure_items, 0, 3);
|
||||
foreach ($pure_items as $j => $item) {
|
||||
$items[] = $pure_items[$j]['value'];
|
||||
}
|
||||
$this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.');
|
||||
}
|
||||
|
||||
// Test that an empty field is rendered without error.
|
||||
$rendered_field = $view->style_plugin->get_field(4, $this->fields[4]['field_name']);
|
||||
|
||||
$view->destroy();
|
||||
|
||||
// Test delta limit + offset
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_offset'] = 1;
|
||||
$this->executeView($view);
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']);
|
||||
$items = array();
|
||||
$pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
|
||||
$pure_items = array_splice($pure_items, 1, 3);
|
||||
foreach ($pure_items as $j => $item) {
|
||||
$items[] = $pure_items[$j]['value'];
|
||||
}
|
||||
$this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.');
|
||||
}
|
||||
$view->destroy();
|
||||
|
||||
// Test delta limit + reverse.
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_offset'] = 0;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_reversed'] = TRUE;
|
||||
$this->executeView($view);
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']);
|
||||
$items = array();
|
||||
$pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
|
||||
array_splice($pure_items, 0, -3);
|
||||
$pure_items = array_reverse($pure_items);
|
||||
foreach ($pure_items as $j => $item) {
|
||||
$items[] = $pure_items[$j]['value'];
|
||||
}
|
||||
$this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.');
|
||||
}
|
||||
$view->destroy();
|
||||
|
||||
// Test delta first last.
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 0;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_first_last'] = TRUE;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_reversed'] = FALSE;
|
||||
$this->executeView($view);
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']);
|
||||
$items = array();
|
||||
$pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
|
||||
$items[] = $pure_items[0]['value'];
|
||||
$items[] = $pure_items[4]['value'];
|
||||
$this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.');
|
||||
}
|
||||
$view->destroy();
|
||||
|
||||
// Test delta limit + custom seperator.
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_first_last'] = FALSE;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['delta_limit'] = 3;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['group_rows'] = TRUE;
|
||||
$view->display['default']->display_options['fields'][$this->fields[3]['field_name']]['separator'] = ':';
|
||||
$this->executeView($view);
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$rendered_field = $view->style_plugin->get_field($i, $this->fields[3]['field_name']);
|
||||
$items = array();
|
||||
$pure_items = $this->nodes[$i]->{$this->fields[3]['field_name']}[LANGUAGE_NONE];
|
||||
$pure_items = array_splice($pure_items, 0, 3);
|
||||
foreach ($pure_items as $j => $item) {
|
||||
$items[] = $pure_items[$j]['value'];
|
||||
}
|
||||
$this->assertEqual($rendered_field, implode(':', $items), 'Take sure that the amount of items are limited.');
|
||||
}
|
||||
}
|
||||
|
||||
protected function getFieldView() {
|
||||
$view = new view;
|
||||
$view->name = 'view_fieldapi';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'view_fieldapi';
|
||||
$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['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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'nid';
|
||||
foreach ($this->fields as $key => $field) {
|
||||
$handler->display->display_options['fields'][$field['field_name']]['id'] = $field['field_name'];
|
||||
$handler->display->display_options['fields'][$field['field_name']]['table'] = 'field_data_' . $field['field_name'];
|
||||
$handler->display->display_options['fields'][$field['field_name']]['field'] = $field['field_name'];
|
||||
}
|
||||
return $view;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerAreaTextTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the text area handler.
|
||||
*
|
||||
* @see views_handler_area_text
|
||||
*/
|
||||
class ViewsHandlerAreaTextTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Area: Text',
|
||||
'description' => 'Test the core views_handler_area_text handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
public function testAreaText() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// add a text header
|
||||
$string = $this->randomName();
|
||||
$view->display['default']->handler->override_option('header', array(
|
||||
'area' => array(
|
||||
'id' => 'area',
|
||||
'table' => 'views',
|
||||
'field' => 'area',
|
||||
'content' => $string,
|
||||
),
|
||||
));
|
||||
|
||||
// Execute the view.
|
||||
$this->executeView($view);
|
||||
|
||||
$view->display_handler->handlers['header']['area']->options['format'] = $this->randomString();
|
||||
$this->assertEqual(NULL, $view->display_handler->handlers['header']['area']->render(), 'Non existant format should return nothing');
|
||||
|
||||
$view->display_handler->handlers['header']['area']->options['format'] = filter_default_format();
|
||||
$this->assertEqual(check_markup($string), $view->display_handler->handlers['header']['area']->render(), 'Existant format should return something');
|
||||
|
||||
// Empty results, and it shouldn't be displayed .
|
||||
$this->assertEqual('', $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header');
|
||||
// Empty results, and it should be displayed.
|
||||
$view->display_handler->handlers['header']['area']->options['empty'] = TRUE;
|
||||
$this->assertEqual(check_markup($string), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result, but empty enabled lead to a full header');
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerArgumentNullTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_argument_null handler.
|
||||
*/
|
||||
class ViewsHandlerArgumentNullTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Argument: Null',
|
||||
'description' => 'Test the core views_handler_argument_null handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['id']['argument']['handler'] = 'views_handler_argument_null';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testAreaText() {
|
||||
// Test validation
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Add a null argument.
|
||||
$string = $this->randomString();
|
||||
$view->display['default']->handler->override_option('arguments', array(
|
||||
'null' => array(
|
||||
'id' => 'null',
|
||||
'table' => 'views',
|
||||
'field' => 'null',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
// Make sure that the argument is not validated yet.
|
||||
unset($view->argument['null']->argument_validated);
|
||||
$this->assertTrue($view->argument['null']->validate_arg(26));
|
||||
// test must_not_be option.
|
||||
unset($view->argument['null']->argument_validated);
|
||||
$view->argument['null']->options['must_not_be'] = TRUE;
|
||||
$this->assertFalse($view->argument['null']->validate_arg(26), 'must_not_be returns FALSE, if there is an argument');
|
||||
unset($view->argument['null']->argument_validated);
|
||||
$this->assertTrue($view->argument['null']->validate_arg(NULL), 'must_not_be returns TRUE, if there is no argument');
|
||||
|
||||
// Test execution.
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Add a argument, which has null as handler.
|
||||
$string = $this->randomString();
|
||||
$view->display['default']->handler->override_option('arguments', array(
|
||||
'id' => array(
|
||||
'id' => 'id',
|
||||
'table' => 'views_test',
|
||||
'field' => 'id',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view, array(26));
|
||||
|
||||
// The argument should be ignored, so every result should return.
|
||||
$this->assertEqual(5, count($view->result));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerArgumentNullTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_argument_string handler.
|
||||
*/
|
||||
class ViewsHandlerArgumentStringTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Argument: String',
|
||||
'description' => 'Test the core views_handler_argument_string handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the glossary feature.
|
||||
*/
|
||||
function testGlossary() {
|
||||
// Setup some nodes, one with a, two with b and three with c.
|
||||
$counter = 1;
|
||||
foreach (array('a', 'b', 'c') as $char) {
|
||||
for ($i = 0; $i < $counter; $i++) {
|
||||
$edit = array(
|
||||
'title' => $char . $this->randomName(),
|
||||
);
|
||||
$this->drupalCreateNode($edit);
|
||||
}
|
||||
}
|
||||
|
||||
$view = $this->viewGlossary();
|
||||
$view->init_display();
|
||||
$this->executeView($view);
|
||||
|
||||
$count_field = 'nid';
|
||||
foreach ($view->result as &$row) {
|
||||
if (strpos($row->node_title, 'a') === 0) {
|
||||
$this->assertEqual(1, $row->{$count_field});
|
||||
}
|
||||
if (strpos($row->node_title, 'b') === 0) {
|
||||
$this->assertEqual(2, $row->{$count_field});
|
||||
}
|
||||
if (strpos($row->node_title, 'c') === 0) {
|
||||
$this->assertEqual(3, $row->{$count_field});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a test view for testGlossary.
|
||||
*
|
||||
* @see testGlossary
|
||||
* @return view
|
||||
*/
|
||||
function viewGlossary() {
|
||||
$view = new view();
|
||||
$view->name = 'test_glossary';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'test_glossary';
|
||||
$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['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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* 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']['label'] = '';
|
||||
/* Contextual filter: Content: Title */
|
||||
$handler->display->display_options['arguments']['title']['id'] = 'title';
|
||||
$handler->display->display_options['arguments']['title']['table'] = 'node';
|
||||
$handler->display->display_options['arguments']['title']['field'] = 'title';
|
||||
$handler->display->display_options['arguments']['title']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['title']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['title']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['title']['summary_options']['items_per_page'] = '25';
|
||||
$handler->display->display_options['arguments']['title']['glossary'] = TRUE;
|
||||
$handler->display->display_options['arguments']['title']['limit'] = '1';
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
314
sites/all/modules/views/tests/handlers/views_handler_field.test
Normal file
314
sites/all/modules/views/tests/handlers/views_handler_field.test
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFieldTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the generic field handler
|
||||
*
|
||||
* @see views_handler_field
|
||||
*/
|
||||
class ViewsHandlerFieldTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field',
|
||||
'description' => 'Test the core views_handler_field handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->column_map = array(
|
||||
'views_test_name' => 'name',
|
||||
);
|
||||
}
|
||||
|
||||
function testEmpty() {
|
||||
$this->_testHideIfEmpty();
|
||||
$this->_testEmptyText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the hide if empty functionality.
|
||||
*
|
||||
* This tests alters the result to get easier and less coupled results.
|
||||
*/
|
||||
function _testHideIfEmpty() {
|
||||
$view = $this->getBasicView();
|
||||
$view->init_display();
|
||||
$this->executeView($view);
|
||||
|
||||
$column_map_reversed = array_flip($this->column_map);
|
||||
$view->row_index = 0;
|
||||
$random_name = $this->randomName();
|
||||
$random_value = $this->randomName();
|
||||
|
||||
// Test when results are not rewritten and empty values are not hidden.
|
||||
$view->field['name']->options['hide_alter_empty'] = FALSE;
|
||||
$view->field['name']->options['hide_empty'] = FALSE;
|
||||
$view->field['name']->options['empty_zero'] = FALSE;
|
||||
|
||||
// Test a valid string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = $random_name;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_name, 'By default, a string should not be treated as empty.');
|
||||
|
||||
// Test an empty string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'By default, "" should not be treated as empty.');
|
||||
|
||||
// Test zero as an integer.
|
||||
$view->result[0]->{$column_map_reversed['name']} = 0;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, '0', 'By default, 0 should not be treated as empty.');
|
||||
|
||||
// Test zero as a string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "0", 'By default, "0" should not be treated as empty.');
|
||||
|
||||
// Test when results are not rewritten and non-zero empty values are hidden.
|
||||
$view->field['name']->options['hide_alter_empty'] = TRUE;
|
||||
$view->field['name']->options['hide_empty'] = TRUE;
|
||||
$view->field['name']->options['empty_zero'] = FALSE;
|
||||
|
||||
// Test a valid string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = $random_name;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_name, 'If hide_empty is checked, a string should not be treated as empty.');
|
||||
|
||||
// Test an empty string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If hide_empty is checked, "" should be treated as empty.');
|
||||
|
||||
// Test zero as an integer.
|
||||
$view->result[0]->{$column_map_reversed['name']} = 0;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, '0', 'If hide_empty is checked, but not empty_zero, 0 should not be treated as empty.');
|
||||
|
||||
// Test zero as a string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "0", 'If hide_empty is checked, but not empty_zero, "0" should not be treated as empty.');
|
||||
|
||||
// Test when results are not rewritten and all empty values are hidden.
|
||||
$view->field['name']->options['hide_alter_empty'] = TRUE;
|
||||
$view->field['name']->options['hide_empty'] = TRUE;
|
||||
$view->field['name']->options['empty_zero'] = TRUE;
|
||||
|
||||
// Test zero as an integer.
|
||||
$view->result[0]->{$column_map_reversed['name']} = 0;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If hide_empty and empty_zero are checked, 0 should be treated as empty.');
|
||||
|
||||
// Test zero as a string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If hide_empty and empty_zero are checked, "0" should be treated as empty.');
|
||||
|
||||
// Test when results are rewritten to a valid string and non-zero empty
|
||||
// results are hidden.
|
||||
$view->field['name']->options['hide_alter_empty'] = FALSE;
|
||||
$view->field['name']->options['hide_empty'] = TRUE;
|
||||
$view->field['name']->options['empty_zero'] = FALSE;
|
||||
$view->field['name']->options['alter']['alter_text'] = TRUE;
|
||||
$view->field['name']->options['alter']['text'] = $random_name;
|
||||
|
||||
// Test a valid string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = $random_value;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, it should not be treated as empty.');
|
||||
|
||||
// Test an empty string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, "" should not be treated as empty.');
|
||||
|
||||
// Test zero as an integer.
|
||||
$view->result[0]->{$column_map_reversed['name']} = 0;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, 0 should not be treated as empty.');
|
||||
|
||||
// Test zero as a string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, "0" should not be treated as empty.');
|
||||
|
||||
// Test when results are rewritten to an empty string and non-zero empty results are hidden.
|
||||
$view->field['name']->options['hide_alter_empty'] = TRUE;
|
||||
$view->field['name']->options['hide_empty'] = TRUE;
|
||||
$view->field['name']->options['empty_zero'] = FALSE;
|
||||
$view->field['name']->options['alter']['alter_text'] = TRUE;
|
||||
$view->field['name']->options['alter']['text'] = "";
|
||||
|
||||
// Test a valid string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = $random_name;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_name, 'If the rewritten string is empty, it should not be treated as empty.');
|
||||
|
||||
// Test an empty string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If the rewritten string is empty, "" should be treated as empty.');
|
||||
|
||||
// Test zero as an integer.
|
||||
$view->result[0]->{$column_map_reversed['name']} = 0;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, '0', 'If the rewritten string is empty, 0 should not be treated as empty.');
|
||||
|
||||
// Test zero as a string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "0", 'If the rewritten string is empty, "0" should not be treated as empty.');
|
||||
|
||||
// Test when results are rewritten to zero as a string and non-zero empty
|
||||
// results are hidden.
|
||||
$view->field['name']->options['hide_alter_empty'] = FALSE;
|
||||
$view->field['name']->options['hide_empty'] = TRUE;
|
||||
$view->field['name']->options['empty_zero'] = FALSE;
|
||||
$view->field['name']->options['alter']['alter_text'] = TRUE;
|
||||
$view->field['name']->options['alter']['text'] = "0";
|
||||
|
||||
// Test a valid string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = $random_name;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "0", 'If the rewritten string is zero and empty_zero is not checked, the string rewritten as 0 should not be treated as empty.');
|
||||
|
||||
// Test an empty string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "0", 'If the rewritten string is zero and empty_zero is not checked, "" rewritten as 0 should not be treated as empty.');
|
||||
|
||||
// Test zero as an integer.
|
||||
$view->result[0]->{$column_map_reversed['name']} = 0;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "0", 'If the rewritten string is zero and empty_zero is not checked, 0 should not be treated as empty.');
|
||||
|
||||
// Test zero as a string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "0", 'If the rewritten string is zero and empty_zero is not checked, "0" should not be treated as empty.');
|
||||
|
||||
// Test when results are rewritten to a valid string and non-zero empty
|
||||
// results are hidden.
|
||||
$view->field['name']->options['hide_alter_empty'] = TRUE;
|
||||
$view->field['name']->options['hide_empty'] = TRUE;
|
||||
$view->field['name']->options['empty_zero'] = FALSE;
|
||||
$view->field['name']->options['alter']['alter_text'] = TRUE;
|
||||
$view->field['name']->options['alter']['text'] = $random_value;
|
||||
|
||||
// Test a valid string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = $random_name;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_value, 'If the original and rewritten strings are valid, it should not be treated as empty.');
|
||||
|
||||
// Test an empty string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If either the original or rewritten string is invalid, "" should be treated as empty.');
|
||||
|
||||
// Test zero as an integer.
|
||||
$view->result[0]->{$column_map_reversed['name']} = 0;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_value, 'If the original and rewritten strings are valid, 0 should not be treated as empty.');
|
||||
|
||||
// Test zero as a string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $random_value, 'If the original and rewritten strings are valid, "0" should not be treated as empty.');
|
||||
|
||||
// Test when results are rewritten to zero as a string and all empty
|
||||
// original values and results are hidden.
|
||||
$view->field['name']->options['hide_alter_empty'] = TRUE;
|
||||
$view->field['name']->options['hide_empty'] = TRUE;
|
||||
$view->field['name']->options['empty_zero'] = TRUE;
|
||||
$view->field['name']->options['alter']['alter_text'] = TRUE;
|
||||
$view->field['name']->options['alter']['text'] = "0";
|
||||
|
||||
// Test a valid string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = $random_name;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If the rewritten string is zero, it should be treated as empty.');
|
||||
|
||||
// Test an empty string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If the rewritten string is zero, "" should be treated as empty.');
|
||||
|
||||
// Test zero as an integer.
|
||||
$view->result[0]->{$column_map_reversed['name']} = 0;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If the rewritten string is zero, 0 should not be treated as empty.');
|
||||
|
||||
// Test zero as a string.
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "", 'If the rewritten string is zero, "0" should not be treated as empty.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the usage of the empty text.
|
||||
*/
|
||||
function _testEmptyText() {
|
||||
$view = $this->getBasicView();
|
||||
$view->init_display();
|
||||
$this->executeView($view);
|
||||
|
||||
$column_map_reversed = array_flip($this->column_map);
|
||||
$view->row_index = 0;
|
||||
|
||||
$empty_text = $view->field['name']->options['empty'] = $this->randomName();
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $empty_text, 'If a field is empty, the empty text should be used for the output.');
|
||||
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, "0", 'If a field is 0 and empty_zero is not checked, the empty text should not be used for the output.');
|
||||
|
||||
$view->result[0]->{$column_map_reversed['name']} = "0";
|
||||
$view->field['name']->options['empty_zero'] = TRUE;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $empty_text, 'If a field is 0 and empty_zero is checked, the empty text should be used for the output.');
|
||||
|
||||
$view->result[0]->{$column_map_reversed['name']} = "";
|
||||
$view->field['name']->options['alter']['alter_text'] = TRUE;
|
||||
$alter_text = $view->field['name']->options['alter']['text'] = $this->randomName();
|
||||
$view->field['name']->options['hide_alter_empty'] = FALSE;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $alter_text, 'If a field is empty, some rewrite text exists, but hide_alter_empty is not checked, render the rewrite text.');
|
||||
|
||||
$view->field['name']->options['hide_alter_empty'] = TRUE;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $empty_text, 'If a field is empty, some rewrite text exists, and hide_alter_empty is checked, use the empty text.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests views_handler_field::is_value_empty().
|
||||
*/
|
||||
function testIsValueEmpty() {
|
||||
$view = $this->getBasicView();
|
||||
$view->init_display();
|
||||
$view->init_handlers();
|
||||
$field = $view->field['name'];
|
||||
|
||||
$this->assertFalse($field->is_value_empty("not empty", TRUE), 'A normal string is not empty.');
|
||||
$this->assertTrue($field->is_value_empty("not empty", TRUE, FALSE), 'A normal string which skips empty() can be seen as empty.');
|
||||
|
||||
$this->assertTrue($field->is_value_empty("", TRUE), '"" is considered as empty.');
|
||||
|
||||
$this->assertTrue($field->is_value_empty('0', TRUE), '"0" is considered as empty if empty_zero is TRUE.');
|
||||
$this->assertTrue($field->is_value_empty(0, TRUE), '0 is considered as empty if empty_zero is TRUE.');
|
||||
$this->assertFalse($field->is_value_empty('0', FALSE), '"0" is considered not as empty if empty_zero is FALSE.');
|
||||
$this->assertFalse($field->is_value_empty(0, FALSE), '0 is considered not as empty if empty_zero is FALSE.');
|
||||
|
||||
$this->assertTrue($field->is_value_empty(NULL, TRUE, TRUE), 'Null should be always seen as empty, regardless of no_skip_empty.');
|
||||
$this->assertTrue($field->is_value_empty(NULL, TRUE, FALSE), 'Null should be always seen as empty, regardless of no_skip_empty.');
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFieldBooleanTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_field_boolean handler.
|
||||
*/
|
||||
class ViewsHandlerFieldBooleanTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field: Boolean',
|
||||
'description' => 'Test the core views_handler_field_boolean handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function dataSet() {
|
||||
// Use default dataset but remove the age from john and paul
|
||||
$data = parent::dataSet();
|
||||
$data[0]['age'] = 0;
|
||||
$data[3]['age'] = 0;
|
||||
return $data;
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['age']['field']['handler'] = 'views_handler_field_boolean';
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFieldBoolean() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
// This is john, which has no age, there are no custom formats defined, yet.
|
||||
$this->assertEqual(t('No'), $view->field['age']->advanced_render($view->result[0]));
|
||||
$this->assertEqual(t('Yes'), $view->field['age']->advanced_render($view->result[1]));
|
||||
|
||||
// Reverse the output.
|
||||
$view->field['age']->options['not'] = TRUE;
|
||||
$this->assertEqual(t('Yes'), $view->field['age']->advanced_render($view->result[0]));
|
||||
$this->assertEqual(t('No'), $view->field['age']->advanced_render($view->result[1]));
|
||||
|
||||
unset($view->field['age']->options['not']);
|
||||
|
||||
// Use another output format.
|
||||
$view->field['age']->options['type'] = 'true-false';
|
||||
$this->assertEqual(t('False'), $view->field['age']->advanced_render($view->result[0]));
|
||||
$this->assertEqual(t('True'), $view->field['age']->advanced_render($view->result[1]));
|
||||
|
||||
// test awesome unicode.
|
||||
$view->field['age']->options['type'] = 'unicode-yes-no';
|
||||
$this->assertEqual('✖', $view->field['age']->advanced_render($view->result[0]));
|
||||
$this->assertEqual('✔', $view->field['age']->advanced_render($view->result[1]));
|
||||
|
||||
// Set a custom output format.
|
||||
$view->field['age']->formats['test'] = array(t('Test-True'), t('Test-False'));
|
||||
$view->field['age']->options['type'] = 'test';
|
||||
$this->assertEqual(t('Test-False'), $view->field['age']->advanced_render($view->result[0]));
|
||||
$this->assertEqual(t('Test-True'), $view->field['age']->advanced_render($view->result[1]));
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFilterCounterTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the views_handler_field_counter handler.
|
||||
*/
|
||||
class ViewsHandlerFilterCounterTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field: Counter',
|
||||
'description' => 'Tests the views_handler_field_counter handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
$view = $this->getBasicView();
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'counter' => array(
|
||||
'id' => 'counter',
|
||||
'table' => 'views',
|
||||
'field' => 'counter',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
$view->preview();
|
||||
|
||||
$this->assertEqual(1, $view->style_plugin->rendered_fields[0]['counter']);
|
||||
$this->assertEqual(2, $view->style_plugin->rendered_fields[1]['counter']);
|
||||
$this->assertEqual(3, $view->style_plugin->rendered_fields[2]['counter']);
|
||||
$view->destroy();
|
||||
|
||||
$view = $this->getBasicView();
|
||||
$rand_start = rand(5, 10);
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'counter' => array(
|
||||
'id' => 'counter',
|
||||
'table' => 'views',
|
||||
'field' => 'counter',
|
||||
'relationship' => 'none',
|
||||
'counter_start' => $rand_start
|
||||
),
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
$view->preview();
|
||||
|
||||
$this->assertEqual(0 + $rand_start, $view->style_plugin->rendered_fields[0]['counter']);
|
||||
$this->assertEqual(1 + $rand_start, $view->style_plugin->rendered_fields[1]['counter']);
|
||||
$this->assertEqual(2 + $rand_start, $view->style_plugin->rendered_fields[2]['counter']);
|
||||
}
|
||||
|
||||
// @TODO: Write tests for pager.
|
||||
function testPager() {
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFieldCustomTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_field_custom handler.
|
||||
*/
|
||||
class ViewsHandlerFieldCustomTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field: Custom',
|
||||
'description' => 'Test the core views_handler_field_custom handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['name']['field']['handler'] = 'views_handler_field_custom';
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFieldCustom() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Alter the text of the field to a random string.
|
||||
$random = $this->randomName();
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'alter' => array(
|
||||
'text' => $random,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual($random, $view->style_plugin->get_field(0, 'name'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFieldDateTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_field_date handler.
|
||||
*/
|
||||
class ViewsHandlerFieldDateTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field: Date',
|
||||
'description' => 'Test the core views_handler_field_date handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['created']['field']['handler'] = 'views_handler_field_date';
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFieldDate() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'created' => array(
|
||||
'id' => 'created',
|
||||
'table' => 'views_test',
|
||||
'field' => 'created',
|
||||
'relationship' => 'none',
|
||||
// c is iso 8601 date format @see http://php.net/manual/en/function.date.php
|
||||
'custom_date_format' => 'c',
|
||||
),
|
||||
));
|
||||
$time = gmmktime(0, 0, 0, 1, 1, 2000);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$timezones = array(
|
||||
NULL,
|
||||
'UTC',
|
||||
'America/New_York',
|
||||
);
|
||||
foreach ($timezones as $timezone) {
|
||||
$dates = array(
|
||||
'small' => format_date($time, 'small', '', $timezone),
|
||||
'medium' => format_date($time, 'medium', '', $timezone),
|
||||
'large' => format_date($time, 'large', '', $timezone),
|
||||
'custom' => format_date($time, 'custom', 'c', $timezone),
|
||||
);
|
||||
$this->assertRenderedDatesEqual($view, $dates, $timezone);
|
||||
}
|
||||
|
||||
$intervals = array(
|
||||
'raw time ago' => format_interval(REQUEST_TIME - $time, 2),
|
||||
'time ago' => t('%time ago', array('%time' => format_interval(REQUEST_TIME - $time, 2))),
|
||||
// TODO write tests for them
|
||||
// 'raw time span' => format_interval(REQUEST_TIME - $time, 2),
|
||||
// 'time span' => t('%time hence', array('%time' => format_interval(REQUEST_TIME - $time, 2))),
|
||||
);
|
||||
$this->assertRenderedDatesEqual($view, $intervals);
|
||||
}
|
||||
|
||||
protected function assertRenderedDatesEqual($view, $map, $timezone = NULL) {
|
||||
foreach ($map as $date_format => $expected_result) {
|
||||
$view->field['created']->options['date_format'] = $date_format;
|
||||
$t_args = array(
|
||||
'%value' => $expected_result,
|
||||
'%format' => $date_format,
|
||||
);
|
||||
if (isset($timezone)) {
|
||||
$t_args['%timezone'] = $timezone;
|
||||
$message = t('Value %value in %format format for timezone %timezone matches.', $t_args);
|
||||
$view->field['created']->options['timezone'] = $timezone;
|
||||
}
|
||||
else {
|
||||
$message = t('Value %value in %format format matches.', $t_args);
|
||||
}
|
||||
$actual_result = $view->field['created']->advanced_render($view->result[0]);
|
||||
$this->assertEqual($expected_result, $actual_result, $message);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerTestFileSize.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_field_file_size handler.
|
||||
*
|
||||
* @see CommonXssUnitTest
|
||||
*/
|
||||
class ViewsHandlerTestFileSize extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field: file_size',
|
||||
'description' => 'Test the core views_handler_field_file_size handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function dataSet() {
|
||||
$data = parent::dataSet();
|
||||
$data[0]['age'] = 0;
|
||||
$data[1]['age'] = 10;
|
||||
$data[2]['age'] = 1000;
|
||||
$data[3]['age'] = 10000;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['age']['field']['handler'] = 'views_handler_field_file_size';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFieldFileSize() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
// Test with the formatted option.
|
||||
$this->assertEqual($view->field['age']->advanced_render($view->result[0]), '');
|
||||
$this->assertEqual($view->field['age']->advanced_render($view->result[1]), '10 bytes');
|
||||
$this->assertEqual($view->field['age']->advanced_render($view->result[2]), '1000 bytes');
|
||||
$this->assertEqual($view->field['age']->advanced_render($view->result[3]), '9.77 KB');
|
||||
// Test with the bytes option.
|
||||
$view->field['age']->options['file_size_display'] = 'bytes';
|
||||
$this->assertEqual($view->field['age']->advanced_render($view->result[0]), '');
|
||||
$this->assertEqual($view->field['age']->advanced_render($view->result[1]), 10);
|
||||
$this->assertEqual($view->field['age']->advanced_render($view->result[2]), 1000);
|
||||
$this->assertEqual($view->field['age']->advanced_render($view->result[3]), 10000);
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFieldMath.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_field_math handler.
|
||||
*/
|
||||
class ViewsHandlerFieldMath extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field: Math',
|
||||
'description' => 'Test the core views_handler_field_math handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFieldCustom() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Alter the text of the field to a random string.
|
||||
$rand1 = rand(0, 100);
|
||||
$rand2 = rand(0, 100);
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'expression' => array(
|
||||
'id' => 'expression',
|
||||
'table' => 'views',
|
||||
'field' => 'expression',
|
||||
'relationship' => 'none',
|
||||
'expression' => $rand1 . ' + ' . $rand2,
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual($rand1 + $rand2, $view->style_plugin->get_field(0, 'expression'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFieldUrlTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_field_url handler.
|
||||
*/
|
||||
class ViewsHandlerFieldUrlTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field: Url',
|
||||
'description' => 'Test the core views_handler_field_url handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['name']['field']['handler'] = 'views_handler_field_url';
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFieldUrl() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'display_as_link' => FALSE,
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual('John', $view->field['name']->advanced_render($view->result[0]));
|
||||
|
||||
// Make the url a link.
|
||||
$view->delete();
|
||||
$view = $this->getBasicView();
|
||||
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual(l('John', 'John'), $view->field['name']->advanced_render($view->result[0]));
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerTestXss.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_field_css handler.
|
||||
*
|
||||
* @see CommonXssUnitTest
|
||||
*/
|
||||
class ViewsHandlerTestXss extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Field: Xss',
|
||||
'description' => 'Test the core views_handler_field_css handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function dataHelper() {
|
||||
$map = array(
|
||||
'John' => 'John',
|
||||
"Foo\xC0barbaz" => '',
|
||||
'Fooÿñ' => 'Fooÿñ'
|
||||
);
|
||||
|
||||
return $map;
|
||||
}
|
||||
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['name']['field']['handler'] = 'views_handler_field_xss';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFieldXss() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$counter = 0;
|
||||
foreach ($this->dataHelper() as $input => $expected_result) {
|
||||
$view->result[$counter]->views_test_name = $input;
|
||||
$this->assertEqual($view->field['name']->advanced_render($view->result[$counter]), $expected_result);
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFilterCombineTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the combine filter handler.
|
||||
*/
|
||||
class ViewsHandlerFilterCombineTest extends ViewsSqlTest {
|
||||
var $column_map = array();
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Filter: Combine',
|
||||
'description' => 'Tests the combine filter handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->column_map = array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_job' => 'job',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getBasicView() {
|
||||
$view = parent::getBasicView();
|
||||
$fields = $view->display['default']->handler->options['fields'];
|
||||
$view->display['default']->display_options['fields']['job'] = array(
|
||||
'id' => 'job',
|
||||
'table' => 'views_test',
|
||||
'field' => 'job',
|
||||
'relationship' => 'none',
|
||||
);
|
||||
return $view;
|
||||
}
|
||||
|
||||
public function testFilterCombineContains() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering.
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'id' => 'combine',
|
||||
'table' => 'views',
|
||||
'field' => 'combine',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'contains',
|
||||
'fields' => array(
|
||||
'name',
|
||||
'job',
|
||||
),
|
||||
'value' => 'ing',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
'job' => 'Singer',
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
'job' => 'Singer',
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'job' => 'Drummer',
|
||||
),
|
||||
array(
|
||||
'name' => 'Ginger',
|
||||
'job' => NULL,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional data to test the NULL issue.
|
||||
*/
|
||||
protected function dataSet() {
|
||||
$data_set = parent::dataSet();
|
||||
$data_set[] = array(
|
||||
'name' => 'Ginger',
|
||||
'age' => 25,
|
||||
'job' => NULL,
|
||||
'created' => gmmktime(0, 0, 0, 1, 2, 2000),
|
||||
);
|
||||
return $data_set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow {views_test}.job to be NULL.
|
||||
*/
|
||||
protected function schemaDefinition() {
|
||||
$schema = parent::schemaDefinition();
|
||||
unset($schema['views_test']['fields']['job']['not null']);
|
||||
return $schema;
|
||||
}
|
||||
}
|
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFilterDateTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_filter_date handler.
|
||||
*/
|
||||
class ViewsHandlerFilterDateTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Filter: Date',
|
||||
'description' => 'Test the core views_handler_filter_date handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
// Add some basic test nodes.
|
||||
$this->nodes = array();
|
||||
$this->nodes[] = $this->drupalCreateNode(array('created' => 100000));
|
||||
$this->nodes[] = $this->drupalCreateNode(array('created' => 200000));
|
||||
$this->nodes[] = $this->drupalCreateNode(array('created' => 300000));
|
||||
$this->nodes[] = $this->drupalCreateNode(array('created' => time() + 86400));
|
||||
|
||||
$this->map = array(
|
||||
'nid' => 'nid',
|
||||
);
|
||||
$this->enableViewsUi();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the general offset functionality.
|
||||
*/
|
||||
function testOffset() {
|
||||
$view = $this->views_test_offset();
|
||||
// Test offset for simple operator.
|
||||
$view->set_display('default');
|
||||
$view->init_handlers();
|
||||
$view->filter['created']->operator = '>';
|
||||
$view->filter['created']->value['type'] = 'offset';
|
||||
$view->filter['created']->value['value'] = '+1 hour';
|
||||
$view->execute_display('default');
|
||||
$expected_result = array(
|
||||
array('nid' => $this->nodes[3]->nid),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->map);
|
||||
$view->destroy();
|
||||
|
||||
// Test offset for between operator.
|
||||
$view->set_display('default');
|
||||
$view->init_handlers();
|
||||
$view->filter['created']->operator = 'between';
|
||||
$view->filter['created']->value['type'] = 'offset';
|
||||
$view->filter['created']->value['max'] = '+2 days';
|
||||
$view->filter['created']->value['min'] = '+1 hour';
|
||||
$view->execute_display('default');
|
||||
$expected_result = array(
|
||||
array('nid' => $this->nodes[3]->nid),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->map);
|
||||
$view->destroy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests the filter operator between/not between.
|
||||
*/
|
||||
function testBetween() {
|
||||
// Test between with min and max.
|
||||
$view = $this->views_test_between();
|
||||
$view->set_display('default');
|
||||
$view->init_handlers();
|
||||
$view->filter['created']->operator = 'between';
|
||||
$view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:s');
|
||||
$view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
|
||||
$view->execute_display('default');
|
||||
$expected_result = array(
|
||||
array('nid' => $this->nodes[1]->nid),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->map);
|
||||
$view->destroy();
|
||||
|
||||
// Test between with just max.
|
||||
$view = $this->views_test_between();
|
||||
$view->set_display('default');
|
||||
$view->init_handlers();
|
||||
$view->filter['created']->operator = 'between';
|
||||
$view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
|
||||
$view->execute_display('default');
|
||||
$expected_result = array(
|
||||
array('nid' => $this->nodes[0]->nid),
|
||||
array('nid' => $this->nodes[1]->nid),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->map);
|
||||
$view->destroy();
|
||||
|
||||
// Test not between with min and max.
|
||||
$view = $this->views_test_between();
|
||||
$view->set_display('default');
|
||||
$view->init_handlers();
|
||||
$view->filter['created']->operator = 'not between';
|
||||
$view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:s');
|
||||
$view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
|
||||
$view->execute_display('default');
|
||||
$expected_result = array(
|
||||
array('nid' => $this->nodes[0]->nid),
|
||||
array('nid' => $this->nodes[2]->nid),
|
||||
array('nid' => $this->nodes[3]->nid),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->map);
|
||||
$view->destroy();
|
||||
|
||||
// Test not between with just max.
|
||||
$view = $this->views_test_between();
|
||||
$view->set_display('default');
|
||||
$view->init_handlers();
|
||||
$view->filter['created']->operator = 'not between';
|
||||
$view->filter['created']->value['max'] = format_date(150000, 'custom', 'Y-m-d H:s');
|
||||
$view->execute_display('default');
|
||||
$expected_result = array(
|
||||
array('nid' => $this->nodes[1]->nid),
|
||||
array('nid' => $this->nodes[2]->nid),
|
||||
array('nid' => $this->nodes[3]->nid),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $expected_result, $this->map);
|
||||
$view->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure the validation callbacks works.
|
||||
*/
|
||||
function testUiValidation() {
|
||||
$view = $this->views_test_between();
|
||||
$view->save();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
||||
$this->drupalLogin($admin_user);
|
||||
menu_rebuild();
|
||||
$this->drupalGet('admin/structure/views/view/test_filter_date_between/edit');
|
||||
$this->drupalGet('admin/structure/views/nojs/config-item/test_filter_date_between/default/filter/created');
|
||||
|
||||
$edit = array();
|
||||
// Generate a definitive wrong value, which should be checked by validation.
|
||||
$edit['options[value][value]'] = $this->randomString() . '-------';
|
||||
$this->drupalPost(NULL, $edit, t('Apply'));
|
||||
$this->assertText(t('Invalid date format.'), 'Make sure that validation is runned and the invalidate date format is identified.');
|
||||
}
|
||||
|
||||
function views_test_between() {
|
||||
$view = new view;
|
||||
$view->name = 'test_filter_date_between';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = '';
|
||||
$view->core = 0;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Field: Content: Nid */
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'nid';
|
||||
/* Filter criterion: Content: Post date */
|
||||
$handler->display->display_options['filters']['created']['id'] = 'created';
|
||||
$handler->display->display_options['filters']['created']['table'] = 'node';
|
||||
$handler->display->display_options['filters']['created']['field'] = 'created';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
function views_test_offset() {
|
||||
$view = $this->views_test_between();
|
||||
return $view;
|
||||
}
|
||||
}
|
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFilterEqualityTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_filter_equality handler.
|
||||
*/
|
||||
class ViewsHandlerFilterEqualityTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Filter: Equality',
|
||||
'description' => 'Test the core views_handler_filter_equality handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->column_map = array(
|
||||
'views_test_name' => 'name',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['name']['filter']['handler'] = 'views_handler_filter_equality';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function testEqual() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'operator' => '=',
|
||||
'value' => array('value' => 'Ringo'),
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
public function testEqualGroupedExposed() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: =, Value: Ringo
|
||||
$filters['name']['group_info']['default_group'] = 1;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testNotEqual() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'operator' => '!=',
|
||||
'value' => array('value' => 'Ringo'),
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
public function testEqualGroupedNotExposed() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: !=, Value: Ringo
|
||||
$filters['name']['group_info']['default_group'] = 2;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
protected function getGroupedExposedFilters() {
|
||||
$filters = array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'exposed' => TRUE,
|
||||
'expose' => array(
|
||||
'operator' => 'name_op',
|
||||
'label' => 'name',
|
||||
'identifier' => 'name',
|
||||
),
|
||||
'is_grouped' => TRUE,
|
||||
'group_info' => array(
|
||||
'label' => 'name',
|
||||
'identifier' => 'name',
|
||||
'default_group' => 'All',
|
||||
'group_items' => array(
|
||||
1 => array(
|
||||
'title' => 'Name is equal to Ringo',
|
||||
'operator' => '=',
|
||||
'value' => array('value' => 'Ringo'),
|
||||
),
|
||||
2 => array(
|
||||
'title' => 'Name is not equal to Ringo',
|
||||
'operator' => '!=',
|
||||
'value' => array('value' => 'Ringo'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return $filters;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFilterInOperator.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_filter_in_operator handler.
|
||||
*/
|
||||
class ViewsHandlerFilterInOperator extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Filter: in_operator',
|
||||
'description' => 'Test the core views_handler_filter_in_operator handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['age']['filter']['handler'] = 'views_handler_filter_in_operator';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFilterInOperatorSimple() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Add a in_operator ordering.
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'field' => 'age',
|
||||
'table' => 'views_test',
|
||||
'value' => array(26, 30),
|
||||
'operator' => 'in',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$expected_result = array(
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
'age' => 30,
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEqual(2, count($view->result));
|
||||
$this->assertIdenticalResultset($view, $expected_result, array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
|
||||
$view->delete();
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Add a in_operator ordering.
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'field' => 'age',
|
||||
'table' => 'views_test',
|
||||
'value' => array(26, 30),
|
||||
'operator' => 'not in',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$expected_result = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEqual(3, count($view->result));
|
||||
$this->assertIdenticalResultset($view, $expected_result, array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
}
|
||||
|
||||
public function testFilterInOperatorGroupedExposedSimple() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Age, Operator: in, Value: 26, 30
|
||||
$filters['age']['group_info']['default_group'] = 1;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$expected_result = array(
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
'age' => 30,
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEqual(2, count($view->result));
|
||||
$this->assertIdenticalResultset($view, $expected_result, array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
}
|
||||
|
||||
public function testFilterNotInOperatorGroupedExposedSimple() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Age, Operator: in, Value: 26, 30
|
||||
$filters['age']['group_info']['default_group'] = 2;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$expected_result = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertEqual(3, count($view->result));
|
||||
$this->assertIdenticalResultset($view, $expected_result, array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
}
|
||||
|
||||
protected function getGroupedExposedFilters() {
|
||||
$filters = array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'exposed' => TRUE,
|
||||
'expose' => array(
|
||||
'operator' => 'age_op',
|
||||
'label' => 'age',
|
||||
'identifier' => 'age',
|
||||
),
|
||||
'is_grouped' => TRUE,
|
||||
'group_info' => array(
|
||||
'label' => 'age',
|
||||
'identifier' => 'age',
|
||||
'default_group' => 'All',
|
||||
'group_items' => array(
|
||||
1 => array(
|
||||
'title' => 'Age is one of 26, 30',
|
||||
'operator' => 'in',
|
||||
'value' => array(26, 30),
|
||||
),
|
||||
2 => array(
|
||||
'title' => 'Age is not one of 26, 30',
|
||||
'operator' => 'not in',
|
||||
'value' => array(26, 30),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return $filters;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFilterNumericTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the numeric filter handler.
|
||||
*/
|
||||
class ViewsHandlerFilterNumericTest extends ViewsSqlTest {
|
||||
var $column_map = array();
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Filter: Numeric',
|
||||
'description' => 'Tests the numeric filter handler',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->column_map = array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['age']['filter']['allow empty'] = TRUE;
|
||||
$data['views_test']['id']['filter']['allow empty'] = FALSE;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testFilterNumericSimple() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'operator' => '=',
|
||||
'value' => array('value' => 28),
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
public function testFilterNumericExposedGroupedSimple() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Age, Operator: =, Value: 28
|
||||
$filters['age']['group_info']['default_group'] = 1;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
public function testFilterNumericBetween() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'between',
|
||||
'value' => array(
|
||||
'min' => 26,
|
||||
'max' => 29,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
|
||||
// test not between
|
||||
$view->delete();
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'not between',
|
||||
'value' => array(
|
||||
'min' => 26,
|
||||
'max' => 29,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
'age' => 30,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
public function testFilterNumericExposedGroupedBetween() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Age, Operator: between, Value: 26 and 29
|
||||
$filters['age']['group_info']['default_group'] = 2;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
public function testFilterNumericExposedGroupedNotBetween() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Age, Operator: between, Value: 26 and 29
|
||||
$filters['age']['group_info']['default_group'] = 3;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
'age' => 30,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
public function testFilterNumericEmpty() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'empty',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
|
||||
$view->delete();
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'not empty',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
'age' => 30,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
public function testFilterNumericExposedGroupedEmpty() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Age, Operator: empty, Value:
|
||||
$filters['age']['group_info']['default_group'] = 4;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
public function testFilterNumericExposedGroupedNotEmpty() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Age, Operator: empty, Value:
|
||||
$filters['age']['group_info']['default_group'] = 5;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
'age' => 30,
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
public function testAllowEmpty() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'id' => array(
|
||||
'id' => 'id',
|
||||
'table' => 'views_test',
|
||||
'field' => 'id',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
$view->set_display('default');
|
||||
$view->init_handlers();
|
||||
|
||||
$id_operators = $view->filter['id']->operators();
|
||||
$age_operators = $view->filter['age']->operators();
|
||||
|
||||
$this->assertFalse(isset($id_operators['empty']));
|
||||
$this->assertFalse(isset($id_operators['not empty']));
|
||||
$this->assertTrue(isset($age_operators['empty']));
|
||||
$this->assertTrue(isset($age_operators['not empty']));
|
||||
}
|
||||
|
||||
protected function getGroupedExposedFilters() {
|
||||
$filters = array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
'exposed' => TRUE,
|
||||
'expose' => array(
|
||||
'operator' => 'age_op',
|
||||
'label' => 'age',
|
||||
'identifier' => 'age',
|
||||
),
|
||||
'is_grouped' => TRUE,
|
||||
'group_info' => array(
|
||||
'label' => 'age',
|
||||
'identifier' => 'age',
|
||||
'default_group' => 'All',
|
||||
'group_items' => array(
|
||||
1 => array(
|
||||
'title' => 'Age is 28',
|
||||
'operator' => '=',
|
||||
'value' => array('value' => 28),
|
||||
),
|
||||
2 => array(
|
||||
'title' => 'Age is between 26 and 29',
|
||||
'operator' => 'between',
|
||||
'value' => array(
|
||||
'min' => 26,
|
||||
'max' => 29,
|
||||
),
|
||||
),
|
||||
3 => array(
|
||||
'title' => 'Age is not between 26 and 29',
|
||||
'operator' => 'not between',
|
||||
'value' => array(
|
||||
'min' => 26,
|
||||
'max' => 29,
|
||||
),
|
||||
),
|
||||
4 => array(
|
||||
'title' => 'Age is empty',
|
||||
'operator' => 'empty',
|
||||
),
|
||||
5 => array(
|
||||
'title' => 'Age is not empty',
|
||||
'operator' => 'not empty',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return $filters;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,810 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerFilterStringTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the core views_handler_filter_string handler.
|
||||
*/
|
||||
class ViewsHandlerFilterStringTest extends ViewsSqlTest {
|
||||
var $column_map = array();
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Filter: String',
|
||||
'description' => 'Tests the core views_handler_filter_string handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$this->column_map = array(
|
||||
'views_test_name' => 'name',
|
||||
);
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['name']['filter']['allow empty'] = TRUE;
|
||||
$data['views_test']['job']['filter']['allow empty'] = FALSE;
|
||||
$data['views_test']['description'] = $data['views_test']['name'];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function schemaDefinition() {
|
||||
$schema = parent::schemaDefinition();
|
||||
$schema['views_test']['fields']['description'] = array(
|
||||
'description' => "A person's description",
|
||||
'type' => 'text',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* An extended test dataset.
|
||||
*/
|
||||
protected function dataSet() {
|
||||
$dataset = parent::dataSet();
|
||||
$dataset[0]['description'] = 'John Winston Ono Lennon, MBE (9 October 1940 – 8 December 1980) was an English musician and singer-songwriter who rose to worldwide fame as one of the founding members of The Beatles, one of the most commercially successful and critically acclaimed acts in the history of popular music. Along with fellow Beatle Paul McCartney, he formed one of the most successful songwriting partnerships of the 20th century.';
|
||||
$dataset[1]['description'] = 'George Harrison,[1] MBE (25 February 1943 – 29 November 2001)[2] was an English rock guitarist, singer-songwriter, actor and film producer who achieved international fame as lead guitarist of The Beatles.';
|
||||
$dataset[2]['description'] = 'Richard Starkey, MBE (born 7 July 1940), better known by his stage name Ringo Starr, is an English musician, singer-songwriter, and actor who gained worldwide fame as the drummer for The Beatles.';
|
||||
$dataset[3]['description'] = 'Sir James Paul McCartney, MBE (born 18 June 1942) is an English musician, singer-songwriter and composer. Formerly of The Beatles (1960–1970) and Wings (1971–1981), McCartney is the most commercially successful songwriter in the history of popular music, according to Guinness World Records.[1]';
|
||||
$dataset[4]['description'] = NULL;
|
||||
|
||||
return $dataset;
|
||||
}
|
||||
|
||||
protected function getBasicView() {
|
||||
$view = parent::getBasicView();
|
||||
$view->display['default']->options['fields']['description'] = array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
);
|
||||
return $view;
|
||||
}
|
||||
|
||||
function testFilterStringEqual() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'operator' => '=',
|
||||
'value' => 'Ringo',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedEqual() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: =, Value: Ringo
|
||||
$filters['name']['group_info']['default_group'] = 1;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringNotEqual() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'operator' => '!=',
|
||||
'value' => array('value' => 'Ringo'),
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedNotEqual() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: !=, Value: Ringo
|
||||
$filters['name']['group_info']['default_group'] = '2';
|
||||
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringContains() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'contains',
|
||||
'value' => 'ing',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
function testFilterStringGroupedExposedContains() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: contains, Value: ing
|
||||
$filters['name']['group_info']['default_group'] = '3';
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
function testFilterStringWord() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'word',
|
||||
'value' => 'actor',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
$view->destroy();
|
||||
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'allwords',
|
||||
'value' => 'Richard Starkey',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
function testFilterStringGroupedExposedWord() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: contains, Value: ing
|
||||
$filters['name']['group_info']['default_group'] = '3';
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
$view->destroy();
|
||||
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Description, Operator: contains, Value: actor
|
||||
$filters['description']['group_info']['default_group'] = '1';
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringStarts() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'starts',
|
||||
'value' => 'George',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedStarts() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: starts, Value: George
|
||||
$filters['description']['group_info']['default_group'] = 2;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringNotStarts() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'not_starts',
|
||||
'value' => 'George',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
// There is no Meredith returned because his description is empty
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedNotStarts() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: not_starts, Value: George
|
||||
$filters['description']['group_info']['default_group'] = 3;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
// There is no Meredith returned because his description is empty
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringEnds() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'ends',
|
||||
'value' => 'Beatles.',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedEnds() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Descriptino, Operator: ends, Value: Beatles
|
||||
$filters['description']['group_info']['default_group'] = 4;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'George',
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringNotEnds() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'not_ends',
|
||||
'value' => 'Beatles.',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
// There is no Meredith returned because his description is empty
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedNotEnds() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Description, Operator: not_ends, Value: Beatles
|
||||
$filters['description']['group_info']['default_group'] = 5;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
// There is no Meredith returned because his description is empty
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringNot() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'not',
|
||||
'value' => 'Beatles.',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
// There is no Meredith returned because his description is empty
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
function testFilterStringGroupedExposedNot() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Description, Operator: not (does not contains), Value: Beatles
|
||||
$filters['description']['group_info']['default_group'] = 6;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
// There is no Meredith returned because his description is empty
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
|
||||
}
|
||||
|
||||
function testFilterStringShorter() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'shorterthan',
|
||||
'value' => 5,
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedShorter() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: shorterthan, Value: 5
|
||||
$filters['name']['group_info']['default_group'] = 4;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringLonger() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'longerthan',
|
||||
'value' => 7,
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedLonger() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Name, Operator: longerthan, Value: 4
|
||||
$filters['name']['group_info']['default_group'] = 5;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
|
||||
function testFilterStringEmpty() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the filtering
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'operator' => 'empty',
|
||||
),
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function testFilterStringGroupedExposedEmpty() {
|
||||
$filters = $this->getGroupedExposedFilters();
|
||||
$view = $this->getBasicPageView();
|
||||
|
||||
// Filter: Description, Operator: empty, Value:
|
||||
$filters['description']['group_info']['default_group'] = 7;
|
||||
$view->set_display('page_1');
|
||||
$view->display['page_1']->handler->override_option('filters', $filters);
|
||||
|
||||
$this->executeView($view);
|
||||
$resultset = array(
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
protected function getGroupedExposedFilters() {
|
||||
$filters = array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
'exposed' => TRUE,
|
||||
'expose' => array(
|
||||
'operator' => 'name_op',
|
||||
'label' => 'name',
|
||||
'identifier' => 'name',
|
||||
),
|
||||
'is_grouped' => TRUE,
|
||||
'group_info' => array(
|
||||
'label' => 'name',
|
||||
'identifier' => 'name',
|
||||
'default_group' => 'All',
|
||||
'group_items' => array(
|
||||
1 => array(
|
||||
'title' => 'Is Ringo',
|
||||
'operator' => '=',
|
||||
'value' => 'Ringo',
|
||||
),
|
||||
2 => array(
|
||||
'title' => 'Is not Ringo',
|
||||
'operator' => '!=',
|
||||
'value' => array('value' => 'Ringo'),
|
||||
),
|
||||
3 => array(
|
||||
'title' => 'Contains ing',
|
||||
'operator' => 'contains',
|
||||
'value' => 'ing',
|
||||
),
|
||||
4 => array(
|
||||
'title' => 'Shorter than 5 letters',
|
||||
'operator' => 'shorterthan',
|
||||
'value' => 5,
|
||||
),
|
||||
5 => array(
|
||||
'title' => 'Longer than 7 letters',
|
||||
'operator' => 'longerthan',
|
||||
'value' => 7,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'description' => array(
|
||||
'id' => 'description',
|
||||
'table' => 'views_test',
|
||||
'field' => 'description',
|
||||
'relationship' => 'none',
|
||||
'exposed' => TRUE,
|
||||
'expose' => array(
|
||||
'operator' => 'description_op',
|
||||
'label' => 'description',
|
||||
'identifier' => 'description',
|
||||
),
|
||||
'is_grouped' => TRUE,
|
||||
'group_info' => array(
|
||||
'label' => 'description',
|
||||
'identifier' => 'description',
|
||||
'default_group' => 'All',
|
||||
'group_items' => array(
|
||||
1 => array(
|
||||
'title' => 'Contains the word: Actor',
|
||||
'operator' => 'word',
|
||||
'value' => 'actor',
|
||||
),
|
||||
2 => array(
|
||||
'title' => 'Starts with George',
|
||||
'operator' => 'starts',
|
||||
'value' => 'George',
|
||||
),
|
||||
3 => array(
|
||||
'title' => 'Not Starts with: George',
|
||||
'operator' => 'not_starts',
|
||||
'value' => 'George',
|
||||
),
|
||||
4 => array(
|
||||
'title' => 'Ends with: Beatles',
|
||||
'operator' => 'ends',
|
||||
'value' => 'Beatles.',
|
||||
),
|
||||
5 => array(
|
||||
'title' => 'Not Ends with: Beatles',
|
||||
'operator' => 'not_ends',
|
||||
'value' => 'Beatles.',
|
||||
),
|
||||
6 => array(
|
||||
'title' => 'Does not contain: Beatles',
|
||||
'operator' => 'not',
|
||||
'value' => 'Beatles.',
|
||||
),
|
||||
7 => array(
|
||||
'title' => 'Empty description',
|
||||
'operator' => 'empty',
|
||||
'value' => '',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return $filters;
|
||||
}
|
||||
|
||||
}
|
121
sites/all/modules/views/tests/handlers/views_handler_sort.test
Normal file
121
sites/all/modules/views/tests/handlers/views_handler_sort.test
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerSortTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests for core views_handler_sort handler.
|
||||
*/
|
||||
class ViewsHandlerSortTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Sort: generic',
|
||||
'description' => 'Test the core views_handler_sort handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests numeric ordering of the result set.
|
||||
*/
|
||||
public function testNumericOrdering() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the ordering
|
||||
$view->display['default']->handler->override_option('sorts', array(
|
||||
'age' => array(
|
||||
'order' => 'ASC',
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Execute the view.
|
||||
$this->executeView($view);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age'), array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Reverse the ordering
|
||||
$view->display['default']->handler->override_option('sorts', array(
|
||||
'age' => array(
|
||||
'order' => 'DESC',
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Execute the view.
|
||||
$this->executeView($view);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'age', TRUE), array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests string ordering of the result set.
|
||||
*/
|
||||
public function testStringOrdering() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the ordering
|
||||
$view->display['default']->handler->override_option('sorts', array(
|
||||
'name' => array(
|
||||
'order' => 'ASC',
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Execute the view.
|
||||
$this->executeView($view);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name'), array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Reverse the ordering
|
||||
$view->display['default']->handler->override_option('sorts', array(
|
||||
'name' => array(
|
||||
'order' => 'DESC',
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Execute the view.
|
||||
$this->executeView($view);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultset($view, $this->orderResultSet($this->dataSet(), 'name', TRUE), array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
}
|
||||
}
|
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerSortDateTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests for core views_handler_sort_date handler.
|
||||
*/
|
||||
class ViewsHandlerSortDateTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Sort: date',
|
||||
'description' => 'Test the core views_handler_sort_date handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
protected function expectedResultSet($granularity, $reverse = TRUE) {
|
||||
$expected = array();
|
||||
if (!$reverse) {
|
||||
switch ($granularity) {
|
||||
case 'second':
|
||||
$expected = array(
|
||||
array('name' => 'John'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'George'),
|
||||
);
|
||||
break;
|
||||
case 'minute':
|
||||
$expected = array(
|
||||
array('name' => 'John'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Meredith'),
|
||||
array('name' => 'George'),
|
||||
);
|
||||
break;
|
||||
case 'hour':
|
||||
$expected = array(
|
||||
array('name' => 'John'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
array('name' => 'George'),
|
||||
);
|
||||
break;
|
||||
case 'day':
|
||||
$expected = array(
|
||||
array('name' => 'John'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
array('name' => 'George'),
|
||||
);
|
||||
break;
|
||||
case 'month':
|
||||
$expected = array(
|
||||
array('name' => 'John'),
|
||||
array('name' => 'George'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
);
|
||||
break;
|
||||
case 'year':
|
||||
$expected = array(
|
||||
array('name' => 'John'),
|
||||
array('name' => 'George'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch ($granularity) {
|
||||
case 'second':
|
||||
$expected = array(
|
||||
array('name' => 'George'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Meredith'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'John'),
|
||||
);
|
||||
break;
|
||||
case 'minute':
|
||||
$expected = array(
|
||||
array('name' => 'George'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Meredith'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'John'),
|
||||
);
|
||||
break;
|
||||
case 'hour':
|
||||
$expected = array(
|
||||
array('name' => 'George'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
array('name' => 'John'),
|
||||
);
|
||||
break;
|
||||
case 'day':
|
||||
$expected = array(
|
||||
array('name' => 'George'),
|
||||
array('name' => 'John'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
);
|
||||
break;
|
||||
case 'month':
|
||||
$expected = array(
|
||||
array('name' => 'John'),
|
||||
array('name' => 'George'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
);
|
||||
break;
|
||||
case 'year':
|
||||
$expected = array(
|
||||
array('name' => 'John'),
|
||||
array('name' => 'George'),
|
||||
array('name' => 'Ringo'),
|
||||
array('name' => 'Paul'),
|
||||
array('name' => 'Meredith'),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $expected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests numeric ordering of the result set.
|
||||
*/
|
||||
public function testDateOrdering() {
|
||||
foreach (array('second', 'minute', 'hour', 'day', 'month', 'year') as $granularity) {
|
||||
foreach (array(FALSE, TRUE) as $reverse) {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Change the fields.
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'created' => array(
|
||||
'id' => 'created',
|
||||
'table' => 'views_test',
|
||||
'field' => 'created',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Change the ordering
|
||||
$view->display['default']->handler->override_option('sorts', array(
|
||||
'created' => array(
|
||||
'id' => 'created',
|
||||
'table' => 'views_test',
|
||||
'field' => 'created',
|
||||
'relationship' => 'none',
|
||||
'granularity' => $granularity,
|
||||
'order' => $reverse ? 'DESC' : 'ASC',
|
||||
),
|
||||
'id' => array(
|
||||
'id' => 'id',
|
||||
'table' => 'views_test',
|
||||
'field' => 'id',
|
||||
'relationship' => 'none',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
));
|
||||
|
||||
// Execute the view.
|
||||
$this->executeView($view);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultset($view, $this->expectedResultSet($granularity, $reverse), array(
|
||||
'views_test_name' => 'name',
|
||||
), t('Result is returned correctly when ordering by granularity @granularity, @reverse.', array('@granularity' => $granularity, '@reverse' => $reverse ? t('reverse') : t('forward'))));
|
||||
$view->destroy();
|
||||
unset($view);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerSortRandomTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests for core views_handler_sort_random handler.
|
||||
*/
|
||||
class ViewsHandlerSortRandomTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Sort: random',
|
||||
'description' => 'Test the core views_handler_sort_random handler.',
|
||||
'group' => 'Views Handlers',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add more items to the test set, to make the order tests more robust.
|
||||
*/
|
||||
protected function dataSet() {
|
||||
$data = parent::dataSet();
|
||||
for ($i = 0; $i < 50; $i++) {
|
||||
$data[] = array(
|
||||
'name' => 'name_' . $i,
|
||||
'age' => $i,
|
||||
'job' => 'job_' . $i,
|
||||
'created' => rand(0, time()),
|
||||
);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a basic view with random ordering.
|
||||
*/
|
||||
protected function getBasicRandomView() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Add a random ordering.
|
||||
$view->display['default']->handler->override_option('sorts', array(
|
||||
'random' => array(
|
||||
'id' => 'random',
|
||||
'field' => 'random',
|
||||
'table' => 'views',
|
||||
),
|
||||
));
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests random ordering of the result set.
|
||||
*
|
||||
* @see DatabaseSelectTestCase::testRandomOrder()
|
||||
*/
|
||||
public function testRandomOrdering() {
|
||||
// Execute a basic view first.
|
||||
$view = $this->getBasicView();
|
||||
$this->executeView($view);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(count($this->dataSet()), count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultset($view, $this->dataSet(), array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
|
||||
// Execute a random view, we expect the result set to be different.
|
||||
$view_random = $this->getBasicRandomView();
|
||||
$this->executeView($view_random);
|
||||
$this->assertEqual(count($this->dataSet()), count($view_random->result), t('The number of returned rows match.'));
|
||||
$this->assertNotIdenticalResultset($view_random, $view->result, array(
|
||||
'views_test_name' => 'views_test_name',
|
||||
'views_test_age' => 'views_test_name',
|
||||
));
|
||||
|
||||
// Execute a second random view, we expect the result set to be different again.
|
||||
$view_random_2 = $this->getBasicRandomView();
|
||||
$this->executeView($view_random_2);
|
||||
$this->assertEqual(count($this->dataSet()), count($view_random_2->result), t('The number of returned rows match.'));
|
||||
$this->assertNotIdenticalResultset($view_random, $view->result, array(
|
||||
'views_test_name' => 'views_test_name',
|
||||
'views_test_age' => 'views_test_name',
|
||||
));
|
||||
}
|
||||
}
|
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsNodeRevisionRelationsTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests basic node_revision table integration into views.
|
||||
*/
|
||||
class ViewsNodeRevisionRelationsTestCase extends ViewsSqlTest {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests basic node_revision integration',
|
||||
'description' => 'Tests the integration of node_revision table of node module',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a node with revision and rest result count for both views.
|
||||
*/
|
||||
public function testNodeRevisionRelationship() {
|
||||
$node = $this->drupalCreateNode();
|
||||
// Create revision of the node.
|
||||
$node_revision = clone $node;
|
||||
$node_revision->revision = 1;
|
||||
node_save($node_revision);
|
||||
$column_map = array(
|
||||
'vid' => 'vid',
|
||||
'node_revision_nid' => 'node_revision_nid',
|
||||
'node_node_revision_nid' => 'node_node_revision_nid',
|
||||
);
|
||||
|
||||
// Here should be two rows.
|
||||
$view_nid = $this->test_view_node_revision_nid();
|
||||
$this->executeView($view_nid, array($node->nid));
|
||||
$resultset_nid = array(
|
||||
array(
|
||||
'vid' => '1',
|
||||
'node_revision_nid' => '1',
|
||||
'node_node_revision_nid' => '1',
|
||||
),
|
||||
array(
|
||||
'vid' => '2',
|
||||
'node_revision_nid' => '1',
|
||||
'node_node_revision_nid' => '1',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view_nid, $resultset_nid, $column_map);
|
||||
|
||||
// There should be only one row with active revision 2.
|
||||
$view_vid = $this->test_view_node_revision_vid();
|
||||
$this->executeView($view_vid, array($node->nid));
|
||||
$resultset_vid = array(
|
||||
array(
|
||||
'vid' => '2',
|
||||
'node_revision_nid' => '1',
|
||||
'node_node_revision_nid' => '1',
|
||||
),
|
||||
);
|
||||
$this->assertIdenticalResultset($view_vid, $resultset_vid, $column_map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view with default join on node.nid.
|
||||
*/
|
||||
function test_view_node_revision_nid() {
|
||||
$view = new view();
|
||||
$view->name = 'test_node_revision_nid';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node_revision';
|
||||
$view->human_name = 'Test node revision nid';
|
||||
$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['access']['perm'] = 'view revisions';
|
||||
$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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Relationship: Content revision: Content */
|
||||
$handler->display->display_options['relationships']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['relationships']['nid']['table'] = 'node_revision';
|
||||
$handler->display->display_options['relationships']['nid']['field'] = 'nid';
|
||||
$handler->display->display_options['relationships']['nid']['label'] = 'NID';
|
||||
$handler->display->display_options['relationships']['nid']['required'] = TRUE;
|
||||
/* Field: Content revision: Vid */
|
||||
$handler->display->display_options['fields']['vid']['id'] = 'vid';
|
||||
$handler->display->display_options['fields']['vid']['table'] = 'node_revision';
|
||||
$handler->display->display_options['fields']['vid']['field'] = 'vid';
|
||||
/* Field: Content revision: Nid */
|
||||
$handler->display->display_options['fields']['nid_1']['id'] = 'nid_1';
|
||||
$handler->display->display_options['fields']['nid_1']['table'] = 'node_revision';
|
||||
$handler->display->display_options['fields']['nid_1']['field'] = 'nid';
|
||||
/* Field: Content: Nid */
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['relationship'] = 'nid';
|
||||
/* Contextual filter: Content revision: Nid */
|
||||
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['arguments']['nid']['table'] = 'node_revision';
|
||||
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
|
||||
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view with default join on node.vid.
|
||||
*/
|
||||
function test_view_node_revision_vid() {
|
||||
$view = new view();
|
||||
$view->name = 'test_node_revision_vid';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node_revision';
|
||||
$view->human_name = 'Test node revision vid';
|
||||
$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['access']['perm'] = 'view revisions';
|
||||
$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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Relationship: Content revision: Content */
|
||||
$handler->display->display_options['relationships']['vid']['id'] = 'vid';
|
||||
$handler->display->display_options['relationships']['vid']['table'] = 'node_revision';
|
||||
$handler->display->display_options['relationships']['vid']['field'] = 'vid';
|
||||
$handler->display->display_options['relationships']['vid']['label'] = 'VID';
|
||||
$handler->display->display_options['relationships']['vid']['required'] = TRUE;
|
||||
/* Field: Content revision: Vid */
|
||||
$handler->display->display_options['fields']['vid']['id'] = 'vid';
|
||||
$handler->display->display_options['fields']['vid']['table'] = 'node_revision';
|
||||
$handler->display->display_options['fields']['vid']['field'] = 'vid';
|
||||
/* Field: Content revision: Nid */
|
||||
$handler->display->display_options['fields']['nid_1']['id'] = 'nid_1';
|
||||
$handler->display->display_options['fields']['nid_1']['table'] = 'node_revision';
|
||||
$handler->display->display_options['fields']['nid_1']['field'] = 'nid';
|
||||
/* Field: Content: Nid */
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['relationship'] = 'vid';
|
||||
/* Contextual filter: Content revision: Nid */
|
||||
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['arguments']['nid']['table'] = 'node_revision';
|
||||
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
|
||||
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
194
sites/all/modules/views/tests/plugins/views_plugin_display.test
Normal file
194
sites/all/modules/views/tests/plugins/views_plugin_display.test
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsPluginDisplayTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ViewsPluginDisplayTestCase extends ViewsSqlTest {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Display plugin',
|
||||
'description' => 'Tests the basic display plugin.',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the overriding of filter_groups.
|
||||
*/
|
||||
function testFilterGroupsOverriding() {
|
||||
$view = $this->viewFilterGroupsUpdating();
|
||||
$view->init_display();
|
||||
|
||||
// mark is as overridden, yes FALSE, means overridden.
|
||||
$view->display['page']->handler->set_override('filter_groups', FALSE);
|
||||
$this->assertFalse($view->display['page']->handler->is_defaulted('filter_groups'), "Take sure that 'filter_groups' is marked as overridden.");
|
||||
$this->assertFalse($view->display['page']->handler->is_defaulted('filters'), "Take sure that 'filters'' is marked as overridden.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a test view for testFilterGroupsOverriding.
|
||||
*
|
||||
* @see testFilterGroupsOverriding
|
||||
* @return view
|
||||
*/
|
||||
function viewFilterGroupsOverriding() {
|
||||
$view = new view();
|
||||
$view->name = 'test_filter_group_override';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'test_filter_group_override';
|
||||
$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['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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* 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']['label'] = '';
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
|
||||
/* 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;
|
||||
$handler->display->display_options['filters']['status']['group'] = 1;
|
||||
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
|
||||
|
||||
/* Display: Page */
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->display->display_options['path'] = 'test';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on a bug some filter_groups landed in the overridden display, even the filters weren't overridden.
|
||||
* This caused multiple issues.
|
||||
* Take sure that the value from the default display are used.
|
||||
*
|
||||
* @see http://drupal.org/node/1259608
|
||||
* @see views_plugin_display::init()
|
||||
*/
|
||||
function testFilterGroupsUpdating() {
|
||||
$view = $this->viewFilterGroupsUpdating();
|
||||
$view->init_display();
|
||||
|
||||
$this->assertFalse($view->display['page']->handler->options['defaults']['filter_groups']);
|
||||
$this->assertEqual($view->display['default']->handler->options['filter_groups'], $view->display['page']->handler->options['filter_groups'], 'Take sure the default options are used for the filter_groups');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a test view for testFilterGroupUpdating.
|
||||
*
|
||||
* @see testFilterGroupUpdating
|
||||
*
|
||||
* @return view
|
||||
*/
|
||||
function viewFilterGroupsUpdating() {
|
||||
$view = new view();
|
||||
$view->name = 'test_filter_groups';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'test_filter_groups';
|
||||
$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['title'] = 'test_filter_groups';
|
||||
$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['pager']['options']['items_per_page'] = '10';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
/* 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']['label'] = '';
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
|
||||
/* 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';
|
||||
$handler->display->display_options['filter_groups']['groups'] = array(
|
||||
1 => 'AND',
|
||||
2 => 'AND',
|
||||
);
|
||||
/* 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;
|
||||
$handler->display->display_options['filters']['status']['group'] = 1;
|
||||
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
|
||||
/* 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']['value']['value'] = '1';
|
||||
$handler->display->display_options['filters']['nid']['group'] = 2;
|
||||
/* Filter criterion: Content: Nid */
|
||||
$handler->display->display_options['filters']['nid_1']['id'] = 'nid_1';
|
||||
$handler->display->display_options['filters']['nid_1']['table'] = 'node';
|
||||
$handler->display->display_options['filters']['nid_1']['field'] = 'nid';
|
||||
$handler->display->display_options['filters']['nid_1']['value']['value'] = '2';
|
||||
$handler->display->display_options['filters']['nid_1']['group'] = 2;
|
||||
|
||||
/* Display: Page */
|
||||
$handler = $view->new_display('page', 'Page', 'page');
|
||||
$handler->display->display_options['filter_groups']['operator'] = 'OR';
|
||||
$handler->display->display_options['filter_groups']['groups'] = array(
|
||||
1 => 'OR',
|
||||
2 => 'OR',
|
||||
);
|
||||
$handler->display->display_options['defaults']['filters'] = FALSE;
|
||||
/* 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;
|
||||
$handler->display->display_options['filters']['status']['group'] = 1;
|
||||
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
|
||||
/* 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']['value']['value'] = '1';
|
||||
$handler->display->display_options['filters']['nid']['group'] = 2;
|
||||
/* Filter criterion: Content: Nid */
|
||||
$handler->display->display_options['filters']['nid_1']['id'] = 'nid_1';
|
||||
$handler->display->display_options['filters']['nid_1']['table'] = 'node';
|
||||
$handler->display->display_options['filters']['nid_1']['field'] = 'nid';
|
||||
$handler->display->display_options['filters']['nid_1']['value']['value'] = '2';
|
||||
$handler->display->display_options['filters']['nid_1']['group'] = 2;
|
||||
$handler->display->display_options['path'] = 'test-filter-groups';
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
264
sites/all/modules/views/tests/styles/views_plugin_style.test
Normal file
264
sites/all/modules/views/tests/styles/views_plugin_style.test
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsPluginStyleTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests some general style plugin related functionality.
|
||||
*/
|
||||
class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Styles',
|
||||
'description' => 'Test general style functionality.',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the grouping legacy features of styles.
|
||||
*/
|
||||
function testGroupingLegacy() {
|
||||
$view = $this->getBasicView();
|
||||
// Setup grouping by the job.
|
||||
$view->init_display();
|
||||
$view->init_style();
|
||||
$view->style_plugin->options['grouping'] = 'job';
|
||||
|
||||
// Reduce the amount of items to make the test a bit easier.
|
||||
// Set up the pager.
|
||||
$view->display['default']->handler->override_option('pager', array(
|
||||
'type' => 'some',
|
||||
'options' => array('items_per_page' => 3),
|
||||
));
|
||||
|
||||
// Add the job field .
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'job' => array(
|
||||
'id' => 'job',
|
||||
'table' => 'views_test',
|
||||
'field' => 'job',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Now run the query and groupby the result.
|
||||
$this->executeView($view);
|
||||
|
||||
// This is the old way to call it.
|
||||
$sets = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping']);
|
||||
|
||||
$expected = array();
|
||||
// Use Job: as label, so be sure that the label is used for groupby as well.
|
||||
$expected['Job: Singer'] = array();
|
||||
$expected['Job: Singer'][0] = new StdClass();
|
||||
$expected['Job: Singer'][0]->views_test_name = 'John';
|
||||
$expected['Job: Singer'][0]->views_test_job = 'Singer';
|
||||
$expected['Job: Singer'][0]->views_test_id = '1';
|
||||
$expected['Job: Singer'][1] = new StdClass();
|
||||
$expected['Job: Singer'][1]->views_test_name = 'George';
|
||||
$expected['Job: Singer'][1]->views_test_job = 'Singer';
|
||||
$expected['Job: Singer'][1]->views_test_id = '2';
|
||||
$expected['Job: Drummer'] = array();
|
||||
$expected['Job: Drummer'][2] = new StdClass();
|
||||
$expected['Job: Drummer'][2]->views_test_name = 'Ringo';
|
||||
$expected['Job: Drummer'][2]->views_test_job = 'Drummer';
|
||||
$expected['Job: Drummer'][2]->views_test_id = '3';
|
||||
|
||||
$this->assertEqual($sets, $expected, t('The style plugin should proper group the results with grouping by the rendered output.'));
|
||||
|
||||
$expected = array();
|
||||
$expected['Job: Singer'] = array();
|
||||
$expected['Job: Singer']['group'] = 'Job: Singer';
|
||||
$expected['Job: Singer']['rows'][0] = new StdClass();
|
||||
$expected['Job: Singer']['rows'][0]->views_test_name = 'John';
|
||||
$expected['Job: Singer']['rows'][0]->views_test_job = 'Singer';
|
||||
$expected['Job: Singer']['rows'][0]->views_test_id = '1';
|
||||
$expected['Job: Singer']['rows'][1] = new StdClass();
|
||||
$expected['Job: Singer']['rows'][1]->views_test_name = 'George';
|
||||
$expected['Job: Singer']['rows'][1]->views_test_job = 'Singer';
|
||||
$expected['Job: Singer']['rows'][1]->views_test_id = '2';
|
||||
$expected['Job: Drummer'] = array();
|
||||
$expected['Job: Drummer']['group'] = 'Job: Drummer';
|
||||
$expected['Job: Drummer']['rows'][2] = new StdClass();
|
||||
$expected['Job: Drummer']['rows'][2]->views_test_name = 'Ringo';
|
||||
$expected['Job: Drummer']['rows'][2]->views_test_job = 'Drummer';
|
||||
$expected['Job: Drummer']['rows'][2]->views_test_id = '3';
|
||||
|
||||
// The newer api passes the value of the grouping as well.
|
||||
$sets_new_rendered = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], TRUE);
|
||||
$sets_new_value = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], FALSE);
|
||||
|
||||
$this->assertEqual($sets_new_rendered, $expected, t('The style plugins should proper group the results with grouping by the rendered output.'));
|
||||
|
||||
// Reorder the group structure to group by value.
|
||||
$expected['Singer'] = $expected['Job: Singer'];
|
||||
$expected['Drummer'] = $expected['Job: Drummer'];
|
||||
unset($expected['Job: Singer']);
|
||||
unset($expected['Job: Drummer']);
|
||||
|
||||
$this->assertEqual($sets_new_value, $expected, t('The style plugins should proper group the results with grouping by the value.'));
|
||||
}
|
||||
|
||||
function testGrouping() {
|
||||
$this->_testGrouping(FALSE);
|
||||
$this->_testGrouping(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the grouping features of styles.
|
||||
*/
|
||||
function _testGrouping($stripped = FALSE) {
|
||||
$view = $this->getBasicView();
|
||||
// Setup grouping by the job and the age field.
|
||||
$view->init_display();
|
||||
$view->init_style();
|
||||
$view->style_plugin->options['grouping'] = array(
|
||||
array('field' => 'job'),
|
||||
array('field' => 'age'),
|
||||
);
|
||||
|
||||
// Reduce the amount of items to make the test a bit easier.
|
||||
// Set up the pager.
|
||||
$view->display['default']->handler->override_option('pager', array(
|
||||
'type' => 'some',
|
||||
'options' => array('items_per_page' => 3),
|
||||
));
|
||||
|
||||
// Add the job and age field.
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'job' => array(
|
||||
'id' => 'job',
|
||||
'table' => 'views_test',
|
||||
'field' => 'job',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Now run the query and groupby the result.
|
||||
$this->executeView($view);
|
||||
|
||||
$expected = array();
|
||||
$expected['Job: Singer'] = array();
|
||||
$expected['Job: Singer']['group'] = 'Job: Singer';
|
||||
$expected['Job: Singer']['rows']['Age: 25'] = array();
|
||||
$expected['Job: Singer']['rows']['Age: 25']['group'] = 'Age: 25';
|
||||
$expected['Job: Singer']['rows']['Age: 25']['rows'][0] = new StdClass();
|
||||
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_name = 'John';
|
||||
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_job = 'Singer';
|
||||
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_age = '25';
|
||||
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_id = '1';
|
||||
$expected['Job: Singer']['rows']['Age: 27'] = array();
|
||||
$expected['Job: Singer']['rows']['Age: 27']['group'] = 'Age: 27';
|
||||
$expected['Job: Singer']['rows']['Age: 27']['rows'][1] = new StdClass();
|
||||
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_name = 'George';
|
||||
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_job = 'Singer';
|
||||
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_age = '27';
|
||||
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_id = '2';
|
||||
$expected['Job: Drummer'] = array();
|
||||
$expected['Job: Drummer']['group'] = 'Job: Drummer';
|
||||
$expected['Job: Drummer']['rows']['Age: 28'] = array();
|
||||
$expected['Job: Drummer']['rows']['Age: 28']['group'] = 'Age: 28';
|
||||
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2] = new StdClass();
|
||||
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_name = 'Ringo';
|
||||
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_job = 'Drummer';
|
||||
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_age = '28';
|
||||
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_id = '3';
|
||||
|
||||
|
||||
// Alter the results to support the stripped case.
|
||||
if ($stripped) {
|
||||
|
||||
// Add some html to the result and expected value.
|
||||
$rand = '<a data="' . $this->randomName() . '" />';
|
||||
$view->result[0]->views_test_job .= $rand;
|
||||
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_job = 'Singer' . $rand;
|
||||
$expected['Job: Singer']['group'] = 'Job: Singer';
|
||||
$rand = '<a data="' . $this->randomName() . '" />';
|
||||
$view->result[1]->views_test_job .= $rand;
|
||||
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_job = 'Singer' . $rand;
|
||||
$rand = '<a data="' . $this->randomName() . '" />';
|
||||
$view->result[2]->views_test_job .= $rand;
|
||||
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_job = 'Drummer' . $rand;
|
||||
$expected['Job: Drummer']['group'] = 'Job: Drummer';
|
||||
|
||||
$view->style_plugin->options['grouping'][0] = array('field' => 'job', 'rendered' => TRUE, 'rendered_strip' => TRUE);
|
||||
$view->style_plugin->options['grouping'][1] = array('field' => 'age', 'rendered' => TRUE, 'rendered_strip' => TRUE);
|
||||
}
|
||||
|
||||
|
||||
// The newer api passes the value of the grouping as well.
|
||||
$sets_new_rendered = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], TRUE);
|
||||
|
||||
$this->assertEqual($sets_new_rendered, $expected, t('The style plugins should proper group the results with grouping by the rendered output.'));
|
||||
|
||||
// Don't test stripped case, because the actual value is not stripped.
|
||||
if (!$stripped) {
|
||||
$sets_new_value = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], FALSE);
|
||||
|
||||
// Reorder the group structure to grouping by value.
|
||||
$expected['Singer'] = $expected['Job: Singer'];
|
||||
$expected['Singer']['rows']['25'] = $expected['Job: Singer']['rows']['Age: 25'];
|
||||
$expected['Singer']['rows']['27'] = $expected['Job: Singer']['rows']['Age: 27'];
|
||||
$expected['Drummer'] = $expected['Job: Drummer'];
|
||||
$expected['Drummer']['rows']['28'] = $expected['Job: Drummer']['rows']['Age: 28'];
|
||||
unset($expected['Job: Singer']);
|
||||
unset($expected['Singer']['rows']['Age: 25']);
|
||||
unset($expected['Singer']['rows']['Age: 27']);
|
||||
unset($expected['Job: Drummer']);
|
||||
unset($expected['Drummer']['rows']['Age: 28']);
|
||||
|
||||
$this->assertEqual($sets_new_value, $expected, t('The style plugins should proper group the results with grouping by the value.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests custom css classes.
|
||||
*/
|
||||
function testCustomRowClasses() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Setup some random css class.
|
||||
$view->init_display();
|
||||
$view->init_style();
|
||||
$random_name = $this->randomName();
|
||||
$view->style_plugin->options['row_class'] = $random_name . " test-token-[name]";
|
||||
|
||||
$rendered_output = $view->preview();
|
||||
$this->storeViewPreview($rendered_output);
|
||||
|
||||
$rows = $this->elements->body->div->div->div;
|
||||
$count = 0;
|
||||
foreach ($rows as $row) {
|
||||
$attributes = $row->attributes();
|
||||
$class = (string) $attributes['class'][0];
|
||||
$this->assertTrue(strpos($class, $random_name) !== FALSE, 'Take sure that a custom css class is added to the output.');
|
||||
|
||||
// Check token replacement.
|
||||
$name = $view->field['name']->get_value($view->result[$count]);
|
||||
$this->assertTrue(strpos($class, "test-token-$name") !== FALSE, 'Take sure that a token in custom css class is replaced.');
|
||||
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsPluginStyleTestBase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a base foundation for testing style plugins.
|
||||
*/
|
||||
abstract class ViewsPluginStyleTestBase extends ViewsSqlTest {
|
||||
|
||||
/**
|
||||
* Stores the SimpleXML representation of the output.
|
||||
*
|
||||
* @var SimpleXMLElement
|
||||
*/
|
||||
protected $elements;
|
||||
|
||||
/**
|
||||
* Stores a view output in the elements.
|
||||
*/
|
||||
function storeViewPreview($output) {
|
||||
$htmlDom = new DOMDocument();
|
||||
@$htmlDom->loadHTML($output);
|
||||
if ($htmlDom) {
|
||||
// It's much easier to work with simplexml than DOM, luckily enough
|
||||
// we can just simply import our DOM tree.
|
||||
$this->elements = simplexml_import_dom($htmlDom);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of viewsPluginStyleJumpMenuTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests jump menu style functionality.
|
||||
*/
|
||||
class viewsPluginStyleJumpMenuTest extends ViewsSqlTest {
|
||||
|
||||
/**
|
||||
* Stores all created nodes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $nodes;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Jump menu',
|
||||
'description' => 'Test jump menu style functionality.',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->nodes = array();
|
||||
$this->nodes['page'][] = $this->drupalCreateNode(array('type' => 'page'));
|
||||
$this->nodes['page'][] = $this->drupalCreateNode(array('type' => 'page'));
|
||||
$this->nodes['story'][] = $this->drupalCreateNode(array('type' => 'story'));
|
||||
$this->nodes['story'][] = $this->drupalCreateNode(array('type' => 'story'));
|
||||
|
||||
$this->nodeTitles = array($this->nodes['page'][0]->title, $this->nodes['page'][1]->title, $this->nodes['story'][0]->title, $this->nodes['story'][1]->title);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests jump menues with more then one same path but maybe differnet titles.
|
||||
*/
|
||||
function testDuplicatePaths() {
|
||||
$view = $this->getJumpMenuView();
|
||||
$view->set_display();
|
||||
$view->init_handlers();
|
||||
|
||||
// Setup a [path] which would leed to "duplicate" paths, but still the shouldn't be used for grouping.
|
||||
$view->field['nothing']->options['alter']['text'] = '[path]';
|
||||
$view->preview();
|
||||
$form = $view->style_plugin->render($view->result);
|
||||
|
||||
// As there is no grouping setup it should be 4 elements.
|
||||
$this->assertEqual(count($form['jump']['#options']), 4 + 1);
|
||||
|
||||
// Check that all titles are part of the form as well.
|
||||
$options = array_values($form['jump']['#options']);
|
||||
foreach ($options as $key => $title) {
|
||||
// The first one is the choose label.
|
||||
if ($key == 0) {
|
||||
continue;
|
||||
}
|
||||
$this->assertTrue($this->nodeTitles[$key - 1] == trim($title), t('Title @title should appear on the jump list, as we do not filter', array('@title' => $title)));
|
||||
}
|
||||
}
|
||||
|
||||
function getJumpMenuView() {
|
||||
$view = new view;
|
||||
$view->name = 'test_jump_menu';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'test_jump_menu';
|
||||
$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['access']['type'] = 'perm';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'jump_menu';
|
||||
$handler->display->display_options['style_options']['hide'] = 0;
|
||||
$handler->display->display_options['style_options']['path'] = 'nothing';
|
||||
$handler->display->display_options['style_options']['default_value'] = 0;
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* 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']['label'] = '';
|
||||
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
|
||||
/* Field: Content: Type */
|
||||
$handler->display->display_options['fields']['type']['id'] = 'type';
|
||||
$handler->display->display_options['fields']['type']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['type']['field'] = 'type';
|
||||
$handler->display->display_options['fields']['type']['exclude'] = 1;
|
||||
/* Field: Global: Custom text */
|
||||
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
|
||||
$handler->display->display_options['fields']['nothing']['table'] = 'views';
|
||||
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
|
||||
$handler->display->display_options['fields']['nothing']['alter']['text'] = '[type]';
|
||||
$handler->display->display_options['fields']['nothing']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['element_label_colon'] = 1;
|
||||
$handler->display->display_options['fields']['nothing']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['nothing']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['nothing']['exclude'] = 1;
|
||||
|
||||
/* 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: 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;
|
||||
$handler->display->display_options['filters']['status']['group'] = 0;
|
||||
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsPluginStyleMappingTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the default/mapping row style.
|
||||
*/
|
||||
class ViewsPluginStyleMappingTest extends ViewsPluginStyleTestBase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Style: Mapping',
|
||||
'description' => 'Test mapping style functionality.',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Reset the plugin data.
|
||||
views_fetch_plugin_data(NULL, NULL, TRUE);
|
||||
}
|
||||
|
||||
protected function viewsPlugins() {
|
||||
return array(
|
||||
'style' => array(
|
||||
'test_mapping' => array(
|
||||
'title' => t('Field mapping'),
|
||||
'help' => t('Maps specific fields to specific purposes.'),
|
||||
'handler' => 'views_test_plugin_style_test_mapping',
|
||||
'path' => drupal_get_path('module', 'views_test') . '/test_plugins',
|
||||
'theme' => 'views_view_mapping_test',
|
||||
'theme path' => drupal_get_path('module', 'views_test'),
|
||||
'theme file' => 'views_test.module',
|
||||
'uses row plugin' => FALSE,
|
||||
'uses fields' => TRUE,
|
||||
'uses options' => TRUE,
|
||||
'uses grouping' => FALSE,
|
||||
'type' => 'normal',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides ViewsTestCase::getBasicView().
|
||||
*/
|
||||
protected function getBasicView() {
|
||||
$view = parent::getBasicView();
|
||||
$view->display['default']->handler->override_option('style_plugin', 'test_mapping');
|
||||
$view->display['default']->handler->override_option('style_options', array(
|
||||
'mapping' => array(
|
||||
'name_field' => 'name',
|
||||
'numeric_field' => array(
|
||||
'age',
|
||||
),
|
||||
'title_field' => 'name',
|
||||
'toggle_numeric_field' => TRUE,
|
||||
'toggle_title_field' => TRUE,
|
||||
),
|
||||
));
|
||||
$view->display['default']->handler->override_option('fields', array(
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'job' => array(
|
||||
'id' => 'job',
|
||||
'table' => 'views_test',
|
||||
'field' => 'job',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that the fields were mapped correctly.
|
||||
*/
|
||||
public function testMappedOutput() {
|
||||
$view = $this->getBasicView();
|
||||
$output = $this->mappedOutputHelper($view);
|
||||
$this->assertTrue(strpos($output, 'job') === FALSE, 'The job field is added to the view but not in the mapping.');
|
||||
|
||||
$view = $this->getBasicView();
|
||||
$view->display['default']->display_options['style_options']['mapping']['name_field'] = 'job';
|
||||
$output = $this->mappedOutputHelper($view);
|
||||
$this->assertTrue(strpos($output, 'job') !== FALSE, 'The job field is added to the view and is in the mapping.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the mapping of fields.
|
||||
*
|
||||
* @param view $view
|
||||
* The view to test.
|
||||
*
|
||||
* @return string
|
||||
* The view rendered as HTML.
|
||||
*/
|
||||
protected function mappedOutputHelper($view) {
|
||||
$rendered_output = $view->preview();
|
||||
$this->storeViewPreview($rendered_output);
|
||||
$rows = $this->elements->body->div->div->div;
|
||||
$data_set = $this->dataSet();
|
||||
|
||||
$count = 0;
|
||||
foreach ($rows as $row) {
|
||||
$attributes = $row->attributes();
|
||||
$class = (string) $attributes['class'][0];
|
||||
$this->assertTrue(strpos($class, 'views-row-mapping-test') !== FALSE, 'Make sure that each row has the correct CSS class.');
|
||||
|
||||
foreach ($row->div as $field) {
|
||||
// Split up the field-level class, the first part is the mapping name
|
||||
// and the second is the field ID.
|
||||
$field_attributes = $field->attributes();
|
||||
$name = strtok((string) $field_attributes['class'][0], '-');
|
||||
$field_id = strtok('-');
|
||||
|
||||
// The expected result is the mapping name and the field value,
|
||||
// separated by ':'.
|
||||
$expected_result = $name . ':' . $data_set[$count][$field_id];
|
||||
$actual_result = (string) $field;
|
||||
$this->assertIdentical($expected_result, $actual_result, format_string('The fields were mapped successfully: %name => %field_id', array('%name' => $name, '%field_id' => $field_id)));
|
||||
}
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
return $rendered_output;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsPluginStyleUnformattedTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the default/unformatted row style.
|
||||
*/
|
||||
class ViewsPluginStyleUnformattedTestCase extends ViewsPluginStyleTestBase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Style: unformatted',
|
||||
'description' => 'Test unformatted style functionality.',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take sure that the default css classes works as expected.
|
||||
*/
|
||||
function testDefaultRowClasses() {
|
||||
$view = $this->getBasicView();
|
||||
$rendered_output = $view->preview();
|
||||
$this->storeViewPreview($rendered_output);
|
||||
|
||||
$rows = $this->elements->body->div->div->div;
|
||||
$count = 0;
|
||||
$count_result = count($view->result);
|
||||
foreach ($rows as $row) {
|
||||
$count++;
|
||||
$attributes = $row->attributes();
|
||||
$class = (string) $attributes['class'][0];
|
||||
// Take sure that each row has a row css class.
|
||||
$this->assertTrue(strpos($class, "views-row-$count") !== FALSE, 'Take sure that each row has a row css class.');
|
||||
// Take sure that the odd/even classes are set right.
|
||||
$odd_even = $count % 2 == 0 ? 'even' : 'odd';
|
||||
$this->assertTrue(strpos($class, "views-row-$odd_even") !== FALSE, 'Take sure that the odd/even classes are set right.');
|
||||
|
||||
if ($count == 1) {
|
||||
$this->assertTrue(strpos($class, "views-row-first") !== FALSE, 'Take sure that the first class is set right.');
|
||||
}
|
||||
else if ($count == $count_result) {
|
||||
$this->assertTrue(strpos($class, "views-row-last") !== FALSE, 'Take sure that the last class is set right.');
|
||||
|
||||
}
|
||||
$this->assertTrue(strpos($class, 'views-row') !== FALSE, 'Take sure that the views row class is set right.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlerRelationshipNodeTermDataTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the relationship_node_term_data handler.
|
||||
*/
|
||||
class ViewsHandlerRelationshipNodeTermDataTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests handler relationship_node_term_data',
|
||||
'description' => 'Tests the taxonomy term on node relationship handler',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new term with random properties in vocabulary $vid.
|
||||
*/
|
||||
function createTerm($vocabulary) {
|
||||
$term = new stdClass();
|
||||
$term->name = $this->randomName();
|
||||
$term->description = $this->randomName();
|
||||
// Use the first available text format.
|
||||
$term->format = db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField();
|
||||
$term->vid = $vocabulary->vid;
|
||||
taxonomy_term_save($term);
|
||||
return $term;
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
//$web_user = $this->drupalCreateUser(array('create article content'));
|
||||
//$this->drupalLogin($web_user);
|
||||
|
||||
$vocabulary = taxonomy_vocabulary_machine_name_load('tags');
|
||||
$this->term_1 = $this->createTerm($vocabulary);
|
||||
$this->term_2 = $this->createTerm($vocabulary);
|
||||
|
||||
$node = array();
|
||||
$node['type'] = 'article';
|
||||
$node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->term_1->tid;
|
||||
$node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->term_2->tid;
|
||||
$this->node = $this->drupalCreateNode($node);
|
||||
}
|
||||
|
||||
function testViewsHandlerRelationshipNodeTermData() {
|
||||
$view = $this->view_taxonomy_node_term_data();
|
||||
|
||||
$this->executeView($view, array($this->term_1->tid, $this->term_2->tid));
|
||||
$resultset = array(
|
||||
array(
|
||||
'nid' => $this->node->nid,
|
||||
),
|
||||
);
|
||||
$this->column_map = array('nid' => 'nid');
|
||||
debug($view->result);
|
||||
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
|
||||
}
|
||||
|
||||
function view_taxonomy_node_term_data() {
|
||||
$view = new view();
|
||||
$view->name = 'test_taxonomy_node_term_data';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'test_taxonomy_node_term_data';
|
||||
$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['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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
/* Relationship: Content: Taxonomy terms on node */
|
||||
$handler->display->display_options['relationships']['term_node_tid']['id'] = 'term_node_tid';
|
||||
$handler->display->display_options['relationships']['term_node_tid']['table'] = 'node';
|
||||
$handler->display->display_options['relationships']['term_node_tid']['field'] = 'term_node_tid';
|
||||
$handler->display->display_options['relationships']['term_node_tid']['label'] = 'Term #1';
|
||||
$handler->display->display_options['relationships']['term_node_tid']['vocabularies'] = array(
|
||||
'tags' => 0,
|
||||
);
|
||||
/* Relationship: Content: Taxonomy terms on node */
|
||||
$handler->display->display_options['relationships']['term_node_tid_1']['id'] = 'term_node_tid_1';
|
||||
$handler->display->display_options['relationships']['term_node_tid_1']['table'] = 'node';
|
||||
$handler->display->display_options['relationships']['term_node_tid_1']['field'] = 'term_node_tid';
|
||||
$handler->display->display_options['relationships']['term_node_tid_1']['label'] = 'Term #2';
|
||||
$handler->display->display_options['relationships']['term_node_tid_1']['vocabularies'] = array(
|
||||
'tags' => 0,
|
||||
);
|
||||
/* Contextual filter: Taxonomy term: Term ID */
|
||||
$handler->display->display_options['arguments']['tid']['id'] = 'tid';
|
||||
$handler->display->display_options['arguments']['tid']['table'] = 'taxonomy_term_data';
|
||||
$handler->display->display_options['arguments']['tid']['field'] = 'tid';
|
||||
$handler->display->display_options['arguments']['tid']['relationship'] = 'term_node_tid';
|
||||
$handler->display->display_options['arguments']['tid']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['tid']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['tid']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['tid']['summary_options']['items_per_page'] = '25';
|
||||
/* Contextual filter: Taxonomy term: Term ID */
|
||||
$handler->display->display_options['arguments']['tid_1']['id'] = 'tid_1';
|
||||
$handler->display->display_options['arguments']['tid_1']['table'] = 'taxonomy_term_data';
|
||||
$handler->display->display_options['arguments']['tid_1']['field'] = 'tid';
|
||||
$handler->display->display_options['arguments']['tid_1']['relationship'] = 'term_node_tid_1';
|
||||
$handler->display->display_options['arguments']['tid_1']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['tid_1']['summary']['number_of_records'] = '0';
|
||||
$handler->display->display_options['arguments']['tid_1']['summary']['format'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['tid_1']['summary_options']['items_per_page'] = '25';
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Main view template.
|
||||
*
|
||||
* Variables available:
|
||||
* - $classes_array: An array of classes determined in
|
||||
* template_preprocess_views_view(). Default classes are:
|
||||
* .view
|
||||
* .view-[css_name]
|
||||
* .view-id-[view_name]
|
||||
* .view-display-id-[display_name]
|
||||
* .view-dom-id-[dom_id]
|
||||
* - $classes: A string version of $classes_array for use in the class attribute
|
||||
* - $css_name: A css-safe version of the view name.
|
||||
* - $css_class: The user-specified classes names, if any
|
||||
* - $header: The view header
|
||||
* - $footer: The view footer
|
||||
* - $rows: The results of the view query, if any
|
||||
* - $empty: The empty text to display if the view is empty
|
||||
* - $pager: The pager next/prev links to display, if any
|
||||
* - $exposed: Exposed widget form/info to display
|
||||
* - $feed_icon: Feed icon to display, if any
|
||||
* - $more: A link to view more, if any
|
||||
*
|
||||
* @ingroup views_templates
|
||||
*/
|
||||
?>
|
||||
<div class="<?php print $classes; ?>">
|
||||
<?php if ($header): ?>
|
||||
<div class="view-header">
|
||||
<?php print $header; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($exposed): ?>
|
||||
<div class="view-filters">
|
||||
<?php print $exposed; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($attachment_before): ?>
|
||||
<div class="attachment attachment-before">
|
||||
<?php print $attachment_before; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($rows): ?>
|
||||
<div class="view-content">
|
||||
<?php print $rows; ?>
|
||||
</div>
|
||||
<?php elseif ($empty): ?>
|
||||
<div class="view-empty">
|
||||
<?php print $empty; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($pager): ?>
|
||||
<?php print $pager; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($attachment_after): ?>
|
||||
<div class="attachment attachment-after">
|
||||
<?php print $attachment_after; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($more): ?>
|
||||
<?php print $more; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($footer): ?>
|
||||
<div class="view-footer">
|
||||
<?php print $footer; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($feed_icon): ?>
|
||||
<div class="feed-icon">
|
||||
<?php print $feed_icon; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div> <?php /* class view */ ?>
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_test_plugin_access_test_dynamic.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests a dynamic access plugin.
|
||||
*/
|
||||
class views_test_plugin_access_test_dynamic extends views_plugin_access {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['access'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function access($account) {
|
||||
return !empty($this->options['access']) && isset($this->view->args[0]) && $this->view->args[0] == variable_get('test_dynamic_access_argument1', NULL) && isset($this->view->args[1]) && $this->view->args[1] == variable_get('test_dynamic_access_argument2', NULL);
|
||||
}
|
||||
|
||||
function get_access_callback() {
|
||||
return array('views_test_test_dynamic_access_callback', array(!empty($options['access']), 1, 2));
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_test_plugin_access_test_static.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests a static access plugin.
|
||||
*/
|
||||
class views_test_plugin_access_test_static extends views_plugin_access {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['access'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function access($account) {
|
||||
return !empty($this->options['access']);
|
||||
}
|
||||
|
||||
function get_access_callback() {
|
||||
return array('views_test_test_static_access_callback', array(!empty($options['access'])));
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_test_plugin_style_test_mapping.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides a test mapping style plugin.
|
||||
*/
|
||||
class views_test_plugin_style_test_mapping extends views_plugin_style_mapping {
|
||||
|
||||
/**
|
||||
* Overrides views_plugin_style_mapping::define_mapping().
|
||||
*/
|
||||
protected function define_mapping() {
|
||||
return array(
|
||||
'title_field' => array(
|
||||
'#title' => t('Title field'),
|
||||
'#description' => t('Choose the field with the custom title.'),
|
||||
'#toggle' => TRUE,
|
||||
'#required' => TRUE,
|
||||
),
|
||||
'name_field' => array(
|
||||
'#title' => t('Name field'),
|
||||
'#description' => t('Choose the field with the custom name.'),
|
||||
),
|
||||
'numeric_field' => array(
|
||||
'#title' => t('Numeric field'),
|
||||
'#description' => t('Select one or more numeric fields.'),
|
||||
'#multiple' => TRUE,
|
||||
'#toggle' => TRUE,
|
||||
'#filter' => 'filter_numeric_fields',
|
||||
'#required' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restricts the allowed fields to only numeric fields.
|
||||
*
|
||||
* @param array $fields
|
||||
* An array of field labels, keyed by the field ID.
|
||||
*/
|
||||
protected function filter_numeric_fields(&$fields) {
|
||||
foreach ($this->view->field as $id => $field) {
|
||||
if (!($field instanceof views_handler_field_numeric)) {
|
||||
unset($fields[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of viewsHandlerFieldUserNameTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the field username handler.
|
||||
*
|
||||
* @see views_handler_field_user_name
|
||||
*/
|
||||
class viewsHandlerFieldUserNameTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests user: name field',
|
||||
'description' => 'Tests the handler of the user: name field',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
function testUserName() {
|
||||
$view = $this->view_user_name();
|
||||
$view->init_display();
|
||||
$this->executeView($view);
|
||||
|
||||
$view->row_index = 0;
|
||||
|
||||
$view->field['name']->options['link_to_user'] = TRUE;
|
||||
$username = $view->result[0]->users_name = $this->randomName();
|
||||
$view->result[0]->uid = 1;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
|
||||
$this->assertTrue(strpos($render, 'user/1') !== FALSE, 'If link to user is checked the link to the user should appear as well.');
|
||||
|
||||
$view->field['name']->options['link_to_user'] = FALSE;
|
||||
$username = $view->result[0]->users_name = $this->randomName();
|
||||
$view->result[0]->uid = 1;
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $username, 'If the user is not linked the username should be printed out for a normal user.');
|
||||
|
||||
$view->result[0]->uid = 0;
|
||||
$anon_name = variable_get('anonymous', t('Anonymous'));
|
||||
$view->result[0]->users_name = '';
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $anon_name , 'For user0 it should use the default anonymous name by default.');
|
||||
|
||||
$view->field['name']->options['overwrite_anonymous'] = TRUE;
|
||||
$anon_name = $view->field['name']->options['anonymous_text'] = $this->randomName();
|
||||
$render = $view->field['name']->advanced_render($view->result[0]);
|
||||
$this->assertIdentical($render, $anon_name , 'For user0 it should use the configured anonymous text if overwrite_anonymous is checked.');
|
||||
|
||||
|
||||
}
|
||||
function view_user_name() {
|
||||
$view = new view;
|
||||
$view->name = 'test_views_handler_field_user_name';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'users';
|
||||
$view->human_name = 'test_views_handler_field_user_name';
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Field: User: Name */
|
||||
$handler->display->display_options['fields']['name']['id'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['table'] = 'users';
|
||||
$handler->display->display_options['fields']['name']['field'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['label'] = '';
|
||||
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
|
||||
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
143
sites/all/modules/views/tests/user/views_user.test
Normal file
143
sites/all/modules/views/tests/user/views_user.test
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsUserTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests basic user module integration into views.
|
||||
*/
|
||||
class ViewsUserTestCase extends ViewsSqlTest {
|
||||
var $users = array();
|
||||
var $nodes = array();
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests basic user integration',
|
||||
'description' => 'Tests the integration of user module',
|
||||
'group' => 'Views Modules',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->users[] = $this->drupalCreateUser();
|
||||
$this->users[] = user_load(1);
|
||||
$this->nodes[] = $this->drupalCreateNode(array('uid' => $this->users[0]->uid));
|
||||
$this->nodes[] = $this->drupalCreateNode(array('uid' => 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a view which has no explicit relationship to the author and check the result.
|
||||
*
|
||||
* @todo: Remove the following comment once the relationship is required.
|
||||
* One day a view will require the relationship so it should still work
|
||||
*/
|
||||
public function testRelationship() {
|
||||
$view = $this->test_view_user_relationship();
|
||||
|
||||
$view->execute_display();
|
||||
$expected = array();
|
||||
for ($i = 0; $i <= 1; $i++) {
|
||||
$expected[$i] = array(
|
||||
'node_title' => $this->nodes[$i]->title,
|
||||
'users_uid' => $this->nodes[$i]->uid,
|
||||
'users_name' => $this->users[$i]->name,
|
||||
);
|
||||
}
|
||||
$this->assertIdenticalResultset($view, $expected);
|
||||
}
|
||||
|
||||
function test_view_user_relationship() {
|
||||
$view = new view;
|
||||
$view->name = 'test_user_relationship';
|
||||
$view->description = '';
|
||||
$view->tag = 'default';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'test_user_relationship';
|
||||
$view->core = 7;
|
||||
$view->api_version = '3.0-alpha1';
|
||||
$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['title'] = 'test_user_relationship';
|
||||
$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['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
$handler->display->display_options['row_options']['hide_empty'] = 0;
|
||||
$handler->display->display_options['row_options']['default_field_elements'] = 1;
|
||||
/* 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']['label'] = '';
|
||||
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
|
||||
/* Field: User: Name */
|
||||
$handler->display->display_options['fields']['name']['id'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['table'] = 'users';
|
||||
$handler->display->display_options['fields']['name']['field'] = 'name';
|
||||
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['name']['element_label_colon'] = 1;
|
||||
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['name']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
|
||||
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
|
||||
/* Field: User: Uid */
|
||||
$handler->display->display_options['fields']['uid']['id'] = 'uid';
|
||||
$handler->display->display_options['fields']['uid']['table'] = 'users';
|
||||
$handler->display->display_options['fields']['uid']['field'] = 'uid';
|
||||
$handler->display->display_options['fields']['uid']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['absolute'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['external'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['replace_spaces'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['trim_whitespace'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['nl2br'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['uid']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['uid']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['element_label_colon'] = 1;
|
||||
$handler->display->display_options['fields']['uid']['element_default_classes'] = 1;
|
||||
$handler->display->display_options['fields']['uid']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['hide_alter_empty'] = 0;
|
||||
$handler->display->display_options['fields']['uid']['link_to_user'] = 1;
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsUserArgumentDefault.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests views user argument default plugin.
|
||||
*/
|
||||
class ViewsUserArgumentDefault extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests user argument default plugin',
|
||||
'description' => 'Tests user argument default plugin',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
public function test_plugin_argument_default_current_user() {
|
||||
// Create a user to test.
|
||||
$account = $this->drupalCreateUser();
|
||||
|
||||
// Switch the user, we have to check the global user too, because drupalLogin is only for the simpletest browser.
|
||||
$this->drupalLogin($account);
|
||||
global $user;
|
||||
$admin = $user;
|
||||
drupal_save_session(FALSE);
|
||||
$user = $account;
|
||||
|
||||
$view = $this->view_plugin_argument_default_current_user();
|
||||
|
||||
$view->set_display('default');
|
||||
$view->pre_execute();
|
||||
$view->init_handlers();
|
||||
|
||||
$this->assertEqual($view->argument['null']->get_default_argument(), $account->uid, 'Uid of the current user is used.');
|
||||
// Switch back.
|
||||
$user = $admin;
|
||||
drupal_save_session(TRUE);
|
||||
}
|
||||
|
||||
function view_plugin_argument_default_current_user() {
|
||||
$view = new view;
|
||||
$view->name = 'test_plugin_argument_default_current_user';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = '3.0-alpha1';
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* 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']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
|
||||
/* Argument: Global: Null */
|
||||
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
||||
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'current_user';
|
||||
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsUserArgumentValidate.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests views user argument argument handler.
|
||||
*/
|
||||
class ViewsUserArgumentValidate extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests user argument validator',
|
||||
'description' => 'Tests user argument validator',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('views');
|
||||
$this->account = $this->drupalCreateUser();
|
||||
}
|
||||
|
||||
function testArgumentValidateUserUid() {
|
||||
$account = $this->account;
|
||||
// test 'uid' case
|
||||
$view = $this->view_argument_validate_user('uid');
|
||||
$view->set_display('default');
|
||||
$view->pre_execute();
|
||||
$view->init_handlers();
|
||||
$this->assertTrue($view->argument['null']->validate_arg($account->uid));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
// Fail for a string variable since type is 'uid'
|
||||
$this->assertFalse($view->argument['null']->validate_arg($account->name));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
// Fail for a valid numeric, but for a user that doesn't exist
|
||||
$this->assertFalse($view->argument['null']->validate_arg(32));
|
||||
}
|
||||
|
||||
function testArgumentValidateUserName() {
|
||||
$account = $this->account;
|
||||
// test 'name' case
|
||||
$view = $this->view_argument_validate_user('name');
|
||||
$view->set_display('default');
|
||||
$view->pre_execute();
|
||||
$view->init_handlers();
|
||||
$this->assertTrue($view->argument['null']->validate_arg($account->name));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
// Fail for a uid variable since type is 'name'
|
||||
$this->assertFalse($view->argument['null']->validate_arg($account->uid));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
// Fail for a valid string, but for a user that doesn't exist
|
||||
$this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
|
||||
}
|
||||
|
||||
function testArgumentValidateUserEither() {
|
||||
$account = $this->account;
|
||||
// test 'either' case
|
||||
$view = $this->view_argument_validate_user('either');
|
||||
$view->set_display('default');
|
||||
$view->pre_execute();
|
||||
$view->init_handlers();
|
||||
$this->assertTrue($view->argument['null']->validate_arg($account->name));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
// Fail for a uid variable since type is 'name'
|
||||
$this->assertTrue($view->argument['null']->validate_arg($account->uid));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
// Fail for a valid string, but for a user that doesn't exist
|
||||
$this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
// Fail for a valid uid, but for a user that doesn't exist
|
||||
$this->assertFalse($view->argument['null']->validate_arg(32));
|
||||
}
|
||||
|
||||
function view_argument_validate_user($argtype) {
|
||||
$view = new view;
|
||||
$view->name = 'view_argument_validate_user';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Argument: Global: Null */
|
||||
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
||||
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['null']['validate']['type'] = 'user';
|
||||
$handler->display->display_options['arguments']['null']['validate_options']['type'] = $argtype;
|
||||
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
}
|
285
sites/all/modules/views/tests/views_access.test
Normal file
285
sites/all/modules/views/tests/views_access.test
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsAccessTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Basic test for pluggable access.
|
||||
*/
|
||||
class ViewsAccessTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Access',
|
||||
'description' => 'Tests pluggable access for views.',
|
||||
'group' => 'Views Plugins'
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->admin_user = $this->drupalCreateUser(array('access all views'));
|
||||
$this->web_user = $this->drupalCreateUser();
|
||||
$this->web_role = current($this->web_user->roles);
|
||||
|
||||
$this->normal_role = $this->drupalCreateRole(array());
|
||||
$this->normal_user = $this->drupalCreateUser(array('views_test test permission'));
|
||||
$this->normal_user->roles[$this->normal_role] = $this->normal_role;
|
||||
// Reset the plugin data.
|
||||
views_fetch_plugin_data(NULL, NULL, TRUE);
|
||||
}
|
||||
|
||||
function viewsPlugins() {
|
||||
$plugins = array(
|
||||
'access' => array(
|
||||
'test_static' => array(
|
||||
'title' => t('Static test access plugin'),
|
||||
'help' => t('Provides a static test access plugin.'),
|
||||
'handler' => 'views_test_plugin_access_test_static',
|
||||
'path' => drupal_get_path('module', 'views_test') . '/test_plugins',
|
||||
),
|
||||
'test_dynamic' => array(
|
||||
'title' => t('Dynamic test access plugin'),
|
||||
'help' => t('Provides a dynamic test access plugin.'),
|
||||
'handler' => 'views_test_plugin_access_test_dynamic',
|
||||
'path' => drupal_get_path('module', 'views_test') . '/test_plugins',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests none access plugin.
|
||||
*/
|
||||
function testAccessNone() {
|
||||
$view = $this->view_access_none();
|
||||
|
||||
$view->set_display('default');
|
||||
|
||||
$this->assertTrue($view->display_handler->access($this->admin_user), t('Admin-Account should be able to access the view everytime'));
|
||||
$this->assertTrue($view->display_handler->access($this->web_user));
|
||||
$this->assertTrue($view->display_handler->access($this->normal_user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests perm access plugin.
|
||||
*/
|
||||
function testAccessPerm() {
|
||||
$view = $this->view_access_perm();
|
||||
|
||||
$view->set_display('default');
|
||||
$access_plugin = $view->display_handler->get_plugin('access');
|
||||
|
||||
$this->assertTrue($view->display_handler->access($this->admin_user), t('Admin-Account should be able to access the view everytime'));
|
||||
$this->assertFalse($view->display_handler->access($this->web_user));
|
||||
$this->assertTrue($view->display_handler->access($this->normal_user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests role access plugin.
|
||||
*/
|
||||
function testAccessRole() {
|
||||
$view = $this->view_access_role();
|
||||
|
||||
$view->set_display('default');
|
||||
$access_plugin = $view->display_handler->get_plugin('access');
|
||||
|
||||
$this->assertTrue($view->display_handler->access($this->admin_user), t('Admin-Account should be able to access the view everytime'));
|
||||
$this->assertFalse($view->display_handler->access($this->web_user));
|
||||
$this->assertTrue($view->display_handler->access($this->normal_user));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Test abstract access plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests static access check.
|
||||
*/
|
||||
function testStaticAccessPlugin() {
|
||||
$view = $this->view_access_static();
|
||||
|
||||
$view->set_display('default');
|
||||
$access_plugin = $view->display_handler->get_plugin('access');
|
||||
|
||||
$this->assertFalse($access_plugin->access($this->normal_user));
|
||||
|
||||
$access_plugin->options['access'] = TRUE;
|
||||
$this->assertTrue($access_plugin->access($this->normal_user));
|
||||
|
||||
// FALSE comes from hook_menu caching.
|
||||
$expected_hook_menu = array(
|
||||
'views_test_test_static_access_callback', array(FALSE)
|
||||
);
|
||||
$hook_menu = $view->execute_hook_menu('page_1');
|
||||
$this->assertEqual($expected_hook_menu, $hook_menu['test_access_static']['access arguments'][0]);
|
||||
|
||||
$expected_hook_menu = array(
|
||||
'views_test_test_static_access_callback', array(TRUE)
|
||||
);
|
||||
$this->assertTrue(views_access($expected_hook_menu));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests dynamic access plugin.
|
||||
*/
|
||||
function testDynamicAccessPlugin() {
|
||||
$view = $this->view_access_dynamic();
|
||||
$argument1 = $this->randomName();
|
||||
$argument2 = $this->randomName();
|
||||
variable_set('test_dynamic_access_argument1', $argument1);
|
||||
variable_set('test_dynamic_access_argument2', $argument2);
|
||||
|
||||
$view->set_display('default');
|
||||
$access_plugin = $view->display_handler->get_plugin('access');
|
||||
|
||||
$this->assertFalse($access_plugin->access($this->normal_user));
|
||||
|
||||
$access_plugin->options['access'] = TRUE;
|
||||
$this->assertFalse($access_plugin->access($this->normal_user));
|
||||
|
||||
$view->set_arguments(array($argument1, $argument2));
|
||||
$this->assertTrue($access_plugin->access($this->normal_user));
|
||||
|
||||
// FALSE comes from hook_menu caching.
|
||||
$expected_hook_menu = array(
|
||||
'views_test_test_dynamic_access_callback', array(FALSE, 1, 2)
|
||||
);
|
||||
$hook_menu = $view->execute_hook_menu('page_1');
|
||||
$this->assertEqual($expected_hook_menu, $hook_menu['test_access_dynamic']['access arguments'][0]);
|
||||
|
||||
$expected_hook_menu = array(
|
||||
'views_test_test_dynamic_access_callback', array(TRUE, 1, 2)
|
||||
);
|
||||
$this->assertTrue(views_access($expected_hook_menu, $argument1, $argument2));
|
||||
}
|
||||
|
||||
function view_access_none() {
|
||||
$view = new view;
|
||||
$view->name = 'test_access_none';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
function view_access_perm() {
|
||||
$view = new view;
|
||||
$view->name = 'test_access_perm';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'perm';
|
||||
$handler->display->display_options['access']['perm'] = 'views_test test permission';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
function view_access_role() {
|
||||
$view = new view;
|
||||
$view->name = 'test_access_role';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'role';
|
||||
$handler->display->display_options['access']['role'] = array(
|
||||
$this->normal_role => $this->normal_role,
|
||||
);
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
function view_access_dynamic() {
|
||||
$view = new view;
|
||||
$view->name = 'test_access_dynamic';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'test_dynamic';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->display->display_options['path'] = 'test_access_dynamic';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
function view_access_static() {
|
||||
$view = new view;
|
||||
$view->name = 'test_access_static';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'test_static';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->display->display_options['path'] = 'test_access_static';
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
51
sites/all/modules/views/tests/views_analyze.test
Normal file
51
sites/all/modules/views/tests/views_analyze.test
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsAnalyzeTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the views analyze system.
|
||||
*/
|
||||
class ViewsAnalyzeTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views Analyze',
|
||||
'description' => 'Test the views analyze system.',
|
||||
'group' => 'Views',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('views_ui');
|
||||
module_enable(array('views_ui'));
|
||||
// @TODO Figure out why it's required to clear the cache here.
|
||||
views_module_include('views_default', TRUE);
|
||||
views_get_all_views(TRUE);
|
||||
menu_rebuild();
|
||||
|
||||
// Add an admin user will full rights;
|
||||
$this->admin = $this->drupalCreateUser(array('administer views'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that analyze works in general.
|
||||
*/
|
||||
function testAnalyzeBasic() {
|
||||
$this->drupalLogin($this->admin);
|
||||
// Enable the frontpage view and click the analyse button.
|
||||
$view = views_get_view('frontpage');
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/frontpage/edit');
|
||||
$this->assertLink(t('analyze view'));
|
||||
|
||||
// This redirects the user to the form.
|
||||
$this->clickLink(t('analyze view'));
|
||||
$this->assertText(t('View analysis'));
|
||||
|
||||
// This redirects the user back to the main views edit page.
|
||||
$this->drupalPost(NULL, array(), t('Ok'));
|
||||
}
|
||||
}
|
137
sites/all/modules/views/tests/views_argument_default.test
Normal file
137
sites/all/modules/views/tests/views_argument_default.test
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsArgumentDefaultTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Basic test for pluggable argument default.
|
||||
*/
|
||||
class ViewsArgumentDefaultTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Argument_default',
|
||||
'description' => 'Tests pluggable argument_default for views.',
|
||||
'group' => 'Views Plugins'
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('views');
|
||||
|
||||
$this->random = $this->randomString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the use of a default argument plugin that provides no options.
|
||||
*/
|
||||
function testArgumentDefaultNoOptions() {
|
||||
module_enable(array('views_ui', 'views_test'));
|
||||
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
// The current_user plugin has no options form, and should pass validation.
|
||||
$argument_type = 'current_user';
|
||||
$edit = array(
|
||||
'options[default_argument_type]' => $argument_type,
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/config-item/test_argument_default_current_user/default/argument/uid', $edit, t('Apply'));
|
||||
|
||||
// Note, the undefined index error has two spaces after it.
|
||||
$error = array(
|
||||
'%type' => 'Notice',
|
||||
'!message' => 'Undefined index: ' . $argument_type,
|
||||
'%function' => 'views_handler_argument->options_validate()',
|
||||
);
|
||||
$message = t('%type: !message in %function', $error);
|
||||
$this->assertNoRaw($message, t('Did not find error message: !message.', array('!message' => $message)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests fixed default argument.
|
||||
*/
|
||||
function testArgumentDefaultFixed() {
|
||||
$view = $this->view_argument_default_fixed();
|
||||
|
||||
$view->set_display('default');
|
||||
$view->pre_execute();
|
||||
$view->init_handlers();
|
||||
|
||||
$this->assertEqual($view->argument['null']->get_default_argument(), $this->random, 'Fixed argument should be used by default.');
|
||||
|
||||
$view->destroy();
|
||||
|
||||
// Make sure that a normal argument provided is used
|
||||
$view = $this->view_argument_default_fixed();
|
||||
|
||||
$view->set_display('default');
|
||||
$random_string = $this->randomString();
|
||||
$view->execute_display('default', array($random_string));
|
||||
|
||||
$this->assertEqual($view->args[0], $random_string, 'Provided argument should be used.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Test php default argument.
|
||||
*/
|
||||
function testArgumentDefaultPhp() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Test node default argument.
|
||||
*/
|
||||
function testArgumentDefaultNode() {
|
||||
|
||||
}
|
||||
|
||||
function view_argument_default_fixed() {
|
||||
$view = new view;
|
||||
$view->name = 'test_argument_default_fixed';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* 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']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
|
||||
/* Argument: Global: Null */
|
||||
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
||||
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['default_action'] = 'default';
|
||||
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['null']['default_argument_options']['argument'] = $this->random;
|
||||
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
106
sites/all/modules/views/tests/views_argument_validator.test
Normal file
106
sites/all/modules/views/tests/views_argument_validator.test
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsArgumentValidatorTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests Views argument validators.
|
||||
*/
|
||||
class ViewsArgumentValidatorTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Argument validator',
|
||||
'group' => 'Views Plugins',
|
||||
'description' => 'Test argument validator tests.',
|
||||
);
|
||||
}
|
||||
|
||||
function testArgumentValidatePhp() {
|
||||
$string = $this->randomName();
|
||||
$view = $this->view_test_argument_validate_php($string);
|
||||
$view->set_display('default');
|
||||
$view->pre_execute();
|
||||
$view->init_handlers();
|
||||
$this->assertTrue($view->argument['null']->validate_arg($string));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
$this->assertFalse($view->argument['null']->validate_arg($this->randomName()));
|
||||
}
|
||||
|
||||
function testArgumentValidateNumeric() {
|
||||
$view = $this->view_argument_validate_numeric();
|
||||
$view->set_display('default');
|
||||
$view->pre_execute();
|
||||
$view->init_handlers();
|
||||
$this->assertFalse($view->argument['null']->validate_arg($this->randomString()));
|
||||
// Reset safed argument validation.
|
||||
$view->argument['null']->argument_validated = NULL;
|
||||
$this->assertTrue($view->argument['null']->validate_arg(12));
|
||||
}
|
||||
|
||||
function view_test_argument_validate_php($string) {
|
||||
$code = 'return $argument == \''. $string .'\';';
|
||||
$view = new view;
|
||||
$view->name = 'view_argument_validate_numeric';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Argument: Global: Null */
|
||||
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
||||
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['null']['validate_type'] = 'php';
|
||||
$handler->display->display_options['arguments']['null']['validate_options']['code'] = $code;
|
||||
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
function view_argument_validate_numeric() {
|
||||
$view = new view;
|
||||
$view->name = 'view_argument_validate_numeric';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Argument: Global: Null */
|
||||
$handler->display->display_options['arguments']['null']['id'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['table'] = 'views';
|
||||
$handler->display->display_options['arguments']['null']['field'] = 'null';
|
||||
$handler->display->display_options['arguments']['null']['style_plugin'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['null']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['null']['validate_type'] = 'numeric';
|
||||
$handler->display->display_options['arguments']['null']['must_not_be'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
178
sites/all/modules/views/tests/views_basic.test
Normal file
178
sites/all/modules/views/tests/views_basic.test
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsBasicTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Basic test class for Views query builder tests.
|
||||
*/
|
||||
class ViewsBasicTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Basic query test',
|
||||
'description' => 'A basic query test for Views.',
|
||||
'group' => 'Views'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a trivial result set.
|
||||
*/
|
||||
public function testSimpleResultSet() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Execute the view.
|
||||
$this->executeView($view);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultset($view, $this->dataSet(), array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests filtering of the result set.
|
||||
*/
|
||||
public function testSimpleFiltering() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Add a filter.
|
||||
$view->display['default']->handler->override_option('filters', array(
|
||||
'age' => array(
|
||||
'operator' => '<',
|
||||
'value' => array(
|
||||
'value' => '28',
|
||||
'min' => '',
|
||||
'max' => '',
|
||||
),
|
||||
'group' => '0',
|
||||
'exposed' => FALSE,
|
||||
'expose' => array(
|
||||
'operator' => FALSE,
|
||||
'label' => '',
|
||||
),
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Execute the view.
|
||||
$this->executeView($view);
|
||||
|
||||
// Build the expected result.
|
||||
$dataset = array(
|
||||
array(
|
||||
'id' => 1,
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
),
|
||||
array(
|
||||
'id' => 2,
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
),
|
||||
array(
|
||||
'id' => 4,
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
),
|
||||
);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(3, count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultSet($view, $dataset, array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests simple argument.
|
||||
*/
|
||||
public function testSimpleArgument() {
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// Add a argument.
|
||||
$view->display['default']->handler->override_option('arguments', array(
|
||||
'age' => array(
|
||||
'default_action' => 'ignore',
|
||||
'style_plugin' => 'default_summary',
|
||||
'style_options' => array(),
|
||||
'wildcard' => 'all',
|
||||
'wildcard_substitution' => 'All',
|
||||
'title' => '',
|
||||
'breadcrumb' => '',
|
||||
'default_argument_type' => 'fixed',
|
||||
'default_argument' => '',
|
||||
'validate_type' => 'none',
|
||||
'validate_fail' => 'not found',
|
||||
'break_phrase' => 0,
|
||||
'not' => 0,
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'validate_user_argument_type' => 'uid',
|
||||
'validate_user_roles' => array(
|
||||
'2' => 0,
|
||||
),
|
||||
'relationship' => 'none',
|
||||
'default_options_div_prefix' => '',
|
||||
'default_argument_user' => 0,
|
||||
'default_argument_fixed' => '',
|
||||
'default_argument_php' => '',
|
||||
'validate_argument_node_type' => array(
|
||||
'page' => 0,
|
||||
'story' => 0,
|
||||
),
|
||||
'validate_argument_node_access' => 0,
|
||||
'validate_argument_nid_type' => 'nid',
|
||||
'validate_argument_vocabulary' => array(),
|
||||
'validate_argument_type' => 'tid',
|
||||
'validate_argument_transform' => 0,
|
||||
'validate_user_restrict_roles' => 0,
|
||||
'validate_argument_php' => '',
|
||||
)
|
||||
));
|
||||
|
||||
$saved_view = clone $view;
|
||||
|
||||
// Execute with a view
|
||||
$view->set_arguments(array(27));
|
||||
$this->executeView($view);
|
||||
|
||||
// Build the expected result.
|
||||
$dataset = array(
|
||||
array(
|
||||
'id' => 2,
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
),
|
||||
);
|
||||
|
||||
// Verify the result.
|
||||
$this->assertEqual(1, count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultSet($view, $dataset, array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
|
||||
// Test "show all" if no argument is present.
|
||||
$view = $saved_view;
|
||||
$this->executeView($view);
|
||||
|
||||
// Build the expected result.
|
||||
$dataset = $this->dataSet();
|
||||
|
||||
$this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
|
||||
$this->assertIdenticalResultSet($view, $dataset, array(
|
||||
'views_test_name' => 'name',
|
||||
'views_test_age' => 'age',
|
||||
));
|
||||
}
|
||||
}
|
244
sites/all/modules/views/tests/views_cache.test
Normal file
244
sites/all/modules/views/tests/views_cache.test
Normal file
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsCacheTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Basic test for pluggable caching.
|
||||
*
|
||||
* @see views_plugin_cache
|
||||
*/
|
||||
class ViewsCacheTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Cache',
|
||||
'description' => 'Tests pluggable caching for views.',
|
||||
'group' => 'Views Plugins'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and return a basic view of the views_test table.
|
||||
*
|
||||
* @return view
|
||||
*/
|
||||
protected function getBasicView() {
|
||||
views_include('view');
|
||||
|
||||
// Create the basic view.
|
||||
$view = new view();
|
||||
$view->name = 'test_view';
|
||||
$view->add_display('default');
|
||||
$view->base_table = 'views_test';
|
||||
|
||||
// Set up the fields we need.
|
||||
$display = $view->new_display('default', 'Master', 'default');
|
||||
$display->override_option('fields', array(
|
||||
'id' => array(
|
||||
'id' => 'id',
|
||||
'table' => 'views_test',
|
||||
'field' => 'id',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Set up the sort order.
|
||||
$display->override_option('sorts', array(
|
||||
'id' => array(
|
||||
'order' => 'ASC',
|
||||
'id' => 'id',
|
||||
'table' => 'views_test',
|
||||
'field' => 'id',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests time based caching.
|
||||
*
|
||||
* @see views_plugin_cache_time
|
||||
*/
|
||||
function testTimeCaching() {
|
||||
// Create a basic result which just 2 results.
|
||||
$view = $this->getBasicView();
|
||||
$view->set_display();
|
||||
$view->display_handler->override_option('cache', array(
|
||||
'type' => 'time',
|
||||
'results_lifespan' => '3600',
|
||||
'output_lifespan' => '3600',
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
// Verify the result.
|
||||
$this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
|
||||
|
||||
// Add another man to the beatles.
|
||||
$record = array(
|
||||
'name' => 'Rod Davis',
|
||||
'age' => 29,
|
||||
'job' => 'Banjo',
|
||||
);
|
||||
drupal_write_record('views_test', $record);
|
||||
|
||||
// The Result should be the same as before, because of the caching.
|
||||
$view = $this->getBasicView();
|
||||
$view->set_display();
|
||||
$view->display_handler->override_option('cache', array(
|
||||
'type' => 'time',
|
||||
'results_lifespan' => '3600',
|
||||
'output_lifespan' => '3600',
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
// Verify the result.
|
||||
$this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests no caching.
|
||||
*
|
||||
* @see views_plugin_cache_time
|
||||
*/
|
||||
function testNoneCaching() {
|
||||
// Create a basic result which just 2 results.
|
||||
$view = $this->getBasicView();
|
||||
$view->set_display();
|
||||
$view->display_handler->override_option('cache', array(
|
||||
'type' => 'none',
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
// Verify the result.
|
||||
$this->assertEqual(5, count($view->result), t('The number of returned rows match.'));
|
||||
|
||||
// Add another man to the beatles.
|
||||
$record = array(
|
||||
'name' => 'Rod Davis',
|
||||
'age' => 29,
|
||||
'job' => 'Banjo',
|
||||
);
|
||||
|
||||
drupal_write_record('views_test', $record);
|
||||
|
||||
// The Result changes, because the view is not cached.
|
||||
$view = $this->getBasicView();
|
||||
$view->set_display();
|
||||
$view->display_handler->override_option('cache', array(
|
||||
'type' => 'none',
|
||||
));
|
||||
|
||||
$this->executeView($view);
|
||||
// Verify the result.
|
||||
$this->assertEqual(6, count($view->result), t('The number of returned rows match.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests css/js storage and restoring mechanism.
|
||||
*/
|
||||
function testHeaderStorage() {
|
||||
// Create a view with output caching enabled.
|
||||
// Some hook_views_pre_render in views_test.module adds the test css/js file.
|
||||
// so they should be added to the css/js storage.
|
||||
$view = $this->getBasicView();
|
||||
$view->init_display();
|
||||
$view->name = 'test_cache_header_storage';
|
||||
$view->display_handler->override_option('cache', array(
|
||||
'type' => 'time',
|
||||
'output_lifespan' => '3600',
|
||||
));
|
||||
|
||||
$view->preview();
|
||||
$view->destroy();
|
||||
unset($view->pre_render_called);
|
||||
drupal_static_reset('drupal_add_css');
|
||||
drupal_static_reset('drupal_add_js');
|
||||
|
||||
$view->init_display();
|
||||
$view->preview();
|
||||
$css = drupal_add_css();
|
||||
$css_path = drupal_get_path('module', 'views_test') . '/views_cache.test.css';
|
||||
$js_path = drupal_get_path('module', 'views_test') . '/views_cache.test.js';
|
||||
$js = drupal_add_js();
|
||||
|
||||
$this->assertTrue(isset($css[$css_path]), 'Make sure the css is added for cached views.');
|
||||
$this->assertTrue(isset($js[$js_path]), 'Make sure the js is added for cached views.');
|
||||
$this->assertFalse(!empty($view->pre_render_called), 'Make sure hook_views_pre_render is not called for the cached view.');
|
||||
$view->destroy();
|
||||
|
||||
// Now add some css/jss before running the view.
|
||||
// Make sure that this css is not added when running the cached view.
|
||||
$view->name = 'test_cache_header_storage_2';
|
||||
|
||||
$system_css_path = drupal_get_path('module', 'system') . '/system.maintenance.css';
|
||||
drupal_add_css($system_css_path);
|
||||
$system_js_path = drupal_get_path('module', 'system') . '/system.cron.js';
|
||||
drupal_add_js($system_js_path);
|
||||
|
||||
$view->init_display();
|
||||
$view->preview();
|
||||
$view->destroy();
|
||||
drupal_static_reset('drupal_add_css');
|
||||
drupal_static_reset('drupal_add_js');
|
||||
|
||||
$view->init_display();
|
||||
$view->preview();
|
||||
|
||||
$css = drupal_add_css();
|
||||
$js = drupal_add_js();
|
||||
|
||||
$this->assertFalse(isset($css[$system_css_path]), 'Make sure that unrelated css is not added.');
|
||||
$this->assertFalse(isset($js[$system_js_path]), 'Make sure that unrelated js is not added.');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that HTTP headers are cached for views.
|
||||
*/
|
||||
function testHttpHeadersCaching() {
|
||||
// Create a few nodes to appear in RSS feed.
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
|
||||
// Make the first request and check returned content type.
|
||||
$this->drupalGet('test_feed_http_headers_caching');
|
||||
$first_content = $this->drupalGetContent();
|
||||
$first_content_type = $this->drupalGetHeader('content-type');
|
||||
$expected_type = 'application/rss+xml';
|
||||
$this->assertIdentical(0, strpos(trim($first_content_type), $expected_type), t('Expected content type returned.'));
|
||||
|
||||
// Check that we have 5 items in RSS feed returned by the first request.
|
||||
$xml = simplexml_load_string($first_content);
|
||||
$items = $xml->xpath('/rss/channel/item');
|
||||
$this->assertEqual(5, count($items), t('The number of RSS feed items matched.'));
|
||||
|
||||
// Create another node to be sure we get cached results on the second
|
||||
// request.
|
||||
$this->drupalCreateNode();
|
||||
|
||||
// Make the second request, check content type and content matching.
|
||||
$this->drupalGet('test_feed_http_headers_caching');
|
||||
$second_content = $this->drupalGetContent();
|
||||
$this->assertEqual($first_content, $second_content, t('The second result fetched from cache.'));
|
||||
$second_content_type = $this->drupalGetHeader('content-type');
|
||||
$this->assertEqual($first_content_type, $second_content_type, t('Content types of responses are equal.'));
|
||||
}
|
||||
|
||||
}
|
5
sites/all/modules/views/tests/views_cache.test.css
Normal file
5
sites/all/modules/views/tests/views_cache.test.css
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @file
|
||||
* Just a placeholder file for the test.
|
||||
* @see ViewsCacheTest::testHeaderStorage
|
||||
*/
|
5
sites/all/modules/views/tests/views_cache.test.js
Normal file
5
sites/all/modules/views/tests/views_cache.test.js
Normal file
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @file
|
||||
* Just a placeholder file for the test.
|
||||
* @see ViewsCacheTest::testHeaderStorage
|
||||
*/
|
170
sites/all/modules/views/tests/views_exposed_form.test
Normal file
170
sites/all/modules/views/tests/views_exposed_form.test
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsExposedFormTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests exposed forms.
|
||||
*/
|
||||
class ViewsExposedFormTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Exposed forms',
|
||||
'description' => 'Test exposed forms functionality.',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('views_ui');
|
||||
module_enable(array('views_ui'));
|
||||
// @TODO Figure out why it's required to clear the cache here.
|
||||
views_module_include('views_default', TRUE);
|
||||
views_get_all_views(TRUE);
|
||||
menu_rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests, whether and how the reset button can be renamed.
|
||||
*/
|
||||
public function testRenameResetButton() {
|
||||
$account = $this->drupalCreateUser();
|
||||
$this->drupalLogin($account);
|
||||
// Create some random nodes.
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
// Look at the page and check the label "reset".
|
||||
$this->drupalGet('test_rename_reset_button');
|
||||
// Rename the label of the reset button.
|
||||
$view = views_get_view('test_rename_reset_button');
|
||||
$view->set_display('default');
|
||||
|
||||
$exposed_form = $view->display_handler->get_option('exposed_form');
|
||||
$exposed_form['options']['reset_button_label'] = $expected_label = $this->randomName();
|
||||
$exposed_form['options']['reset_button'] = TRUE;
|
||||
$view->display_handler->set_option('exposed_form', $exposed_form);
|
||||
$view->save();
|
||||
|
||||
views_invalidate_cache();
|
||||
|
||||
// Look whether ther reset button label changed.
|
||||
$this->drupalGet('test_rename_reset_button');
|
||||
|
||||
$this->helperButtonHasLabel('edit-reset', $expected_label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the admin interface of exposed filter and sort items.
|
||||
*/
|
||||
function testExposedAdminUi() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
||||
$this->drupalLogin($admin_user);
|
||||
menu_rebuild();
|
||||
$edit = array();
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
||||
// Be sure that the button is called exposed.
|
||||
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose filter'));
|
||||
|
||||
// The first time the filter UI is displayed, the operator and the
|
||||
// value forms should be shown.
|
||||
$this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
|
||||
$this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
|
||||
$this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
|
||||
$this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
|
||||
|
||||
// Click the Expose filter button.
|
||||
$this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type', $edit, t('Expose filter'));
|
||||
// Check the label of the expose button.
|
||||
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide filter'));
|
||||
// Check the label of the grouped exposed button
|
||||
$this->helperButtonHasLabel('edit-options-group-button-button', t('Grouped filters'));
|
||||
|
||||
// After Expose the filter, Operator and Value should be still here
|
||||
$this->assertFieldById('edit-options-operator-in', '', 'Operator In exists');
|
||||
$this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists');
|
||||
$this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists');
|
||||
$this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists');
|
||||
|
||||
// Check the validations of the filter handler.
|
||||
$edit = array();
|
||||
$edit['options[expose][identifier]'] = '';
|
||||
$this->drupalPost(NULL, $edit, t('Apply'));
|
||||
$this->assertText(t('The identifier is required if the filter is exposed.'));
|
||||
|
||||
$edit = array();
|
||||
$edit['options[expose][identifier]'] = 'value';
|
||||
$this->drupalPost(NULL, $edit, t('Apply'));
|
||||
$this->assertText(t('This identifier is not allowed.'));
|
||||
|
||||
// Now check the sort criteria.
|
||||
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created');
|
||||
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Expose sort'));
|
||||
$this->assertNoFieldById('edit-options-expose-label', '', t('Make sure no label field is shown'));
|
||||
|
||||
// Click the Grouped Filters button.
|
||||
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
||||
$this->drupalPost(NULL, array(), t('Grouped filters'));
|
||||
|
||||
// After click on 'Grouped Filters' standard operator and value should not be displayed
|
||||
$this->assertNoFieldById('edit-options-operator-in', '', 'Operator In not exists');
|
||||
$this->assertNoFieldById('edit-options-operator-not-in', '', 'Operator Not In not exists');
|
||||
$this->assertNoFieldById('edit-options-value-page', '', 'Checkbox for Page not exists');
|
||||
$this->assertNoFieldById('edit-options-value-article', '', 'Checkbox for Article not exists');
|
||||
|
||||
|
||||
// Check that after click on 'Grouped Filters', a new button is shown to
|
||||
// add more items to the list.
|
||||
$this->helperButtonHasLabel('edit-options-group-info-add-group', t('Add another item'));
|
||||
|
||||
// Create a grouped filter
|
||||
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
||||
$edit = array();
|
||||
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
||||
$edit["options[group_info][group_items][1][value][article]"] = 'article';
|
||||
|
||||
$edit["options[group_info][group_items][2][title]"] = 'Is Page';
|
||||
$edit["options[group_info][group_items][2][value][page]"] = TRUE;
|
||||
|
||||
$edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
|
||||
$edit["options[group_info][group_items][3][value][article]"] = TRUE;
|
||||
$edit["options[group_info][group_items][3][value][page]"] = TRUE;
|
||||
$this->drupalPost(NULL, $edit, t('Apply'));
|
||||
|
||||
// Validate that all the titles are defined for each group
|
||||
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
||||
$edit = array();
|
||||
$edit["options[group_info][group_items][1][title]"] = 'Is Article';
|
||||
$edit["options[group_info][group_items][1][value][article]"] = TRUE;
|
||||
|
||||
// This should trigger an error
|
||||
$edit["options[group_info][group_items][2][title]"] = '';
|
||||
$edit["options[group_info][group_items][2][value][page]"] = TRUE;
|
||||
|
||||
$edit["options[group_info][group_items][3][title]"] = 'Is Page and Article';
|
||||
$edit["options[group_info][group_items][3][value][article]"] = TRUE;
|
||||
$edit["options[group_info][group_items][3][value][page]"] = TRUE;
|
||||
$this->drupalPost(NULL, $edit, t('Apply'));
|
||||
$this->assertRaw(t('The title is required if value for this item is defined.'), t('Group items should have a title'));
|
||||
|
||||
// Un-Expose the filter
|
||||
$this->drupalGet('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/filter/type');
|
||||
$this->drupalPost(NULL, array(), t('Hide filter'));
|
||||
|
||||
// After Un-Expose the filter, Operator and Value should be shown again
|
||||
$this->assertFieldById('edit-options-operator-in', '', 'Operator In exists after hide filter');
|
||||
$this->assertFieldById('edit-options-operator-not-in', '', 'Operator Not In exists after hide filter');
|
||||
$this->assertFieldById('edit-options-value-page', '', 'Checkbox for Page exists after hide filter');
|
||||
$this->assertFieldById('edit-options-value-article', '', 'Checkbox for Article exists after hide filter');
|
||||
|
||||
// Click the Expose sort button.
|
||||
$edit = array();
|
||||
$this->drupalPost('admin/structure/views/nojs/config-item/test_exposed_admin_ui/default/sort/created', $edit, t('Expose sort'));
|
||||
// Check the label of the expose button.
|
||||
$this->helperButtonHasLabel('edit-options-expose-button-button', t('Hide sort'));
|
||||
$this->assertFieldById('edit-options-expose-label', '', t('Make sure a label field is shown'));
|
||||
}
|
||||
}
|
60
sites/all/modules/views/tests/views_glossary.test
Normal file
60
sites/all/modules/views/tests/views_glossary.test
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsGlossaryTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests glossary view ( summary of arguments ).
|
||||
*/
|
||||
class ViewsGlossaryTestCase extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Glossary Test',
|
||||
'description' => 'Tests glossary functionality of views.',
|
||||
'group' => 'Views',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('views');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the default glossary view.
|
||||
*/
|
||||
public function testGlossaryView() {
|
||||
// create a contentype and add some nodes, with a non random title.
|
||||
$type = $this->drupalCreateContentType();
|
||||
$nodes_per_char = array(
|
||||
'd' => 1,
|
||||
'r' => 4,
|
||||
'u' => 10,
|
||||
'p' => 2,
|
||||
'a' => 3,
|
||||
'l' => 6,
|
||||
);
|
||||
foreach ($nodes_per_char as $char => $count) {
|
||||
$setting = array(
|
||||
'type' => $type->type
|
||||
);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$node = $setting;
|
||||
$node['title'] = $char . $this->randomString(3);
|
||||
$this->drupalCreateNode($node);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute glossary view
|
||||
$view = views_get_view('glossary');
|
||||
$view->set_display('attachment');
|
||||
$view->execute_display('attachment');
|
||||
|
||||
// Check that the amount of nodes per char.
|
||||
$result_nodes_per_char = array();
|
||||
foreach ($view->result as $item) {
|
||||
$this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
|
||||
}
|
||||
}
|
||||
}
|
326
sites/all/modules/views/tests/views_groupby.test
Normal file
326
sites/all/modules/views/tests/views_groupby.test
Normal file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests aggregate functionality of Views.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests aggregate functionality of views, for example count.
|
||||
*/
|
||||
class ViewsQueryGroupByTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Groupby',
|
||||
'description' => 'Tests aggregate functionality of views, for example count.',
|
||||
'group' => 'Views',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests aggregate count feature.
|
||||
*/
|
||||
public function testAggregateCount() {
|
||||
// Create 2 nodes of type1 and 3 nodes of type2
|
||||
$type1 = $this->drupalCreateContentType();
|
||||
$type2 = $this->drupalCreateContentType();
|
||||
|
||||
$node_1 = array(
|
||||
'type' => $type1->type,
|
||||
);
|
||||
$this->drupalCreateNode($node_1);
|
||||
$this->drupalCreateNode($node_1);
|
||||
$this->drupalCreateNode($node_1);
|
||||
$this->drupalCreateNode($node_1);
|
||||
|
||||
$node_2 = array(
|
||||
'type' => $type2->type,
|
||||
);
|
||||
$this->drupalCreateNode($node_2);
|
||||
$this->drupalCreateNode($node_2);
|
||||
$this->drupalCreateNode($node_2);
|
||||
|
||||
$view = $this->viewsAggregateCountView();
|
||||
$output = $view->execute_display();
|
||||
|
||||
$this->assertEqual(count($view->result), 2, 'Make sure the count of items is right.');
|
||||
|
||||
$types = array();
|
||||
foreach ($view->result as $item) {
|
||||
// num_records is a alias for nid.
|
||||
$types[$item->node_type] = $item->num_records;
|
||||
}
|
||||
|
||||
$this->assertEqual($types[$type1->type], 4);
|
||||
$this->assertEqual($types[$type2->type], 3);
|
||||
}
|
||||
|
||||
//public function testAggregateSum() {
|
||||
//}
|
||||
|
||||
public function viewsAggregateCountView() {
|
||||
$view = new view;
|
||||
$view->name = 'aggregate_count';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = '';
|
||||
$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['group_by'] = TRUE;
|
||||
$handler->display->display_options['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'some';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Field: Content: Title */
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'title';
|
||||
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['link_to_node'] = 0;
|
||||
/* Contextual filter: Content: Type */
|
||||
$handler->display->display_options['arguments']['type']['id'] = 'type';
|
||||
$handler->display->display_options['arguments']['type']['table'] = 'node';
|
||||
$handler->display->display_options['arguments']['type']['field'] = 'type';
|
||||
$handler->display->display_options['arguments']['type']['default_action'] = 'summary';
|
||||
$handler->display->display_options['arguments']['type']['default_argument_type'] = 'fixed';
|
||||
$handler->display->display_options['arguments']['type']['summary']['format'] = 'default_summary';
|
||||
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $group_by
|
||||
* Which group_by function should be used, for example sum or count.
|
||||
*/
|
||||
function GroupByTestHelper($group_by, $values) {
|
||||
// Create 2 nodes of type1 and 3 nodes of type2
|
||||
$type1 = $this->drupalCreateContentType();
|
||||
$type2 = $this->drupalCreateContentType();
|
||||
|
||||
$node_1 = array(
|
||||
'type' => $type1->type,
|
||||
);
|
||||
// Nids from 1 to 4.
|
||||
$this->drupalCreateNode($node_1);
|
||||
$this->drupalCreateNode($node_1);
|
||||
$this->drupalCreateNode($node_1);
|
||||
$this->drupalCreateNode($node_1);
|
||||
$node_2 = array(
|
||||
'type' => $type2->type,
|
||||
);
|
||||
// Nids from 5 to 7.
|
||||
$this->drupalCreateNode($node_2);
|
||||
$this->drupalCreateNode($node_2);
|
||||
$this->drupalCreateNode($node_2);
|
||||
|
||||
$view = $this->viewsGroupByViewHelper($group_by);
|
||||
$output = $view->execute_display();
|
||||
|
||||
$this->assertEqual(count($view->result), 2, 'Make sure the count of items is right.');
|
||||
// Group by nodetype to identify the right count.
|
||||
foreach ($view->result as $item) {
|
||||
$results[$item->node_type] = $item->nid;
|
||||
}
|
||||
$this->assertEqual($results[$type1->type], $values[0]);
|
||||
$this->assertEqual($results[$type2->type], $values[1]);
|
||||
}
|
||||
|
||||
function viewsGroupByViewHelper($group_by) {
|
||||
$view = new view;
|
||||
$view->name = 'group_by_count';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['group_by'] = TRUE;
|
||||
$handler->display->display_options['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'some';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Field: Content: Nid */
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['group_type'] = $group_by;
|
||||
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['link_to_node'] = 0;
|
||||
/* Field: Content: Type */
|
||||
$handler->display->display_options['fields']['type']['id'] = 'type';
|
||||
$handler->display->display_options['fields']['type']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['type']['field'] = 'type';
|
||||
$handler->display->display_options['fields']['type']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['type']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['type']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['type']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['type']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['type']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['type']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['type']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['type']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['type']['link_to_node'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
public function testGroupByCount() {
|
||||
$this->GroupByTestHelper('count', array(4, 3));
|
||||
}
|
||||
|
||||
function testGroupBySum() {
|
||||
$this->GroupByTestHelper('sum', array(10, 18));
|
||||
}
|
||||
|
||||
|
||||
function testGroupByAverage() {
|
||||
$this->GroupByTestHelper('avg', array(2.5, 6));
|
||||
}
|
||||
|
||||
function testGroupByMin() {
|
||||
$this->GroupByTestHelper('min', array(1, 5));
|
||||
}
|
||||
|
||||
function testGroupByMax() {
|
||||
$this->GroupByTestHelper('max', array(4, 7));
|
||||
}
|
||||
|
||||
public function testGroupByCountOnlyFilters() {
|
||||
// Check if GROUP BY and HAVING are included when a view
|
||||
// Doesn't display SUM, COUNT, MAX... functions in SELECT statment
|
||||
|
||||
$type1 = $this->drupalCreateContentType();
|
||||
|
||||
$node_1 = array(
|
||||
'type' => $type1->type,
|
||||
);
|
||||
for ($x = 0; $x < 10; $x++) {
|
||||
$this->drupalCreateNode($node_1);
|
||||
}
|
||||
|
||||
$view = $this->viewsGroupByCountViewOnlyFilters();
|
||||
$output = $view->execute_display();
|
||||
|
||||
$this->assertTrue(strpos($view->build_info['query'], 'GROUP BY'), t('Make sure that GROUP BY is in the query'));
|
||||
$this->assertTrue(strpos($view->build_info['query'], 'HAVING'), t('Make sure that HAVING is in the query'));
|
||||
}
|
||||
|
||||
function viewsGroupByCountViewOnlyFilters() {
|
||||
$view = new view;
|
||||
$view->name = 'group_by_in_filters';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['group_by'] = TRUE;
|
||||
$handler->display->display_options['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'some';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Field: Nodo: Tipo */
|
||||
$handler->display->display_options['fields']['type']['id'] = 'type';
|
||||
$handler->display->display_options['fields']['type']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['type']['field'] = 'type';
|
||||
$handler->display->display_options['fields']['type']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['type']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['type']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['type']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['type']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['type']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['type']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['type']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['type']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['type']['link_to_node'] = 0;
|
||||
/* Filtrar: Nodo: 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']['group_type'] = 'count';
|
||||
$handler->display->display_options['filters']['nid']['operator'] = '>';
|
||||
$handler->display->display_options['filters']['nid']['value']['value'] = '3';
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests UI of aggregate functionality..
|
||||
*/
|
||||
class viewsUiGroupbyTestCase extends DrupalWebTestCase {
|
||||
function setUp() {
|
||||
// Enable views_ui.
|
||||
parent::setUp('views_ui', 'views_test');
|
||||
|
||||
// Create and log in a user with administer views permission.
|
||||
$views_admin = $this->drupalCreateUser(array('administer views', 'administer blocks', 'bypass node access', 'access user profiles', 'view revisions'));
|
||||
$this->drupalLogin($views_admin);
|
||||
}
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Groupby UI',
|
||||
'description' => 'Tests UI of aggregate functionality.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether basic saving works.
|
||||
*
|
||||
* @todo: this should check the change of the settings as well.
|
||||
*/
|
||||
function testGroupBySave() {
|
||||
$this->drupalGet('admin/structure/views/view/test_views_groupby_save/edit');
|
||||
|
||||
$edit = array(
|
||||
'group_by' => TRUE,
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/test_views_groupby_save/default/group_by', $edit, t('Apply'));
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_views_groupby_save/edit');
|
||||
$this->drupalPost('admin/structure/views/view/test_views_groupby_save/edit', array(), t('Save'));
|
||||
|
||||
$this->drupalGet('admin/structure/views/nojs/display/test_views_groupby_save/default/group_by');
|
||||
}
|
||||
}
|
150
sites/all/modules/views/tests/views_handlers.test
Normal file
150
sites/all/modules/views/tests/views_handlers.test
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsHandlersTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests abstract handlers of views.
|
||||
*/
|
||||
class ViewsHandlersTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Handlers test',
|
||||
'description' => 'test abstract handler definitions',
|
||||
'group' => 'Views',
|
||||
);
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp('views', 'views_ui');
|
||||
module_enable(array('views_ui'));
|
||||
}
|
||||
|
||||
function testFilterInOperatorUi() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
||||
$this->drupalLogin($admin_user);
|
||||
menu_rebuild();
|
||||
|
||||
$path = 'admin/structure/views/nojs/config-item/test_filter_in_operator_ui/default/filter/type';
|
||||
$this->drupalGet($path);
|
||||
$this->assertFieldByName('options[expose][reduce]', FALSE);
|
||||
|
||||
$edit = array(
|
||||
'options[expose][reduce]' => TRUE,
|
||||
);
|
||||
$this->drupalPost($path, $edit, t('Apply'));
|
||||
$this->drupalGet($path);
|
||||
$this->assertFieldByName('options[expose][reduce]', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests views_break_phrase_string function.
|
||||
*/
|
||||
function test_views_break_phrase_string() {
|
||||
$empty_stdclass = new stdClass();
|
||||
$empty_stdclass->operator = 'or';
|
||||
$empty_stdclass->value = array();
|
||||
|
||||
$null = NULL;
|
||||
// check defaults
|
||||
$this->assertEqual($empty_stdclass, views_break_phrase_string('', $null));
|
||||
|
||||
$handler = views_get_handler('node', 'title', 'argument');
|
||||
$this->assertEqual($handler, views_break_phrase_string('', $handler));
|
||||
|
||||
// test ors
|
||||
$handler = views_break_phrase_string('word1 word2+word');
|
||||
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
$handler = views_break_phrase_string('word1+word2+word');
|
||||
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
$handler = views_break_phrase_string('word1 word2 word');
|
||||
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
$handler = views_break_phrase_string('word-1+word-2+word');
|
||||
$this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
$handler = views_break_phrase_string('wõrd1+wõrd2+wõrd');
|
||||
$this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
|
||||
// test ands.
|
||||
$handler = views_break_phrase_string('word1,word2,word');
|
||||
$this->assertEqualValue(array('word1', 'word2', 'word'), $handler);
|
||||
$this->assertEqual('and', $handler->operator);
|
||||
$handler = views_break_phrase_string('word1 word2,word');
|
||||
$this->assertEqualValue(array('word1 word2', 'word'), $handler);
|
||||
$this->assertEqual('and', $handler->operator);
|
||||
$handler = views_break_phrase_string('word1,word2 word');
|
||||
$this->assertEqualValue(array('word1', 'word2 word'), $handler);
|
||||
$this->assertEqual('and', $handler->operator);
|
||||
$handler = views_break_phrase_string('word-1,word-2,word');
|
||||
$this->assertEqualValue(array('word-1', 'word-2', 'word'), $handler);
|
||||
$this->assertEqual('and', $handler->operator);
|
||||
$handler = views_break_phrase_string('wõrd1,wõrd2,wõrd');
|
||||
$this->assertEqualValue(array('wõrd1', 'wõrd2', 'wõrd'), $handler);
|
||||
$this->assertEqual('and', $handler->operator);
|
||||
|
||||
// test a single word
|
||||
$handler = views_break_phrase_string('word');
|
||||
$this->assertEqualValue(array('word'), $handler);
|
||||
$this->assertEqual('and', $handler->operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests views_break_phrase function.
|
||||
*/
|
||||
function test_views_break_phrase() {
|
||||
$empty_stdclass = new stdClass();
|
||||
$empty_stdclass->operator = 'or';
|
||||
$empty_stdclass->value = array();
|
||||
|
||||
$null = NULL;
|
||||
// check defaults
|
||||
$this->assertEqual($empty_stdclass, views_break_phrase('', $null));
|
||||
|
||||
$handler = views_get_handler('node', 'title', 'argument');
|
||||
$this->assertEqual($handler, views_break_phrase('', $handler));
|
||||
|
||||
// Generate three random numbers which can be used below;
|
||||
$n1 = rand(0, 100);
|
||||
$n2 = rand(0, 100);
|
||||
$n3 = rand(0, 100);
|
||||
// test ors
|
||||
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2+$n3", $handler));
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1+$n2+$n3", $handler));
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2 $n3", $handler));
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1 $n2++$n3", $handler));
|
||||
$this->assertEqual('or', $handler->operator);
|
||||
|
||||
// test ands.
|
||||
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1,$n2,$n3", $handler));
|
||||
$this->assertEqual('and', $handler->operator);
|
||||
$this->assertEqualValue(array($n1, $n2, $n3), views_break_phrase("$n1,,$n2,$n3", $handler));
|
||||
$this->assertEqual('and', $handler->operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if two values are equal.
|
||||
*
|
||||
* @param $first
|
||||
* The first value to check.
|
||||
* @param views_handler $handler
|
||||
* @param string $message
|
||||
* The message to display along with the assertion.
|
||||
* @param string $group
|
||||
* The type of assertion - examples are "Browser", "PHP".
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the assertion succeeded, FALSE otherwise.
|
||||
*/
|
||||
protected function assertEqualValue($first, $handler, $message = '', $group = 'Other') {
|
||||
return $this->assert($first == $handler->value, $message ? $message : t('First value is equal to second value'), $group);
|
||||
}
|
||||
}
|
163
sites/all/modules/views/tests/views_module.test
Normal file
163
sites/all/modules/views/tests/views_module.test
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsModuleTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests basic functions from the Views module.
|
||||
*/
|
||||
class ViewsModuleTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Tests views.module',
|
||||
'description' => 'Tests some basic functions of views.module',
|
||||
'group' => 'Views',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
drupal_theme_rebuild();
|
||||
}
|
||||
|
||||
public function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test_previous'] = array();
|
||||
$data['views_test_previous']['id']['field']['moved to'] = array('views_test', 'id');
|
||||
$data['views_test_previous']['id']['filter']['moved to'] = array('views_test', 'id');
|
||||
$data['views_test']['age_previous']['field']['moved to'] = array('views_test', 'age');
|
||||
$data['views_test']['age_previous']['sort']['moved to'] = array('views_test', 'age');
|
||||
$data['views_test_previous']['name_previous']['field']['moved to'] = array('views_test', 'name');
|
||||
$data['views_test_previous']['name_previous']['argument']['moved to'] = array('views_test', 'name');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function test_views_trim_text() {
|
||||
// Test unicode, @see http://drupal.org/node/513396#comment-2839416
|
||||
$text = array(
|
||||
'Tuy nhiên, những hi vọng',
|
||||
'Giả sử chúng tôi có 3 Apple',
|
||||
'siêu nhỏ này là bộ xử lý',
|
||||
'Di động của nhà sản xuất Phần Lan',
|
||||
'khoảng cách từ đại lí đến',
|
||||
'của hãng bao gồm ba dòng',
|
||||
'сд асд асд ас',
|
||||
'асд асд асд ас'
|
||||
);
|
||||
// Just test maxlength without word boundry.
|
||||
$alter = array(
|
||||
'max_length' => 10,
|
||||
);
|
||||
$expect = array(
|
||||
'Tuy nhiên,',
|
||||
'Giả sử chú',
|
||||
'siêu nhỏ n',
|
||||
'Di động củ',
|
||||
'khoảng các',
|
||||
'của hãng b',
|
||||
'сд асд асд',
|
||||
'асд асд ас',
|
||||
);
|
||||
|
||||
foreach ($text as $key => $line) {
|
||||
$result_text = views_trim_text($alter, $line);
|
||||
$this->assertEqual($result_text, $expect[$key]);
|
||||
}
|
||||
|
||||
// Test also word_boundary
|
||||
$alter['word_boundary'] = TRUE;
|
||||
$expect = array(
|
||||
'Tuy nhiên',
|
||||
'Giả sử',
|
||||
'siêu nhỏ',
|
||||
'Di động',
|
||||
'khoảng',
|
||||
'của hãng',
|
||||
'сд асд',
|
||||
'асд асд',
|
||||
);
|
||||
|
||||
foreach ($text as $key => $line) {
|
||||
$result_text = views_trim_text($alter, $line);
|
||||
$this->assertEqual($result_text, $expect[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the dynamic includes of templates via module feature.
|
||||
*/
|
||||
function testModuleTemplates() {
|
||||
$views_status = variable_get('views_defaults', array());
|
||||
$views_status['frontpage'] = FALSE; // false is enabled
|
||||
variable_set('views_defaults', $views_status);
|
||||
|
||||
$existing = array();
|
||||
$type = array();
|
||||
$theme = array();
|
||||
$path = array();
|
||||
$registry = views_theme($existing, $type, $theme, $path);
|
||||
$this->assertTrue(isset($registry['views_view__frontpage']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the views_get_handler method.
|
||||
*/
|
||||
function testviews_get_handler() {
|
||||
$types = array('field', 'area', 'filter');
|
||||
foreach ($types as $type) {
|
||||
$handler = views_get_handler($this->randomName(), $this->randomName(), $type);
|
||||
$this->assertEqual('views_handler_' . $type . '_broken', get_class($handler), t('Make sure that a broken handler of type: @type are created', array('@type' => $type)));
|
||||
}
|
||||
|
||||
$views_data = $this->viewsData();
|
||||
$test_tables = array('views_test' => array('id', 'name'));
|
||||
foreach ($test_tables as $table => $fields) {
|
||||
foreach ($fields as $field) {
|
||||
$data = $views_data[$table][$field];
|
||||
foreach ($data as $id => $field_data) {
|
||||
if (!in_array($id, array('title', 'help'))) {
|
||||
$handler = views_get_handler($table, $field, $id);
|
||||
$this->assertInstanceHandler($handler, $table, $field, $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test the automatic conversion feature.
|
||||
|
||||
// Test the automatic table renaming.
|
||||
$handler = views_get_handler('views_test_previous', 'id', 'field');
|
||||
$this->assertInstanceHandler($handler, 'views_test', 'id', 'field');
|
||||
$handler = views_get_handler('views_test_previous', 'id', 'filter');
|
||||
$this->assertInstanceHandler($handler, 'views_test', 'id', 'filter');
|
||||
|
||||
// Test the automatic field renaming.
|
||||
$handler = views_get_handler('views_test', 'age_previous', 'field');
|
||||
$this->assertInstanceHandler($handler, 'views_test', 'age', 'field');
|
||||
$handler = views_get_handler('views_test', 'age_previous', 'sort');
|
||||
$this->assertInstanceHandler($handler, 'views_test', 'age', 'sort');
|
||||
|
||||
// Test the automatic table and field renaming.
|
||||
$handler = views_get_handler('views_test_previous', 'name_previous', 'field');
|
||||
$this->assertInstanceHandler($handler, 'views_test', 'name', 'field');
|
||||
$handler = views_get_handler('views_test_previous', 'name_previous', 'argument');
|
||||
$this->assertInstanceHandler($handler, 'views_test', 'name', 'argument');
|
||||
|
||||
// Test the override handler feature.
|
||||
$handler = views_get_handler('views_test', 'job', 'filter', 'views_handler_filter');
|
||||
$this->assertEqual('views_handler_filter', get_class($handler));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that a certain handler is a instance of a certain table/field.
|
||||
*/
|
||||
function assertInstanceHandler($handler, $table, $field, $id) {
|
||||
$table_data = views_fetch_data($table);
|
||||
$field_data = $table_data[$field][$id];
|
||||
|
||||
$this->assertEqual($field_data['handler'], get_class($handler));
|
||||
}
|
||||
}
|
496
sites/all/modules/views/tests/views_pager.test
Normal file
496
sites/all/modules/views/tests/views_pager.test
Normal file
@@ -0,0 +1,496 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsPagerTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the pluggable pager system.
|
||||
*/
|
||||
class ViewsPagerTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Pager',
|
||||
'description' => 'Test the pluggable pager system',
|
||||
'group' => 'Views Plugins',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('views', 'views_ui', 'views_test');
|
||||
}
|
||||
|
||||
/**
|
||||
* Pagers was sometimes not stored.
|
||||
*
|
||||
* @see http://drupal.org/node/652712
|
||||
*/
|
||||
public function testStorePagerSettings() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
||||
$this->drupalLogin($admin_user);
|
||||
// Test behaviour described in http://drupal.org/node/652712#comment-2354918.
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/frontpage/edit');
|
||||
|
||||
|
||||
$edit = array(
|
||||
'pager_options[items_per_page]' => 20,
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/frontpage/default/pager_options', $edit, t('Apply'));
|
||||
$this->assertText('20 items');
|
||||
|
||||
// Change type and check whether the type is new type is stored.
|
||||
$edit = array();
|
||||
$edit = array(
|
||||
'pager[type]' => 'mini',
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/frontpage/default/pager', $edit, t('Apply'));
|
||||
$this->drupalGet('admin/structure/views/view/frontpage/edit');
|
||||
$this->assertText('Mini', 'Changed pager plugin, should change some text');
|
||||
|
||||
// Test behaviour described in http://drupal.org/node/652712#comment-2354400
|
||||
$view = $this->viewsStorePagerSettings();
|
||||
// Make it editable in the admin interface.
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
|
||||
|
||||
$edit = array();
|
||||
$edit = array(
|
||||
'pager[type]' => 'full',
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager', $edit, t('Apply'));
|
||||
$this->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
|
||||
$this->assertText('Full');
|
||||
|
||||
$edit = array(
|
||||
'pager_options[items_per_page]' => 20,
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options', $edit, t('Apply'));
|
||||
$this->assertText('20 items');
|
||||
|
||||
// add new display and test the settings again, by override it.
|
||||
$edit = array( );
|
||||
// Add a display and override the pager settings.
|
||||
$this->drupalPost('admin/structure/views/view/test_store_pager_settings/edit', $edit, t('Add Page'));
|
||||
$edit = array(
|
||||
'override[dropdown]' => 'page_1',
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager', $edit, t('Apply'));
|
||||
|
||||
$edit = array(
|
||||
'pager[type]' => 'mini',
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager', $edit, t('Apply'));
|
||||
$this->drupalGet('admin/structure/views/view/test_store_pager_settings/edit');
|
||||
$this->assertText('Mini', 'Changed pager plugin, should change some text');
|
||||
|
||||
$edit = array(
|
||||
'pager_options[items_per_page]' => 10,
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/test_store_pager_settings/default/pager_options', $edit, t('Apply'));
|
||||
$this->assertText('20 items');
|
||||
|
||||
}
|
||||
|
||||
public function viewsStorePagerSettings() {
|
||||
$view = new view;
|
||||
$view->name = 'test_store_pager_settings';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 3;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'none';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the none-pager-query.
|
||||
*/
|
||||
public function testNoLimit() {
|
||||
// Create 11 nodes and make sure that everyone is returned.
|
||||
// We create 11 nodes, because the default pager plugin had 10 items per page.
|
||||
for ($i = 0; $i < 11; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
$view = $this->viewsPagerNoLimit();
|
||||
$view->set_display('default');
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 11, 'Make sure that every item is returned in the result');
|
||||
|
||||
$view->destroy();
|
||||
|
||||
// Setup and test a offset.
|
||||
$view = $this->viewsPagerNoLimit();
|
||||
$view->set_display('default');
|
||||
|
||||
$pager = array(
|
||||
'type' => 'none',
|
||||
'options' => array(
|
||||
'offset' => 3,
|
||||
),
|
||||
);
|
||||
$view->display_handler->set_option('pager', $pager);
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual(count($view->result), 8, 'Make sure that every item beside the first three is returned in the result');
|
||||
|
||||
// Check some public functions.
|
||||
$this->assertFalse($view->query->pager->use_pager());
|
||||
$this->assertFalse($view->query->pager->use_count_query());
|
||||
$this->assertEqual($view->query->pager->get_items_per_page(), 0);
|
||||
}
|
||||
|
||||
public function viewsPagerNoLimit() {
|
||||
$view = new view;
|
||||
$view->name = 'test_pager_none';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version =3;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'none';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
return $view;
|
||||
}
|
||||
|
||||
public function testViewTotalRowsWithoutPager() {
|
||||
$this->createNodes(23);
|
||||
|
||||
$view = $this->viewsPagerNoLimit();
|
||||
$view->get_total_rows = TRUE;
|
||||
$view->set_display('default');
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual($view->total_rows, 23, "'total_rows' is calculated when pager type is 'none' and 'get_total_rows' is TRUE.");
|
||||
}
|
||||
|
||||
public function createNodes($count) {
|
||||
if ($count >= 0) {
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the some pager plugin.
|
||||
*/
|
||||
public function testLimit() {
|
||||
// Create 11 nodes and make sure that everyone is returned.
|
||||
// We create 11 nodes, because the default pager plugin had 10 items per page.
|
||||
for ($i = 0; $i < 11; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
$view = $this->viewsPagerLimit();
|
||||
$view->set_display('default');
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 5, 'Make sure that only a certain count of items is returned');
|
||||
$view->destroy();
|
||||
|
||||
// Setup and test a offset.
|
||||
$view = $this->viewsPagerLimit();
|
||||
$view->set_display('default');
|
||||
|
||||
$pager = array(
|
||||
'type' => 'none',
|
||||
'options' => array(
|
||||
'offset' => 8,
|
||||
'items_per_page' => 5,
|
||||
),
|
||||
);
|
||||
$view->display_handler->set_option('pager', $pager);
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 3, 'Make sure that only a certain count of items is returned');
|
||||
|
||||
// Check some public functions.
|
||||
$this->assertFalse($view->query->pager->use_pager());
|
||||
$this->assertFalse($view->query->pager->use_count_query());
|
||||
}
|
||||
|
||||
public function viewsPagerLimit() {
|
||||
$view = new view;
|
||||
$view->name = 'test_pager_some';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 3;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'some';
|
||||
$handler->display->display_options['pager']['options']['offset'] = 0;
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = 5;
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the normal pager.
|
||||
*/
|
||||
public function testNormalPager() {
|
||||
// Create 11 nodes and make sure that everyone is returned.
|
||||
// We create 11 nodes, because the default pager plugin had 10 items per page.
|
||||
for ($i = 0; $i < 11; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
$view = $this->viewsPagerFull();
|
||||
$view->set_display('default');
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 5, 'Make sure that only a certain count of items is returned');
|
||||
$view->destroy();
|
||||
|
||||
// Setup and test a offset.
|
||||
$view = $this->viewsPagerFull();
|
||||
$view->set_display('default');
|
||||
|
||||
$pager = array(
|
||||
'type' => 'full',
|
||||
'options' => array(
|
||||
'offset' => 8,
|
||||
'items_per_page' => 5,
|
||||
),
|
||||
);
|
||||
$view->display_handler->set_option('pager', $pager);
|
||||
$this->executeView($view);
|
||||
$this->assertEqual(count($view->result), 3, 'Make sure that only a certain count of items is returned');
|
||||
|
||||
// Test items per page = 0
|
||||
$view = $this->viewPagerFullZeroItemsPerPage();
|
||||
$view->set_display('default');
|
||||
$this->executeView($view);
|
||||
|
||||
$this->assertEqual(count($view->result), 11, 'All items are return');
|
||||
|
||||
// TODO test number of pages.
|
||||
|
||||
// Test items per page = 0.
|
||||
$view->destroy();
|
||||
|
||||
// Setup and test a offset.
|
||||
$view = $this->viewsPagerFull();
|
||||
$view->set_display('default');
|
||||
|
||||
$pager = array(
|
||||
'type' => 'full',
|
||||
'options' => array(
|
||||
'offset' => 0,
|
||||
'items_per_page' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
$view->display_handler->set_option('pager', $pager);
|
||||
$this->executeView($view);
|
||||
$this->assertEqual($view->query->pager->get_items_per_page(), 0);
|
||||
$this->assertEqual(count($view->result), 11);
|
||||
}
|
||||
|
||||
function viewPagerFullZeroItemsPerPage() {
|
||||
$view = new view;
|
||||
$view->name = 'view_pager_full_zero_items_per_page';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 3;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '0';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* 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']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
function viewsPagerFull() {
|
||||
$view = new view;
|
||||
$view->name = 'test_pager_full';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 3;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
function viewsPagerFullFields() {
|
||||
$view = new view;
|
||||
$view->name = 'test_pager_full';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 3;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
$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']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the minipager.
|
||||
*/
|
||||
public function testMiniPager() {
|
||||
// the functionality is the same as the normal pager, so i don't know what to test here.
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests rendering with NULL pager.
|
||||
*/
|
||||
public function testRenderNullPager() {
|
||||
// Create 11 nodes and make sure that everyone is returned.
|
||||
// We create 11 nodes, because the default pager plugin had 10 items per page.
|
||||
for ($i = 0; $i < 11; $i++) {
|
||||
$this->drupalCreateNode();
|
||||
}
|
||||
$view = $this->viewsPagerFullFields();
|
||||
$view->set_display('default');
|
||||
$this->executeView($view);
|
||||
$view->use_ajax = TRUE; // force the value again here
|
||||
$view->query->pager = NULL;
|
||||
$output = $view->render();
|
||||
$this->assertEqual(preg_match('/<ul class="pager">/', $output), 0, t('The pager is not rendered.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the api functions on the view object.
|
||||
*/
|
||||
function testPagerApi() {
|
||||
$view = $this->viewsPagerFull();
|
||||
// On the first round don't initialize the pager.
|
||||
|
||||
$this->assertEqual($view->get_items_per_page(), NULL, 'If the pager is not initialized and no manual override there is no items per page.');
|
||||
$rand_number = rand(1, 5);
|
||||
$view->set_items_per_page($rand_number);
|
||||
$this->assertEqual($view->get_items_per_page(), $rand_number, 'Make sure get_items_per_page uses the settings of set_items_per_page.');
|
||||
|
||||
$this->assertEqual($view->get_offset(), NULL, 'If the pager is not initialized and no manual override there is no offset.');
|
||||
$rand_number = rand(1, 5);
|
||||
$view->set_offset($rand_number);
|
||||
$this->assertEqual($view->get_offset(), $rand_number, 'Make sure get_offset uses the settings of set_offset.');
|
||||
|
||||
$this->assertEqual($view->get_current_page(), NULL, 'If the pager is not initialized and no manual override there is no current page.');
|
||||
$rand_number = rand(1, 5);
|
||||
$view->set_current_page($rand_number);
|
||||
$this->assertEqual($view->get_current_page(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.');
|
||||
|
||||
$view->destroy();
|
||||
|
||||
// On this round enable the pager.
|
||||
$view->init_display();
|
||||
$view->init_query();
|
||||
$view->init_pager();
|
||||
|
||||
$this->assertEqual($view->get_items_per_page(), 5, 'Per default the view has 5 items per page.');
|
||||
$rand_number = rand(1, 5);
|
||||
$view->set_items_per_page($rand_number);
|
||||
$rand_number = rand(6, 11);
|
||||
$view->query->pager->set_items_per_page($rand_number);
|
||||
$this->assertEqual($view->get_items_per_page(), $rand_number, 'Make sure get_items_per_page uses the settings of set_items_per_page.');
|
||||
|
||||
$this->assertEqual($view->get_offset(), 0, 'Per default a view has a 0 offset.');
|
||||
$rand_number = rand(1, 5);
|
||||
$view->set_offset($rand_number);
|
||||
$rand_number = rand(6, 11);
|
||||
$view->query->pager->set_offset($rand_number);
|
||||
$this->assertEqual($view->get_offset(), $rand_number, 'Make sure get_offset uses the settings of set_offset.');
|
||||
|
||||
$this->assertEqual($view->get_current_page(), 0, 'Per default the current page is 0.');
|
||||
$rand_number = rand(1, 5);
|
||||
$view->set_current_page($rand_number);
|
||||
$rand_number = rand(6, 11);
|
||||
$view->query->pager->set_current_page($rand_number);
|
||||
$this->assertEqual($view->get_current_page(), $rand_number, 'Make sure get_current_page uses the settings of set_current_page.');
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_plugin_localization_test.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A stump localisation plugin which has static variables to cache the input.
|
||||
*/
|
||||
class views_plugin_localization_test extends views_plugin_localization {
|
||||
/**
|
||||
* Store the strings which was translated.
|
||||
*/
|
||||
var $translated_strings;
|
||||
/**
|
||||
* Return the string and take sure that the test can find out whether the
|
||||
* string got translated.
|
||||
*/
|
||||
function translate_string($string, $keys = array(), $format = '') {
|
||||
$this->translated_strings[] = $string;
|
||||
return $string . "-translated";
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the export strings.
|
||||
*/
|
||||
function export($source) {
|
||||
if (!empty($source['value'])) {
|
||||
$this->export_strings[] = $source['value'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the stored strings for the simpletest.
|
||||
*/
|
||||
function get_export_strings() {
|
||||
return $this->export_strings;
|
||||
}
|
||||
}
|
433
sites/all/modules/views/tests/views_query.test
Normal file
433
sites/all/modules/views/tests/views_query.test
Normal file
@@ -0,0 +1,433 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for Views query features.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract class for views testing.
|
||||
*/
|
||||
abstract class ViewsTestCase extends DrupalWebTestCase {
|
||||
/**
|
||||
* Helper function: verify a result set returned by view.
|
||||
*
|
||||
* The comparison is done on the string representation of the columns of the
|
||||
* column map, taking the order of the rows into account, but not the order
|
||||
* of the columns.
|
||||
*
|
||||
* @param $view
|
||||
* An executed View.
|
||||
* @param $expected_result
|
||||
* An expected result set.
|
||||
* @param $column_map
|
||||
* An associative array mapping the columns of the result set from the view
|
||||
* (as keys) and the expected result set (as values).
|
||||
*/
|
||||
protected function assertIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') {
|
||||
return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertIdentical');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function: verify a result set returned by view..
|
||||
*
|
||||
* Inverse of ViewsTestCase::assertIdenticalResultset().
|
||||
*
|
||||
* @param $view
|
||||
* An executed View.
|
||||
* @param $expected_result
|
||||
* An expected result set.
|
||||
* @param $column_map
|
||||
* An associative array mapping the columns of the result set from the view
|
||||
* (as keys) and the expected result set (as values).
|
||||
*/
|
||||
protected function assertNotIdenticalResultset($view, $expected_result, $column_map = array(), $message = 'Identical result set') {
|
||||
return $this->assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, 'assertNotIdentical');
|
||||
}
|
||||
|
||||
protected function assertIdenticalResultsetHelper($view, $expected_result, $column_map, $message, $assert_method) {
|
||||
// Convert $view->result to an array of arrays.
|
||||
$result = array();
|
||||
foreach ($view->result as $key => $value) {
|
||||
$row = array();
|
||||
foreach ($column_map as $view_column => $expected_column) {
|
||||
// The comparison will be done on the string representation of the value.
|
||||
$row[$expected_column] = (string) $value->$view_column;
|
||||
}
|
||||
$result[$key] = $row;
|
||||
}
|
||||
|
||||
// Remove the columns we don't need from the expected result.
|
||||
foreach ($expected_result as $key => $value) {
|
||||
$row = array();
|
||||
foreach ($column_map as $expected_column) {
|
||||
// The comparison will be done on the string representation of the value.
|
||||
$row[$expected_column] = (string) (is_object($value) ? $value->$expected_column : $value[$expected_column]);
|
||||
}
|
||||
$expected_result[$key] = $row;
|
||||
}
|
||||
|
||||
// Reset the numbering of the arrays.
|
||||
$result = array_values($result);
|
||||
$expected_result = array_values($expected_result);
|
||||
|
||||
$this->verbose('<pre>Returned data set: ' . print_r($result, TRUE) . "\n\nExpected: ". print_r($expected_result, TRUE));
|
||||
|
||||
// Do the actual comparison.
|
||||
return $this->$assert_method($result, $expected_result, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function: order an array of array based on a column.
|
||||
*/
|
||||
protected function orderResultSet($result_set, $column, $reverse = FALSE) {
|
||||
$this->sort_column = $column;
|
||||
$this->sort_order = $reverse ? -1 : 1;
|
||||
usort($result_set, array($this, 'helperCompareFunction'));
|
||||
return $result_set;
|
||||
}
|
||||
|
||||
protected $sort_column = NULL;
|
||||
protected $sort_order = 1;
|
||||
|
||||
/**
|
||||
* Helper comparison function for orderResultSet().
|
||||
*/
|
||||
protected function helperCompareFunction($a, $b) {
|
||||
$value1 = $a[$this->sort_column];
|
||||
$value2 = $b[$this->sort_column];
|
||||
if ($value1 == $value2) {
|
||||
return 0;
|
||||
}
|
||||
return $this->sort_order * (($value1 < $value2) ? -1 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to check whether a button with a certain id exists and has a certain label.
|
||||
*/
|
||||
protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') {
|
||||
return $this->assertFieldById($id, $expected_label, t($message, array('%label' => $expected_label)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to execute a view with debugging.
|
||||
*
|
||||
* @param view $view
|
||||
* @param array $args
|
||||
*/
|
||||
protected function executeView($view, $args = array()) {
|
||||
$view->set_display();
|
||||
$view->pre_execute($args);
|
||||
$view->execute();
|
||||
$this->verbose('<pre>Executed view: ' . ((string) $view->build_info['query']) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ViewsSqlTest extends ViewsTestCase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp('views', 'views_ui');
|
||||
|
||||
// Define the schema and views data variable before enabling the test module.
|
||||
variable_set('views_test_schema', $this->schemaDefinition());
|
||||
variable_set('views_test_views_data', $this->viewsData());
|
||||
variable_set('views_test_views_plugins', $this->viewsPlugins());
|
||||
|
||||
module_enable(array('views_test'));
|
||||
$this->resetAll();
|
||||
|
||||
// Load the test dataset.
|
||||
$data_set = $this->dataSet();
|
||||
$query = db_insert('views_test')
|
||||
->fields(array_keys($data_set[0]));
|
||||
foreach ($data_set as $record) {
|
||||
$query->values($record);
|
||||
}
|
||||
$query->execute();
|
||||
$this->checkPermissions(array(), TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function allows to enable views ui from a higher class which can't change the setup function anymore.
|
||||
*
|
||||
* @TODO
|
||||
* Convert existing setUp functions.
|
||||
*/
|
||||
function enableViewsUi() {
|
||||
module_enable(array('views_ui'));
|
||||
// @TODO Figure out why it's required to clear the cache here.
|
||||
views_module_include('views_default', TRUE);
|
||||
views_get_all_views(TRUE);
|
||||
menu_rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* The schema definition.
|
||||
*/
|
||||
protected function schemaDefinition() {
|
||||
$schema['views_test'] = array(
|
||||
'description' => 'Basic test table for Views tests.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => "A person's name",
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'age' => array(
|
||||
'description' => "The person's age",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0),
|
||||
'job' => array(
|
||||
'description' => "The person's job",
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => 'Undefined',
|
||||
),
|
||||
'created' => array(
|
||||
'description' => "The creation date of this record",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
'unique keys' => array(
|
||||
'name' => array('name')
|
||||
),
|
||||
'indexes' => array(
|
||||
'ages' => array('age'),
|
||||
),
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* The views data definition.
|
||||
*/
|
||||
protected function viewsData() {
|
||||
// Declaration of the base table.
|
||||
$data['views_test']['table'] = array(
|
||||
'group' => t('Views test'),
|
||||
'base' => array(
|
||||
'field' => 'id',
|
||||
'title' => t('Views test'),
|
||||
'help' => t('Users who have created accounts on your site.'),
|
||||
),
|
||||
);
|
||||
|
||||
// Declaration of fields.
|
||||
$data['views_test']['id'] = array(
|
||||
'title' => t('ID'),
|
||||
'help' => t('The test data ID'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_numeric',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['views_test']['name'] = array(
|
||||
'title' => t('Name'),
|
||||
'help' => t('The name of the person'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['views_test']['age'] = array(
|
||||
'title' => t('Age'),
|
||||
'help' => t('The age of the person'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_numeric',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_numeric',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['views_test']['job'] = array(
|
||||
'title' => t('Job'),
|
||||
'help' => t('The job of the person'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['views_test']['created'] = array(
|
||||
'title' => t('Created'),
|
||||
'help' => t('The creation date of this record'),
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field_date',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_date',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_date',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort_date',
|
||||
),
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function viewsPlugins() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* A very simple test dataset.
|
||||
*/
|
||||
protected function dataSet() {
|
||||
return array(
|
||||
array(
|
||||
'name' => 'John',
|
||||
'age' => 25,
|
||||
'job' => 'Singer',
|
||||
'created' => gmmktime(0, 0, 0, 1, 1, 2000),
|
||||
),
|
||||
array(
|
||||
'name' => 'George',
|
||||
'age' => 27,
|
||||
'job' => 'Singer',
|
||||
'created' => gmmktime(0, 0, 0, 1, 2, 2000),
|
||||
),
|
||||
array(
|
||||
'name' => 'Ringo',
|
||||
'age' => 28,
|
||||
'job' => 'Drummer',
|
||||
'created' => gmmktime(6, 30, 30, 1, 1, 2000),
|
||||
),
|
||||
array(
|
||||
'name' => 'Paul',
|
||||
'age' => 26,
|
||||
'job' => 'Songwriter',
|
||||
'created' => gmmktime(6, 0, 0, 1, 1, 2000),
|
||||
),
|
||||
array(
|
||||
'name' => 'Meredith',
|
||||
'age' => 30,
|
||||
'job' => 'Speaker',
|
||||
'created' => gmmktime(6, 30, 10, 1, 1, 2000),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and return a basic view of the views_test table.
|
||||
*
|
||||
* @return view
|
||||
*/
|
||||
protected function getBasicView() {
|
||||
views_include('view');
|
||||
|
||||
// Create the basic view.
|
||||
$view = new view();
|
||||
$view->name = 'test_view';
|
||||
$view->add_display('default');
|
||||
$view->base_table = 'views_test';
|
||||
|
||||
// Set up the fields we need.
|
||||
$display = $view->new_display('default', 'Master', 'default');
|
||||
$display->override_option('fields', array(
|
||||
'id' => array(
|
||||
'id' => 'id',
|
||||
'table' => 'views_test',
|
||||
'field' => 'id',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'name' => array(
|
||||
'id' => 'name',
|
||||
'table' => 'views_test',
|
||||
'field' => 'name',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'age' => array(
|
||||
'id' => 'age',
|
||||
'table' => 'views_test',
|
||||
'field' => 'age',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Set up the sort order.
|
||||
$display->override_option('sorts', array(
|
||||
'id' => array(
|
||||
'order' => 'ASC',
|
||||
'id' => 'id',
|
||||
'table' => 'views_test',
|
||||
'field' => 'id',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
|
||||
// Set up the pager.
|
||||
$display->override_option('pager', array(
|
||||
'type' => 'none',
|
||||
'options' => array('offset' => 0),
|
||||
));
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and return a Page view of the views_test table.
|
||||
*
|
||||
* @return view
|
||||
*/
|
||||
protected function getBasicPageView() {
|
||||
views_include('view');
|
||||
$view = $this->getBasicView();
|
||||
|
||||
// In order to test exposed filters, we have to disable
|
||||
// the exposed forms cache.
|
||||
drupal_static_reset('views_exposed_form_cache');
|
||||
|
||||
$display = $view->new_display('page', 'Page', 'page_1');
|
||||
return $view;
|
||||
}
|
||||
}
|
13
sites/all/modules/views/tests/views_test.info
Normal file
13
sites/all/modules/views/tests/views_test.info
Normal file
@@ -0,0 +1,13 @@
|
||||
name = Views Test
|
||||
description = Test module for Views.
|
||||
package = Views
|
||||
core = 7.x
|
||||
dependencies[] = views
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-02-04
|
||||
version = "7.x-3.5+38-dev"
|
||||
core = "7.x"
|
||||
project = "views"
|
||||
datestamp = "1359942791"
|
||||
|
13
sites/all/modules/views/tests/views_test.install
Normal file
13
sites/all/modules/views/tests/views_test.install
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update, and uninstall functions for the Views Test module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function views_test_schema() {
|
||||
return variable_get('views_test_schema', array());
|
||||
}
|
117
sites/all/modules/views/tests/views_test.module
Normal file
117
sites/all/modules/views/tests/views_test.module
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Helper module for Views tests.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function views_test_permission() {
|
||||
return array(
|
||||
'views_test test permission' => array(
|
||||
'title' => t('Test permission'),
|
||||
'description' => t('views_test test permission'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function views_test_views_api() {
|
||||
return array(
|
||||
'api' => 3.0,
|
||||
'template path' => drupal_get_path('module', 'views_test') . '/templates',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function views_test_views_data() {
|
||||
return variable_get('views_test_views_data', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_plugins().
|
||||
*/
|
||||
function views_test_views_plugins() {
|
||||
return variable_get('views_test_views_plugins', array());
|
||||
}
|
||||
|
||||
function views_test_test_static_access_callback($access) {
|
||||
return $access;
|
||||
}
|
||||
|
||||
function views_test_test_dynamic_access_callback($access, $argument1, $argument2) {
|
||||
return $access && $argument1 == variable_get('test_dynamic_access_argument1', NULL) && $argument2 == variable_get('test_dynamic_access_argument2', NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_pre_render().
|
||||
*/
|
||||
function views_test_views_pre_render(&$view) {
|
||||
if ($view->name == 'test_cache_header_storage') {
|
||||
drupal_add_js(drupal_get_path('module', 'views_test') . '/views_cache.test.js');
|
||||
drupal_add_css(drupal_get_path('module', 'views_test') . '/views_cache.test.css');
|
||||
$view->pre_render_called = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK() for theme_views_view_mapping_test().
|
||||
*/
|
||||
function template_preprocess_views_view_mapping_test(&$variables) {
|
||||
$variables['element'] = array();
|
||||
|
||||
foreach ($variables['rows'] as $delta => $row) {
|
||||
$fields = array();
|
||||
foreach ($variables['options']['mapping'] as $type => $field_names) {
|
||||
if (!is_array($field_names)) {
|
||||
$field_names = array($field_names);
|
||||
}
|
||||
foreach ($field_names as $field_name) {
|
||||
if ($value = $variables['view']->style_plugin->get_field($delta, $field_name)) {
|
||||
$fields[$type . '-' . $field_name] = $type . ':' . $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no fields in this row, skip to the next one.
|
||||
if (empty($fields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Build a container for the row.
|
||||
$variables['element'][$delta] = array(
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array(
|
||||
'views-row-mapping-test',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Add each field to the row.
|
||||
foreach ($fields as $key => $render) {
|
||||
$variables['element'][$delta][$key] = array(
|
||||
'#children' => $render,
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array(
|
||||
$key,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML for the Mapping Test style.
|
||||
*/
|
||||
function theme_views_view_mapping_test($variables) {
|
||||
return drupal_render($variables['element']);
|
||||
}
|
222
sites/all/modules/views/tests/views_test.views_default.inc
Normal file
222
sites/all/modules/views/tests/views_test.views_default.inc
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests views.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_default_views().
|
||||
*/
|
||||
function views_test_views_default_views() {
|
||||
$view = new view;
|
||||
$view->name = 'test_views_groupby_save';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$view->version = 7;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'none';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
$view = new view;
|
||||
$view->name = 'test_rename_reset_button';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = '';
|
||||
$view->core = 0;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['query']['type'] = 'views_query';
|
||||
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE;
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
$handler->display->display_options['row_options']['links'] = 1;
|
||||
$handler->display->display_options['row_options']['comments'] = 0;
|
||||
/* Filter criterion: Content: Type */
|
||||
$handler->display->display_options['filters']['type']['id'] = 'type';
|
||||
$handler->display->display_options['filters']['type']['table'] = 'node';
|
||||
$handler->display->display_options['filters']['type']['field'] = 'type';
|
||||
$handler->display->display_options['filters']['type']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['type']['expose']['operator_id'] = 'type_op';
|
||||
$handler->display->display_options['filters']['type']['expose']['label'] = 'Content: Type';
|
||||
$handler->display->display_options['filters']['type']['expose']['identifier'] = 'type';
|
||||
$handler->display->display_options['filters']['type']['expose']['reduce'] = 0;
|
||||
|
||||
/* Display: Page */
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->display->display_options['path'] = 'test_rename_reset_button';
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
$view = new view;
|
||||
$view->name = 'test_exposed_admin_ui';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$view->version = 7;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE;
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
$handler->display->display_options['row_options']['links'] = 1;
|
||||
$handler->display->display_options['row_options']['comments'] = 0;
|
||||
/* 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';
|
||||
/* Filter: Content: Type */
|
||||
$handler->display->display_options['filters']['type']['id'] = 'type';
|
||||
$handler->display->display_options['filters']['type']['table'] = 'node';
|
||||
$handler->display->display_options['filters']['type']['field'] = 'type';
|
||||
$handler->display->display_options['filters']['type']['expose']['operator_id'] = 'type_op';
|
||||
$handler->display->display_options['filters']['type']['expose']['label'] = 'Content: Type';
|
||||
$handler->display->display_options['filters']['type']['expose']['use_operator'] = TRUE;
|
||||
|
||||
/* Display: Page */
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->display->display_options['path'] = 'test_exposed_admin_ui';
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
$view = new view;
|
||||
$view->name = 'test_filter_in_operator_ui';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$view->version = 7;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Filter: Content: Type */
|
||||
$handler->display->display_options['filters']['type']['id'] = 'type';
|
||||
$handler->display->display_options['filters']['type']['table'] = 'node';
|
||||
$handler->display->display_options['filters']['type']['field'] = 'type';
|
||||
$handler->display->display_options['filters']['type']['exposed'] = TRUE;
|
||||
$handler->display->display_options['filters']['type']['expose']['operator_id'] = 'type_op';
|
||||
$handler->display->display_options['filters']['type']['expose']['label'] = 'Content: Type';
|
||||
$handler->display->display_options['filters']['type']['expose']['use_operator'] = 0;
|
||||
$handler->display->display_options['filters']['type']['expose']['identifier'] = 'type';
|
||||
$handler->display->display_options['filters']['type']['expose']['reduce'] = 0;
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
$view = new view;
|
||||
$view->name = 'test_argument_default_current_user';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 3;
|
||||
$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['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'none';
|
||||
$handler->display->display_options['exposed_form']['type'] = 'basic';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* 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']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
|
||||
/* Contextual filter: Content: Author uid */
|
||||
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
|
||||
$handler->display->display_options['arguments']['uid']['table'] = 'node';
|
||||
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
|
||||
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
$view = new view();
|
||||
$view->name = 'test_feed_http_headers_caching';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node';
|
||||
$view->core = 7;
|
||||
$view->api_version = '3.0';
|
||||
$view->disabled = FALSE;
|
||||
|
||||
/* Display: Master */
|
||||
$handler = $view->new_display('default', 'Master', 'default');
|
||||
$handler->display->display_options['access']['type'] = 'none';
|
||||
$handler->display->display_options['cache']['type'] = 'time';
|
||||
$handler->display->display_options['cache']['results_lifespan'] = '3600';
|
||||
$handler->display->display_options['cache']['results_lifespan_custom'] = '0';
|
||||
$handler->display->display_options['cache']['output_lifespan'] = '3600';
|
||||
$handler->display->display_options['cache']['output_lifespan_custom'] = '0';
|
||||
$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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'node';
|
||||
|
||||
/* Display: Feed */
|
||||
$handler = $view->new_display('feed', 'Feed', 'feed_1');
|
||||
$handler->display->display_options['pager']['type'] = 'none';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['style_plugin'] = 'rss';
|
||||
$handler->display->display_options['row_plugin'] = 'node_rss';
|
||||
$handler->display->display_options['path'] = 'test_feed_http_headers_caching';
|
||||
|
||||
$views[$view->name] = $view;
|
||||
|
||||
return $views;
|
||||
}
|
200
sites/all/modules/views/tests/views_translatable.test
Normal file
200
sites/all/modules/views/tests/views_translatable.test
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsTranslatableTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests Views pluggable translations.
|
||||
*/
|
||||
class ViewsTranslatableTest extends ViewsSqlTest {
|
||||
var $strings;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views Translatable Test',
|
||||
'description' => 'Tests the pluggable translations',
|
||||
'group' => 'Views',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The views plugin definition. Override it if you test provides a plugin.
|
||||
*/
|
||||
public function viewsPlugins() {
|
||||
return array(
|
||||
'localization' => array(
|
||||
'test' => array(
|
||||
'no ui' => TRUE,
|
||||
'title' => t('Test'),
|
||||
'help' => t('This is a test description.'),
|
||||
'handler' => 'views_plugin_localization_test',
|
||||
'parent' => 'parent',
|
||||
'path' => drupal_get_path('module', 'views') .'/tests',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
variable_set('views_localization_plugin', 'test');
|
||||
// Reset the plugin data.
|
||||
views_fetch_plugin_data(NULL, NULL, TRUE);
|
||||
$this->strings = array('Master1', 'Apply1', 'Sort By1', 'Asc1', 'Desc1', 'more1', 'Reset1', 'Offset1', 'Master1', 'title1', 'Items per page1', 'fieldlabel1', 'filterlabel1');
|
||||
$this->enableViewsUi();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the unpack translation funtionality.
|
||||
*/
|
||||
public function testUnpackTranslatable() {
|
||||
$view = $this->view_unpack_translatable();
|
||||
$view->init_localization();
|
||||
|
||||
$this->assertEqual('views_plugin_localization_test', get_class($view->localization_plugin), 'Make sure that init_localization initializes the right translation plugin');
|
||||
|
||||
$view->export_locale_strings();
|
||||
|
||||
$expected_strings = $this->strings;
|
||||
$result_strings = $view->localization_plugin->get_export_strings();
|
||||
$this->assertEqual(sort($expected_strings), sort($result_strings), 'Make sure that the localization plugin got every translatable string.');
|
||||
}
|
||||
|
||||
public function testUi() {
|
||||
// Make sure that the string is not translated in the UI.
|
||||
$view = $this->view_unpack_translatable();
|
||||
$view->save();
|
||||
views_invalidate_cache();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
|
||||
$this->drupalLogin($admin_user);
|
||||
|
||||
$this->drupalGet("admin/structure/views/view/$view->name/edit");
|
||||
$this->assertNoText('-translated', 'Make sure that no strings get translated in the UI.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that the translations get into the loaded view.
|
||||
*/
|
||||
public function testTranslation() {
|
||||
$view = $this->view_unpack_translatable();
|
||||
$view->set_display('default');
|
||||
$this->executeView($view);
|
||||
|
||||
$expected_strings = array();
|
||||
foreach ($this->strings as $string) {
|
||||
$expected_strings[] = $string .= '-translated';
|
||||
}
|
||||
$this->assertEqual(sort($expected_strings), sort($view->localization_plugin->translated_strings), 'Make sure that every string got loaded translated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that the different things have the right translation keys.
|
||||
*/
|
||||
public function testTranslationKey() {
|
||||
$view = $this->view_unpack_translatable();
|
||||
$view->editing = TRUE;
|
||||
$view->init_display();
|
||||
|
||||
// Don't run translation. We just want to get the right keys.
|
||||
|
||||
foreach ($view->display as $display_id => $display) {
|
||||
$translatables = array();
|
||||
$display->handler->unpack_translatables($translatables);
|
||||
|
||||
$this->string_keys = array(
|
||||
'Master1' => array('title'),
|
||||
'Apply1' => array('exposed_form', 'submit_button'),
|
||||
'Sort By1' => array('exposed_form', 'exposed_sorts_label'),
|
||||
'Asc1' => array('exposed_form', 'sort_asc_label'),
|
||||
'Desc1' => array('exposed_form', 'sort_desc_label'),
|
||||
'more1' => array('use_more_text'),
|
||||
'Reset1' => array('exposed_form', 'reset_button_label'),
|
||||
'Offset1' => array('pager', 'expose', 'offset_label'),
|
||||
'Master1' => array('title'),
|
||||
'title1' => array('title'),
|
||||
'Tag first1' => array('pager', 'tags', 'first'),
|
||||
'Tag prev1' => array('pager', 'tags', 'previous'),
|
||||
'Tag next1' => array('pager', 'tags', 'next'),
|
||||
'Tag last1' => array('pager', 'tags', 'last'),
|
||||
'Items per page1' => array('pager', 'expose', 'items_per_page_label'),
|
||||
'fieldlabel1' => array('field', 'node', 'nid', 'label'),
|
||||
'filterlabel1' => array('filter', 'node', 'nid', 'expose', 'label'),
|
||||
'- All -' => array('pager', 'expose', 'items_per_page_options_all_label'),
|
||||
);
|
||||
foreach ($translatables as $translatable) {
|
||||
$this->assertEqual($translatable['keys'], $this->string_keys[$translatable['value']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function view_unpack_translatable() {
|
||||
$view = new view;
|
||||
$view->name = 'view_unpack_translatable';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node';
|
||||
$view->api_version = '3.0-alpha1';
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Master */
|
||||
$handler = $view->new_display('default', 'Master1', 'default');
|
||||
$handler->display->display_options['title'] = 'title1';
|
||||
$handler->display->display_options['use_more_text'] = 'more1';
|
||||
$handler->display->display_options['access']['type'] = 'none';
|
||||
$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['exposed_form']['options']['submit_button'] = 'Apply1';
|
||||
$handler->display->display_options['exposed_form']['options']['reset_button'] = TRUE;
|
||||
$handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Reset1';
|
||||
$handler->display->display_options['exposed_form']['options']['exposed_sorts_label'] = 'Sort By1';
|
||||
$handler->display->display_options['exposed_form']['options']['sort_asc_label'] = 'Asc1';
|
||||
$handler->display->display_options['exposed_form']['options']['sort_desc_label'] = 'Desc1';
|
||||
$handler->display->display_options['pager']['type'] = 'full';
|
||||
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
|
||||
$handler->display->display_options['pager']['options']['offset'] = '0';
|
||||
$handler->display->display_options['pager']['options']['id'] = '0';
|
||||
$handler->display->display_options['pager']['options']['quantity'] = '9';
|
||||
$handler->display->display_options['pager']['options']['tags']['first'] = 'Tag first1';
|
||||
$handler->display->display_options['pager']['options']['tags']['previous'] = 'Tag prev1';
|
||||
$handler->display->display_options['pager']['options']['tags']['next'] = 'Tag next1';
|
||||
$handler->display->display_options['pager']['options']['tags']['last'] = 'Tag last1';
|
||||
$handler->display->display_options['pager']['options']['expose']['items_per_page'] = TRUE;
|
||||
$handler->display->display_options['pager']['options']['expose']['items_per_page_label'] = 'Items per page1';
|
||||
$handler->display->display_options['pager']['options']['expose']['offset'] = TRUE;
|
||||
$handler->display->display_options['pager']['options']['expose']['offset_label'] = 'Offset1';
|
||||
$handler->display->display_options['style_plugin'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Field: Content: Nid */
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['label'] = 'fieldlabel1';
|
||||
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
|
||||
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
|
||||
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
|
||||
$handler->display->display_options['fields']['nid']['link_to_node'] = 0;
|
||||
/* Filter: 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'] = 'filterlabel1';
|
||||
$handler->display->display_options['filters']['nid']['expose']['identifier'] = 'nid';
|
||||
$handler->display->display_options['filters']['nid']['expose']['multiple'] = 1;
|
||||
$handler->display->display_options['filters']['nid']['expose']['reduce'] = 0;
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
973
sites/all/modules/views/tests/views_ui.test
Normal file
973
sites/all/modules/views/tests/views_ui.test
Normal file
@@ -0,0 +1,973 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests Views UI Wizard.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Views UI wizard tests.
|
||||
*/
|
||||
class ViewsUIWizardHelper extends DrupalWebTestCase {
|
||||
function setUp() {
|
||||
// Enable views_ui.
|
||||
parent::setUp('views_ui');
|
||||
|
||||
// Create and log in a user with administer views permission.
|
||||
$views_admin = $this->drupalCreateUser(array('administer views', 'administer blocks', 'bypass node access', 'access user profiles', 'view revisions'));
|
||||
$this->drupalLogin($views_admin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating views with the wizard and viewing them on the listing page.
|
||||
*/
|
||||
class ViewsUIWizardBasicTestCase extends ViewsUIWizardHelper {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views UI wizard basic functionality',
|
||||
'description' => 'Test creating basic views with the wizard and viewing them on the listing page.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
function testViewsWizardAndListing() {
|
||||
// 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();
|
||||
$view1['human_name'] = $this->randomName(16);
|
||||
$view1['name'] = strtolower($this->randomName(16));
|
||||
$view1['description'] = $this->randomName(16);
|
||||
$view1['page[create]'] = FALSE;
|
||||
$this->drupalPost('admin/structure/views/add', $view1, t('Save & exit'));
|
||||
$this->assertText(t('Your view was saved. You may edit it from the list below.'));
|
||||
$this->assertText($view1['human_name']);
|
||||
$this->assertText($view1['description']);
|
||||
foreach(array('delete', 'clone', 'edit') as $operation) {
|
||||
$this->assertLinkByHref(url('admin/structure/views/view/' . $view1['name'] . '/' . $operation));
|
||||
}
|
||||
|
||||
// This view should not have a block.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->assertNoText('View: ' . $view1['human_name']);
|
||||
|
||||
// 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();
|
||||
$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->drupalPost('admin/structure/views/add', $view2, t('Save & exit'));
|
||||
|
||||
// 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.
|
||||
$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)));
|
||||
$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->drupalGet('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->drupalGet('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->drupalPost('admin/structure/views/add', $view3, t('Save & exit'));
|
||||
|
||||
// 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->drupalGet('admin/structure/views');
|
||||
$this->assertText($view3['human_name']);
|
||||
$this->assertText($view3['description']);
|
||||
$this->assertLinkByHref(url($view3['page[path]']));
|
||||
|
||||
// Put the block into the first sidebar region.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->assertText('View: ' . $view3['human_name']);
|
||||
$edit = array();
|
||||
$edit["blocks[views_{$view3['name']}-block][region]"] = 'sidebar_first';
|
||||
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
||||
|
||||
// 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');
|
||||
$this->assertText($node1->title);
|
||||
$this->assertNoText($node2->title);
|
||||
|
||||
// Check if the export screen works.
|
||||
$this->drupalGet('admin/structure/views/view/' . $view3['name'] . '/export');
|
||||
$this->assertRaw('$view = new view();');
|
||||
$this->assertRaw($view3['human_name']);
|
||||
$this->assertRaw($view3['description']);
|
||||
|
||||
// Make sure the listing page doesn't show disabled default views.
|
||||
$this->assertNoText('tracker', t('Default tracker view does not show on the listing page.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests enabling, disabling, and reverting default views via the listing page.
|
||||
*/
|
||||
class ViewsUIWizardDefaultViewsTestCase extends ViewsUIWizardHelper {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views UI default views functionality',
|
||||
'description' => 'Test enabling, disabling, and reverting default views via the listing page.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests default views.
|
||||
*/
|
||||
function testDefaultViews() {
|
||||
// Make sure the front page view starts off as disabled (does not appear on
|
||||
// the listing page).
|
||||
$edit_href = 'admin/structure/views/view/frontpage/edit';
|
||||
$this->drupalGet('admin/structure/views');
|
||||
// TODO: Disabled default views do now appear on the front page. Test this
|
||||
// behavior with templates instead.
|
||||
// $this->assertNoLinkByHref($edit_href);
|
||||
|
||||
// Enable the front page view, and make sure it is now visible on the main
|
||||
// listing page.
|
||||
$this->drupalGet('admin/structure/views/templates');
|
||||
$this->clickViewsOperationLink(t('Enable'), '/frontpage/');
|
||||
$this->assertUrl('admin/structure/views');
|
||||
$this->assertLinkByHref($edit_href);
|
||||
|
||||
// It should not be possible to revert the view yet.
|
||||
$this->assertNoLink(t('Revert'));
|
||||
$revert_href = 'admin/structure/views/view/frontpage/revert';
|
||||
$this->assertNoLinkByHref($revert_href);
|
||||
|
||||
// Edit the view and change the title. Make sure that the new title is
|
||||
// displayed.
|
||||
$new_title = $this->randomName(16);
|
||||
$edit = array('title' => $new_title);
|
||||
$this->drupalPost('admin/structure/views/nojs/display/frontpage/page/title', $edit, t('Apply'));
|
||||
$this->drupalPost('admin/structure/views/view/frontpage/edit/page', array(), t('Save'));
|
||||
$this->drupalGet('frontpage');
|
||||
$this->assertText($new_title);
|
||||
|
||||
// It should now be possible to revert the view. Do that, and make sure the
|
||||
// view title we added above no longer is displayed.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->assertLink(t('Revert'));
|
||||
$this->assertLinkByHref($revert_href);
|
||||
$this->drupalPost($revert_href, array(), t('Revert'));
|
||||
$this->drupalGet('frontpage');
|
||||
$this->assertNoText($new_title);
|
||||
|
||||
// Now disable the view, and make sure it stops appearing on the main view
|
||||
// listing page but instead goes back to displaying on the disabled views
|
||||
// listing page.
|
||||
// TODO: Test this behavior with templates instead.
|
||||
$this->drupalGet('admin/structure/views');
|
||||
$this->clickViewsOperationLink(t('Disable'), '/frontpage/');
|
||||
// $this->assertUrl('admin/structure/views');
|
||||
// $this->assertNoLinkByHref($edit_href);
|
||||
// The easiest way to verify it appears on the disabled views listing page
|
||||
// is to try to click the "enable" link from there again.
|
||||
$this->drupalGet('admin/structure/views/templates');
|
||||
$this->clickViewsOperationLink(t('Enable'), '/frontpage/');
|
||||
$this->assertUrl('admin/structure/views');
|
||||
$this->assertLinkByHref($edit_href);
|
||||
}
|
||||
|
||||
/**
|
||||
* Click a link to perform an operation on a view.
|
||||
*
|
||||
* In general, we expect lots of links titled "enable" or "disable" on the
|
||||
* various views listing pages, and they might have tokens in them. So we
|
||||
* need special code to find the correct one to click.
|
||||
*
|
||||
* @param $label
|
||||
* Text between the anchor tags of the desired link.
|
||||
* @param $unique_href_part
|
||||
* A unique string that is expected to occur within the href of the desired
|
||||
* link. For example, if the link URL is expected to look like
|
||||
* "admin/structure/views/view/frontpage/...", then "/frontpage/" could be
|
||||
* passed as the expected unique string.
|
||||
*
|
||||
* @return
|
||||
* The page content that results from clicking on the link, or FALSE on
|
||||
* failure. Failure also results in a failed assertion.
|
||||
*/
|
||||
function clickViewsOperationLink($label, $unique_href_part) {
|
||||
$links = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label));
|
||||
foreach ($links as $link_index => $link) {
|
||||
$position = strpos($link['href'], $unique_href_part);
|
||||
if ($position !== FALSE) {
|
||||
$index = $link_index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertTrue(isset($index), t('Link to "@label" containing @part found.', array('@label' => $label, '@part' => $unique_href_part)));
|
||||
if (isset($index)) {
|
||||
return $this->clickLink($label, $index);
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to create views filtered by taxonomy.
|
||||
*/
|
||||
class ViewsUIWizardTaggedWithTestCase extends ViewsUIWizardHelper {
|
||||
protected $node_type_with_tags;
|
||||
protected $node_type_without_tags;
|
||||
protected $tag_vocabulary;
|
||||
protected $tag_field;
|
||||
protected $tag_instance;
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views UI wizard taxonomy functionality',
|
||||
'description' => 'Test the ability of the views wizard to create views filtered by taxonomy.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create two content types. One will have an autocomplete tagging field,
|
||||
// and one won't.
|
||||
$this->node_type_with_tags = $this->drupalCreateContentType();
|
||||
$this->node_type_without_tags = $this->drupalCreateContentType();
|
||||
|
||||
// Create the vocabulary for the tag field.
|
||||
$this->tag_vocabulary = new stdClass();
|
||||
$this->tag_vocabulary->name = 'Views testing tags';
|
||||
$this->tag_vocabulary->machine_name = 'views_testing_tags';
|
||||
taxonomy_vocabulary_save($this->tag_vocabulary);
|
||||
|
||||
// Create the tag field itself.
|
||||
$this->tag_field = array(
|
||||
'field_name' => 'field_views_testing_tags',
|
||||
'type' => 'taxonomy_term_reference',
|
||||
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
||||
'settings' => array(
|
||||
'allowed_values' => array(
|
||||
array(
|
||||
'vocabulary' => $this->tag_vocabulary->machine_name,
|
||||
'parent' => 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
field_create_field($this->tag_field);
|
||||
|
||||
// Create an instance of the tag field on one of the content types, and
|
||||
// configure it to display an autocomplete widget.
|
||||
$this->tag_instance = array(
|
||||
'field_name' => 'field_views_testing_tags',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $this->node_type_with_tags->type,
|
||||
'widget' => array(
|
||||
'type' => 'taxonomy_autocomplete',
|
||||
),
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'type' => 'taxonomy_term_reference_link',
|
||||
'weight' => 10,
|
||||
),
|
||||
'teaser' => array(
|
||||
'type' => 'taxonomy_term_reference_link',
|
||||
'weight' => 10,
|
||||
),
|
||||
),
|
||||
);
|
||||
field_create_instance($this->tag_instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the "tagged with" functionality.
|
||||
*/
|
||||
function testTaggedWith() {
|
||||
// In this test we will only create nodes that have an instance of the tag
|
||||
// field.
|
||||
$node_add_path = 'node/add/' . $this->node_type_with_tags->type;
|
||||
|
||||
// Create three nodes, with different tags.
|
||||
$tag_field = $this->tag_field['field_name'] . '[' . LANGUAGE_NONE . ']';
|
||||
$edit = array();
|
||||
$edit['title'] = $node_tag1_title = $this->randomName();
|
||||
$edit[$tag_field] = 'tag1';
|
||||
$this->drupalPost($node_add_path, $edit, t('Save'));
|
||||
$edit = array();
|
||||
$edit['title'] = $node_tag1_tag2_title = $this->randomName();
|
||||
$edit[$tag_field] = 'tag1, tag2';
|
||||
$this->drupalPost($node_add_path, $edit, t('Save'));
|
||||
$edit = array();
|
||||
$edit['title'] = $node_no_tags_title = $this->randomName();
|
||||
$this->drupalPost($node_add_path, $edit, t('Save'));
|
||||
|
||||
// Create a view that filters by taxonomy term "tag1". It should show only
|
||||
// the two nodes from above that are tagged with "tag1".
|
||||
$view1 = array();
|
||||
// First select the node type and update the form so the correct tag field
|
||||
// is used.
|
||||
$view1['show[type]'] = $this->node_type_with_tags->type;
|
||||
$this->drupalPost('admin/structure/views/add', $view1, t('Update "of type" choice'));
|
||||
// Now resubmit the entire form to the same URL.
|
||||
$view1['human_name'] = $this->randomName(16);
|
||||
$view1['name'] = strtolower($this->randomName(16));
|
||||
$view1['description'] = $this->randomName(16);
|
||||
$view1['show[tagged_with]'] = 'tag1';
|
||||
$view1['page[create]'] = 1;
|
||||
$view1['page[title]'] = $this->randomName(16);
|
||||
$view1['page[path]'] = $this->randomName(16);
|
||||
$this->drupalPost(NULL, $view1, t('Save & exit'));
|
||||
// Visit the page and check that the nodes we expect are present and the
|
||||
// ones we don't expect are absent.
|
||||
$this->drupalGet($view1['page[path]']);
|
||||
$this->assertText($node_tag1_title);
|
||||
$this->assertText($node_tag1_tag2_title);
|
||||
$this->assertNoText($node_no_tags_title);
|
||||
|
||||
// Create a view that filters by taxonomy term "tag2". It should show only
|
||||
// the one node from above that is tagged with "tag2".
|
||||
$view2 = array();
|
||||
$view2['show[type]'] = $this->node_type_with_tags->type;
|
||||
$this->drupalPost('admin/structure/views/add', $view2, t('Update "of type" choice'));
|
||||
$view2['human_name'] = $this->randomName(16);
|
||||
$view2['name'] = strtolower($this->randomName(16));
|
||||
$view2['description'] = $this->randomName(16);
|
||||
$view2['show[tagged_with]'] = 'tag2';
|
||||
$view2['page[create]'] = 1;
|
||||
$view2['page[title]'] = $this->randomName(16);
|
||||
$view2['page[path]'] = $this->randomName(16);
|
||||
$this->drupalPost(NULL, $view2, t('Save & exit'));
|
||||
$this->drupalGet($view2['page[path]']);
|
||||
$this->assertNoText($node_tag1_title);
|
||||
$this->assertText($node_tag1_tag2_title);
|
||||
$this->assertNoText($node_no_tags_title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the "tagged with" form element only shows for node types that support it.
|
||||
*/
|
||||
function testTaggedWithByNodeType() {
|
||||
// The tagging field is associated with one of our node types only. So the
|
||||
// "tagged with" form element on the view wizard should appear on the form
|
||||
// by default (when the wizard is configured to display all content) and
|
||||
// also when the node type that has the tagging field is selected, but not
|
||||
// when the node type that doesn't have the tagging field is selected.
|
||||
$tags_xpath = '//input[@name="show[tagged_with]"]';
|
||||
$this->drupalGet('admin/structure/views/add');
|
||||
$this->assertFieldByXpath($tags_xpath);
|
||||
$view['show[type]'] = $this->node_type_with_tags->type;
|
||||
$this->drupalPost('admin/structure/views/add', $view, t('Update "of type" choice'));
|
||||
$this->assertFieldByXpath($tags_xpath);
|
||||
$view['show[type]'] = $this->node_type_without_tags->type;
|
||||
$this->drupalPost(NULL, $view, t('Update "of type" choice'));
|
||||
$this->assertNoFieldByXpath($tags_xpath);
|
||||
|
||||
// If we add an instance of the tagging field to the second node type, the
|
||||
// "tagged with" form element should not appear for it too.
|
||||
$instance = $this->tag_instance;
|
||||
$instance['bundle'] = $this->node_type_without_tags->type;
|
||||
field_create_instance($instance);
|
||||
$view['show[type]'] = $this->node_type_with_tags->type;
|
||||
$this->drupalPost('admin/structure/views/add', $view, t('Update "of type" choice'));
|
||||
$this->assertFieldByXpath($tags_xpath);
|
||||
$view['show[type]'] = $this->node_type_without_tags->type;
|
||||
$this->drupalPost(NULL, $view, t('Update "of type" choice'));
|
||||
$this->assertFieldByXpath($tags_xpath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to create views with sorts.
|
||||
*/
|
||||
class ViewsUIWizardSortingTestCase extends ViewsUIWizardHelper {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views UI wizard sorting functionality',
|
||||
'description' => 'Test the ability of the views wizard to create views with sorts.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the sorting functionality.
|
||||
*/
|
||||
function testSorting() {
|
||||
// Create nodes, each with a different creation time so that we can do a
|
||||
// meaningful sort.
|
||||
$node1 = $this->drupalCreateNode(array('created' => REQUEST_TIME));
|
||||
$node2 = $this->drupalCreateNode(array('created' => REQUEST_TIME + 1));
|
||||
$node3 = $this->drupalCreateNode(array('created' => REQUEST_TIME + 2));
|
||||
|
||||
// Create a view that sorts oldest first.
|
||||
$view1 = array();
|
||||
$view1['human_name'] = $this->randomName(16);
|
||||
$view1['name'] = strtolower($this->randomName(16));
|
||||
$view1['description'] = $this->randomName(16);
|
||||
$view1['show[sort]'] = 'created:ASC';
|
||||
$view1['page[create]'] = 1;
|
||||
$view1['page[title]'] = $this->randomName(16);
|
||||
$view1['page[path]'] = $this->randomName(16);
|
||||
$this->drupalPost('admin/structure/views/add', $view1, t('Save & exit'));
|
||||
|
||||
// Make sure the view shows the nodes in the expected order.
|
||||
$this->assertUrl($view1['page[path]']);
|
||||
$this->assertText($view1['page[title]']);
|
||||
$content = $this->drupalGetContent();
|
||||
$this->assertText($node1->title);
|
||||
$this->assertText($node2->title);
|
||||
$this->assertText($node3->title);
|
||||
$pos1 = strpos($content, $node1->title);
|
||||
$pos2 = strpos($content, $node2->title);
|
||||
$pos3 = strpos($content, $node3->title);
|
||||
$this->assertTrue($pos1 < $pos2 && $pos2 < $pos3, t('The nodes appear in the expected order in a view that sorts by oldest first.'));
|
||||
|
||||
// Create a view that sorts newest first.
|
||||
$view2 = array();
|
||||
$view2['human_name'] = $this->randomName(16);
|
||||
$view2['name'] = strtolower($this->randomName(16));
|
||||
$view2['description'] = $this->randomName(16);
|
||||
$view2['show[sort]'] = 'created:DESC';
|
||||
$view2['page[create]'] = 1;
|
||||
$view2['page[title]'] = $this->randomName(16);
|
||||
$view2['page[path]'] = $this->randomName(16);
|
||||
$this->drupalPost('admin/structure/views/add', $view2, t('Save & exit'));
|
||||
|
||||
// Make sure the view shows the nodes in the expected order.
|
||||
$this->assertUrl($view2['page[path]']);
|
||||
$this->assertText($view2['page[title]']);
|
||||
$content = $this->drupalGetContent();
|
||||
$this->assertText($node3->title);
|
||||
$this->assertText($node2->title);
|
||||
$this->assertText($node1->title);
|
||||
$pos3 = strpos($content, $node3->title);
|
||||
$pos2 = strpos($content, $node2->title);
|
||||
$pos1 = strpos($content, $node1->title);
|
||||
$this->assertTrue($pos3 < $pos2 && $pos2 < $pos1, t('The nodes appear in the expected order in a view that sorts by newest first.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to specify the number of items per page.
|
||||
*/
|
||||
class ViewsUIWizardItemsPerPageTestCase extends ViewsUIWizardHelper {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views UI wizard items per page functionality',
|
||||
'description' => 'Test the ability of the views wizard to specify the number of items per page.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the number of items per page.
|
||||
*/
|
||||
function testItemsPerPage() {
|
||||
// Create articles, each with a different creation time so that we can do a
|
||||
// meaningful sort.
|
||||
$node1 = $this->drupalCreateNode(array('type' => 'article', 'created' => REQUEST_TIME));
|
||||
$node2 = $this->drupalCreateNode(array('type' => 'article', 'created' => REQUEST_TIME + 1));
|
||||
$node3 = $this->drupalCreateNode(array('type' => 'article', 'created' => REQUEST_TIME + 2));
|
||||
$node4 = $this->drupalCreateNode(array('type' => 'article', 'created' => REQUEST_TIME + 3));
|
||||
$node5 = $this->drupalCreateNode(array('type' => 'article', 'created' => REQUEST_TIME + 4));
|
||||
|
||||
// Create a page. This should never appear in the view created below.
|
||||
$page_node = $this->drupalCreateNode(array('type' => 'page', 'created' => REQUEST_TIME + 2));
|
||||
|
||||
// Create a view that sorts newest first, and shows 4 items in the page and
|
||||
// 3 in the block.
|
||||
$view = array();
|
||||
$view['human_name'] = $this->randomName(16);
|
||||
$view['name'] = strtolower($this->randomName(16));
|
||||
$view['description'] = $this->randomName(16);
|
||||
$view['show[wizard_key]'] = 'node';
|
||||
$view['show[type]'] = 'article';
|
||||
$view['show[sort]'] = 'created:DESC';
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[title]'] = $this->randomName(16);
|
||||
$view['page[path]'] = $this->randomName(16);
|
||||
$view['page[items_per_page]'] = 4;
|
||||
$view['block[create]'] = 1;
|
||||
$view['block[title]'] = $this->randomName(16);
|
||||
$view['block[items_per_page]'] = 3;
|
||||
$this->drupalPost('admin/structure/views/add', $view, t('Save & exit'));
|
||||
|
||||
// Make sure the page display shows the nodes we expect, and that they
|
||||
// appear in the expected order.
|
||||
$this->assertUrl($view['page[path]']);
|
||||
$this->assertText($view['page[title]']);
|
||||
$content = $this->drupalGetContent();
|
||||
$this->assertText($node5->title);
|
||||
$this->assertText($node4->title);
|
||||
$this->assertText($node3->title);
|
||||
$this->assertText($node2->title);
|
||||
$this->assertNoText($node1->title);
|
||||
$this->assertNoText($page_node->title);
|
||||
$pos5 = strpos($content, $node5->title);
|
||||
$pos4 = strpos($content, $node4->title);
|
||||
$pos3 = strpos($content, $node3->title);
|
||||
$pos2 = strpos($content, $node2->title);
|
||||
$this->assertTrue($pos5 < $pos4 && $pos4 < $pos3 && $pos3 < $pos2, t('The nodes appear in the expected order in the page display.'));
|
||||
|
||||
// Put the block into the first sidebar region, visit a page that displays
|
||||
// the block, and check that the nodes we expect appear in the correct
|
||||
// order.
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$this->assertText('View: ' . $view['human_name']);
|
||||
$edit = array();
|
||||
$edit["blocks[views_{$view['name']}-block][region]"] = 'sidebar_first';
|
||||
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
||||
$this->drupalGet('user');
|
||||
$content = $this->drupalGetContent();
|
||||
$this->assertText($node5->title);
|
||||
$this->assertText($node4->title);
|
||||
$this->assertText($node3->title);
|
||||
$this->assertNoText($node2->title);
|
||||
$this->assertNoText($node1->title);
|
||||
$this->assertNoText($page_node->title);
|
||||
$pos5 = strpos($content, $node5->title);
|
||||
$pos4 = strpos($content, $node4->title);
|
||||
$pos3 = strpos($content, $node3->title);
|
||||
$this->assertTrue($pos5 < $pos4 && $pos4 < $pos3, t('The nodes appear in the expected order in the block display.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to put views in a menu.
|
||||
*/
|
||||
class ViewsUIWizardMenuTestCase extends ViewsUIWizardHelper {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views UI wizard menu functionality',
|
||||
'description' => 'Test the ability of the views wizard to put views in a menu.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the menu functionality.
|
||||
*/
|
||||
function testMenus() {
|
||||
// Create a view with a page display and a menu link in the Main Menu.
|
||||
$view = array();
|
||||
$view['human_name'] = $this->randomName(16);
|
||||
$view['name'] = strtolower($this->randomName(16));
|
||||
$view['description'] = $this->randomName(16);
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[title]'] = $this->randomName(16);
|
||||
$view['page[path]'] = $this->randomName(16);
|
||||
$view['page[link]'] = 1;
|
||||
$view['page[link_properties][menu_name]'] = 'main-menu';
|
||||
$view['page[link_properties][title]'] = $this->randomName(16);
|
||||
$this->drupalPost('admin/structure/views/add', $view, t('Save & exit'));
|
||||
|
||||
// Make sure there is a link to the view from the front page (where we
|
||||
// expect the main menu to display).
|
||||
$this->drupalGet('');
|
||||
$this->assertLink($view['page[link_properties][title]']);
|
||||
$this->assertLinkByHref(url($view['page[path]']));
|
||||
|
||||
// Make sure the link is associated with the main menu.
|
||||
$links = menu_load_links('main-menu');
|
||||
$found = FALSE;
|
||||
foreach ($links as $link) {
|
||||
if ($link['link_path'] == $view['page[path]']) {
|
||||
$found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertTrue($found, t('Found a link to %path in the main menu', array('%path' => $view['page[path]'])));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to create views with a jump menu style plugin.
|
||||
*/
|
||||
class ViewsUIWizardJumpMenuTestCase extends ViewsUIWizardHelper {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views UI wizard jump menu functionality',
|
||||
'description' => 'Test the ability of the views wizard to create views with a jump menu style plugin.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the jump menu style plugin.
|
||||
*/
|
||||
function testJumpMenus() {
|
||||
// We'll run this test for several different base tables that appear in the
|
||||
// wizard.
|
||||
$base_table_methods = array(
|
||||
'node' => 'createNodeAndGetPath',
|
||||
'users' => 'createUserAndGetPath',
|
||||
'comment' => 'createCommentAndGetPath',
|
||||
'taxonomy_term' => 'createTaxonomyTermAndGetPath',
|
||||
'file_managed' => 'createFileAndGetPath',
|
||||
'node_revision' => 'createNodeRevisionAndGetPath',
|
||||
);
|
||||
|
||||
foreach ($base_table_methods as $base_table => $method) {
|
||||
// For each base table, find the path that we expect the jump menu to
|
||||
// redirect us to.
|
||||
$path_info = $this->{$method}();
|
||||
if (is_array($path_info)) {
|
||||
$path = $path_info['path'];
|
||||
$options = isset($path_info['options']) ? $path_info['options'] : array();
|
||||
}
|
||||
else {
|
||||
$path = $path_info;
|
||||
$options = array();
|
||||
}
|
||||
|
||||
// Create a page view for the specified base table that uses the jump
|
||||
// menu style plugin.
|
||||
$view = array();
|
||||
$view['human_name'] = $this->randomName(16);
|
||||
$view['name'] = strtolower($this->randomName(16));
|
||||
$view['description'] = $this->randomName(16);
|
||||
$view['show[wizard_key]'] = $base_table;
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[title]'] = $this->randomName(16);
|
||||
$view['page[path]'] = $this->randomName(16);
|
||||
$view['page[style][style_plugin]'] = 'jump_menu';
|
||||
$view['page[style][row_plugin]'] = 'fields';
|
||||
$this->drupalPost('admin/structure/views/add', $view, t('Save & exit'));
|
||||
|
||||
// Submit the jump menu form, and check that we are redirected to the
|
||||
// expected URL.
|
||||
|
||||
$edit = array();
|
||||
$edit['jump'] = url($path, $options);
|
||||
|
||||
// The urls are built with :: to be able to have a unique path all the time,
|
||||
// so try to find out the real path of $edit.
|
||||
$view_object = views_get_view($view['name']);
|
||||
$view_object->preview('page');
|
||||
$form = $view_object->style_plugin->render();
|
||||
$jump_options = $form['jump']['#options'];
|
||||
foreach ($jump_options as $key => $title) {
|
||||
if (strpos($key, $edit['jump']) !== FALSE) {
|
||||
$edit['jump'] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$this->drupalPost($view['page[path]'], $edit, t('Go'));
|
||||
$this->assertResponse(200);
|
||||
$this->assertUrl($path, $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create a node and return its expected path.
|
||||
*/
|
||||
function createNodeAndGetPath() {
|
||||
$node = $this->drupalCreateNode();
|
||||
return entity_uri('node', $node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create a user and return its expected path.
|
||||
*/
|
||||
function createUserAndGetPath() {
|
||||
$account = $this->drupalCreateUser();
|
||||
return entity_uri('user', $account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create a comment and return its expected path.
|
||||
*/
|
||||
function createCommentAndGetPath() {
|
||||
$node = $this->drupalCreateNode();
|
||||
$comment = (object) array(
|
||||
'cid' => NULL,
|
||||
'nid' => $node->nid,
|
||||
'pid' => 0,
|
||||
'uid' => 0,
|
||||
'status' => COMMENT_PUBLISHED,
|
||||
'subject' => $this->randomName(),
|
||||
'language' => LANGUAGE_NONE,
|
||||
'comment_body' => array(LANGUAGE_NONE => array($this->randomName())),
|
||||
);
|
||||
comment_save($comment);
|
||||
return entity_uri('comment', $comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create a taxonomy term and return its expected path.
|
||||
*/
|
||||
function createTaxonomyTermAndGetPath() {
|
||||
$vocabulary = new stdClass();
|
||||
$vocabulary->name = $this->randomName();
|
||||
$vocabulary->machine_name = drupal_strtolower($this->randomName());
|
||||
taxonomy_vocabulary_save($vocabulary);
|
||||
|
||||
$term = new stdClass();
|
||||
$term->name = $this->randomName();
|
||||
$term->vid = $vocabulary->vid;
|
||||
taxonomy_term_save($term);
|
||||
|
||||
return entity_uri('taxonomy_term', $term);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create a file and return its expected path.
|
||||
*/
|
||||
function createFileAndGetPath() {
|
||||
$file = (object) array(
|
||||
'uid' => 1,
|
||||
'filename' => 'views-ui-jump-menu-test.txt',
|
||||
'uri' => 'public://views-ui-jump-menu-test.txt',
|
||||
'filemime' => 'text/plain',
|
||||
'timestamp' => 1,
|
||||
'status' => FILE_STATUS_PERMANENT,
|
||||
);
|
||||
file_put_contents($file->uri, 'test content');
|
||||
$file = file_save($file);
|
||||
return file_create_url($file->uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to create a node revision and return its expected path.
|
||||
*/
|
||||
function createNodeRevisionAndGetPath() {
|
||||
// The node needs at least two revisions in order for Drupal to allow
|
||||
// access to the revision path.
|
||||
$settings = array('revision' => TRUE);
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
$node->vid = NULL;
|
||||
node_save($node);
|
||||
return 'node/' . $node->nid . '/revisions/' . $node->vid . '/view';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that displays can be correctly overridden via the user interface.
|
||||
*/
|
||||
class ViewsUIWizardOverrideDisplaysTestCase extends ViewsUIWizardHelper {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views UI overridden displays',
|
||||
'description' => 'Test that displays can be correctly overridden via the user interface.',
|
||||
'group' => 'Views UI',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that displays can be overridden via the UI.
|
||||
*/
|
||||
function testOverrideDisplays() {
|
||||
// Create a basic view that shows all content, with a page and a block
|
||||
// display.
|
||||
$view['human_name'] = $this->randomName(16);
|
||||
$view['name'] = strtolower($this->randomName(16));
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[path]'] = $this->randomName(16);
|
||||
$view['block[create]'] = 1;
|
||||
$view_path = $view['page[path]'];
|
||||
$this->drupalPost('admin/structure/views/add', $view, t('Save & exit'));
|
||||
|
||||
// Configure its title. Since the page and block both started off with the
|
||||
// same (empty) title in the views wizard, we expect the wizard to have set
|
||||
// things up so that they both inherit from the default display, and we
|
||||
// therefore only need to change that to have it take effect for both.
|
||||
$edit = array();
|
||||
$edit['title'] = $original_title = $this->randomName(16);
|
||||
$edit['override[dropdown]'] = 'default';
|
||||
$this->drupalPost("admin/structure/views/nojs/display/{$view['name']}/page/title", $edit, t('Apply'));
|
||||
$this->drupalPost("admin/structure/views/view/{$view['name']}/edit/page", array(), t('Save'));
|
||||
|
||||
// Put the block into the first sidebar region, and make sure it will not
|
||||
// display on the view's page display (since we will be searching for the
|
||||
// presence/absence of the view's title in both the page and the block).
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$edit = array();
|
||||
$edit["blocks[views_{$view['name']}-block][region]"] = 'sidebar_first';
|
||||
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
||||
$edit = array();
|
||||
$edit['visibility'] = BLOCK_VISIBILITY_NOTLISTED;
|
||||
$edit['pages'] = $view_path;
|
||||
$this->drupalPost("admin/structure/block/manage/views/{$view['name']}-block/configure", $edit, t('Save block'));
|
||||
|
||||
// Add a node that will appear in the view, so that the block will actually
|
||||
// be displayed.
|
||||
$this->drupalCreateNode();
|
||||
|
||||
// Make sure the title appears in both the page and the block.
|
||||
$this->drupalGet($view_path);
|
||||
$this->assertText($original_title);
|
||||
$this->drupalGet('');
|
||||
$this->assertText($original_title);
|
||||
|
||||
// Change the title for the page display only, and make sure that is the
|
||||
// only one that is changed.
|
||||
$edit = array();
|
||||
$edit['title'] = $new_title = $this->randomName(16);
|
||||
$edit['override[dropdown]'] = 'page';
|
||||
$this->drupalPost("admin/structure/views/nojs/display/{$view['name']}/page/title", $edit, t('Apply'));
|
||||
$this->drupalPost("admin/structure/views/view/{$view['name']}/edit/page", array(), t('Save'));
|
||||
$this->drupalGet($view_path);
|
||||
$this->assertText($new_title);
|
||||
$this->assertNoText($original_title);
|
||||
$this->drupalGet('');
|
||||
$this->assertText($original_title);
|
||||
$this->assertNoText($new_title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the wizard correctly sets up default and overridden displays.
|
||||
*/
|
||||
function testWizardMixedDefaultOverriddenDisplays() {
|
||||
// Create a basic view with a page, block, and feed. Give the page and feed
|
||||
// identical titles, but give the block a different one, so we expect the
|
||||
// page and feed to inherit their titles from the default display, but the
|
||||
// block to override it.
|
||||
$view['human_name'] = $this->randomName(16);
|
||||
$view['name'] = strtolower($this->randomName(16));
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[title]'] = $this->randomName(16);
|
||||
$view['page[path]'] = $this->randomName(16);
|
||||
$view['page[feed]'] = 1;
|
||||
$view['page[feed_properties][path]'] = $this->randomName(16);
|
||||
$view['block[create]'] = 1;
|
||||
$view['block[title]'] = $this->randomName(16);
|
||||
$this->drupalPost('admin/structure/views/add', $view, t('Save & exit'));
|
||||
|
||||
// Put the block into the first sidebar region, and make sure it will not
|
||||
// display on the view's page display (since we will be searching for the
|
||||
// presence/absence of the view's title in both the page and the block).
|
||||
$this->drupalGet('admin/structure/block');
|
||||
$edit = array();
|
||||
$edit["blocks[views_{$view['name']}-block][region]"] = 'sidebar_first';
|
||||
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
|
||||
$edit = array();
|
||||
$edit['visibility'] = BLOCK_VISIBILITY_NOTLISTED;
|
||||
$edit['pages'] = $view['page[path]'];
|
||||
$this->drupalPost("admin/structure/block/manage/views/{$view['name']}-block/configure", $edit, t('Save block'));
|
||||
|
||||
// Add a node that will appear in the view, so that the block will actually
|
||||
// be displayed.
|
||||
$this->drupalCreateNode();
|
||||
|
||||
// Make sure that the feed, page and block all start off with the correct
|
||||
// titles.
|
||||
$this->drupalGet($view['page[path]']);
|
||||
$this->assertText($view['page[title]']);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
$this->drupalGet($view['page[feed_properties][path]']);
|
||||
$this->assertText($view['page[title]']);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
$this->drupalGet('');
|
||||
$this->assertText($view['block[title]']);
|
||||
$this->assertNoText($view['page[title]']);
|
||||
|
||||
// Edit the page and change the title. This should automatically change
|
||||
// the feed's title also, but not the block.
|
||||
$edit = array();
|
||||
$edit['title'] = $new_default_title = $this->randomName(16);
|
||||
$this->drupalPost("admin/structure/views/nojs/display/{$view['name']}/page/title", $edit, t('Apply'));
|
||||
$this->drupalPost("admin/structure/views/view/{$view['name']}/edit/page", array(), t('Save'));
|
||||
$this->drupalGet($view['page[path]']);
|
||||
$this->assertText($new_default_title);
|
||||
$this->assertNoText($view['page[title]']);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
$this->drupalGet($view['page[feed_properties][path]']);
|
||||
$this->assertText($new_default_title);
|
||||
$this->assertNoText($view['page[title]']);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
$this->drupalGet('');
|
||||
$this->assertText($view['block[title]']);
|
||||
$this->assertNoText($new_default_title);
|
||||
$this->assertNoText($view['page[title]']);
|
||||
|
||||
// Edit the block and change the title. This should automatically change
|
||||
// the block title only, and leave the defaults alone.
|
||||
$edit = array();
|
||||
$edit['title'] = $new_block_title = $this->randomName(16);
|
||||
$this->drupalPost("admin/structure/views/nojs/display/{$view['name']}/block/title", $edit, t('Apply'));
|
||||
$this->drupalPost("admin/structure/views/view/{$view['name']}/edit/block", array(), t('Save'));
|
||||
$this->drupalGet($view['page[path]']);
|
||||
$this->assertText($new_default_title);
|
||||
$this->assertNoText($new_block_title);
|
||||
$this->drupalGet($view['page[feed_properties][path]']);
|
||||
$this->assertText($new_default_title);
|
||||
$this->assertNoText($new_block_title);
|
||||
$this->drupalGet('');
|
||||
$this->assertText($new_block_title);
|
||||
$this->assertNoText($view['block[title]']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the revert to all displays select-option works as expected.
|
||||
*/
|
||||
function testRevertAllDisplays() {
|
||||
// Create a basic view with a page, block.
|
||||
// Because there is both a title on page and block we expect the title on
|
||||
// the block be overriden.
|
||||
$view['human_name'] = $this->randomName(16);
|
||||
$view['name'] = strtolower($this->randomName(16));
|
||||
$view['page[create]'] = 1;
|
||||
$view['page[title]'] = $this->randomName(16);
|
||||
$view['page[path]'] = $this->randomName(16);
|
||||
$view['block[create]'] = 1;
|
||||
$view['block[title]'] = $this->randomName(16);
|
||||
$this->drupalPost('admin/structure/views/add', $view, t('Continue & edit'));
|
||||
|
||||
// Revert the title of the block back to the default ones, but submit some
|
||||
// new values to be sure that the new value is not stored.
|
||||
$edit = array();
|
||||
$edit['title'] = $new_block_title = $this->randomName();
|
||||
$edit['override[dropdown]'] = 'default_revert';
|
||||
|
||||
$this->drupalPost("admin/structure/views/nojs/display/{$view['name']}/block/title", $edit, t('Apply'));
|
||||
$this->drupalPost("admin/structure/views/view/{$view['name']}/edit/block", array(), t('Save'));
|
||||
$this->assertText($view['page[title]']);
|
||||
}
|
||||
}
|
277
sites/all/modules/views/tests/views_upgrade.test
Normal file
277
sites/all/modules/views/tests/views_upgrade.test
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsUpgradeTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Try to test the upgrade path of all conversions.
|
||||
*
|
||||
* You can find all conversions by searching for "moved to".
|
||||
*/
|
||||
class ViewsUpgradeTestCase extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Views Upgrade test',
|
||||
'description' => 'Try to test the upgrade path of modules which were changed.',
|
||||
'group' => 'Views',
|
||||
);
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
// // To import a view the user needs use PHP for settings rights, so enable php module.
|
||||
parent::setUp();
|
||||
|
||||
module_enable(array('php'));
|
||||
$this->resetAll();
|
||||
}
|
||||
|
||||
function viewsData() {
|
||||
$data = parent::viewsData();
|
||||
$data['views_test']['old_field_1']['moved to'] = array('views_test', 'id');
|
||||
$data['views_test']['old_field_2']['field']['moved to'] = array('views_test', 'name');
|
||||
$data['views_test']['old_field_3']['filter']['moved to'] = array('views_test', 'age');
|
||||
|
||||
// @todo Test this scenario, too.
|
||||
$data['views_old_table_2']['old_field']['moved to'] = array('views_test', 'job');
|
||||
|
||||
$data['views_old_table']['moved to'] = 'views_test';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function debugField($field) {
|
||||
$keys = array('id', 'table', 'field', 'actual_field', 'original_field', 'real_field');
|
||||
$info = array();
|
||||
foreach ($keys as $key) {
|
||||
$info[$key] = $field->{$key};
|
||||
}
|
||||
debug($info, NULL, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the moved to parameter in general.
|
||||
*/
|
||||
public function testMovedTo() {
|
||||
// Test moving on field lavel.
|
||||
$view = $this->viewsMovedToField();
|
||||
$view->update();
|
||||
$view->build();
|
||||
|
||||
// $this->assertEqual('old_field_1', $view->field['old_field_1']->options['id'], "Id shouldn't change during conversion");
|
||||
// $this->assertEqual('id', $view->field['old_field_1']->field, 'The field should change during conversion');
|
||||
$this->assertEqual('id', $view->field['old_field_1']->real_field);
|
||||
$this->assertEqual('views_test', $view->field['old_field_1']->table);
|
||||
$this->assertEqual('old_field_1', $view->field['old_field_1']->original_field, 'The field should have stored the original_field');
|
||||
|
||||
// Test moving on handler lavel.
|
||||
$view = $this->viewsMovedToHandler();
|
||||
$view->update();
|
||||
$view->build();
|
||||
|
||||
// $this->assertEqual('old_field_2', $view->field['old_field_2']->options['id']);
|
||||
$this->assertEqual('name', $view->field['old_field_2']->real_field);
|
||||
$this->assertEqual('views_test', $view->field['old_field_2']->table);
|
||||
|
||||
// $this->assertEqual('old_field_3', $view->filter['old_field_3']->options['id']);
|
||||
$this->assertEqual('age', $view->filter['old_field_3']->real_field);
|
||||
$this->assertEqual('views_test', $view->filter['old_field_3']->table);
|
||||
|
||||
// Test moving on table level.
|
||||
$view = $this->viewsMovedToTable();
|
||||
$view->update();
|
||||
$view->build();
|
||||
|
||||
$this->assertEqual('views_test', $view->base_table, 'Make sure that view->base_table gets automatically converted.');
|
||||
// $this->assertEqual('id', $view->field['id']->field, 'If we move a whole table fields of this table should work, too.');
|
||||
$this->assertEqual('id', $view->field['id']->real_field, 'To run the query right the real_field has to be set right.');
|
||||
$this->assertEqual('views_test', $view->field['id']->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a import via ui.
|
||||
*
|
||||
* To ensure the general functionality, the recent comments view from drupal6
|
||||
* is used.
|
||||
*/
|
||||
public function testUpgradeImport() {
|
||||
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration', 'use PHP for settings'));
|
||||
$this->drupalLogin($admin_user);
|
||||
$edit = array(
|
||||
'view' => $this->viewUpgradeImport(),
|
||||
);
|
||||
$this->drupalPost('admin/structure/views/import', $edit, t('Import'));
|
||||
|
||||
$this->assertText('Recent comments');
|
||||
}
|
||||
|
||||
public function viewsMovedToField() {
|
||||
$view = new view;
|
||||
$view->name = 'test_views_move_to_field';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'views_test';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['fields']['old_field_1']['id'] = 'old_field_1';
|
||||
$handler->display->display_options['fields']['old_field_1']['table'] = 'views_test';
|
||||
$handler->display->display_options['fields']['old_field_1']['field'] = 'old_field_1';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
public function viewsMovedToHandler() {
|
||||
$view = new view;
|
||||
$view->name = 'test_views_move_to_handler';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'views_test';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['fields']['old_field_2']['id'] = 'old_field_2';
|
||||
$handler->display->display_options['fields']['old_field_2']['table'] = 'views_test';
|
||||
$handler->display->display_options['fields']['old_field_2']['field'] = 'old_field_2';
|
||||
|
||||
$handler->display->display_options['filters']['old_field_3']['id'] = 'old_field_3';
|
||||
$handler->display->display_options['filters']['old_field_3']['table'] = 'views_test';
|
||||
$handler->display->display_options['filters']['old_field_3']['field'] = 'old_field_3';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
public function viewsMovedToTable() {
|
||||
$view = new view;
|
||||
$view->name = 'test_views_move_to_table';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'views_old_table';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$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['fields']['id']['id'] = 'id';
|
||||
$handler->display->display_options['fields']['id']['table'] = 'views_old_table';
|
||||
$handler->display->display_options['fields']['id']['field'] = 'id';
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
protected function viewUpgradeImport() {
|
||||
$import = '
|
||||
$view = new view;
|
||||
$view->name = "comments_recent";
|
||||
$view->description = "Contains a block and a page to list recent comments; the block will automatically link to the page, which displays the comment body as well as a link to the node.";
|
||||
$view->tag = "default";
|
||||
$view->base_table = "comments";
|
||||
$view->human_name = "";
|
||||
$view->core = 0;
|
||||
$view->api_version = "3.0-alpha1";
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Defaults */
|
||||
$handler = $view->new_display("default", "Defaults", "default");
|
||||
$handler->display->display_options["title"] = "Recent comments";
|
||||
$handler->display->display_options["use_more"] = TRUE;
|
||||
$handler->display->display_options["access"]["type"] = "none";
|
||||
$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"] = "some";
|
||||
$handler->display->display_options["pager"]["options"]["items_per_page"] = 5;
|
||||
$handler->display->display_options["style_plugin"] = "list";
|
||||
$handler->display->display_options["row_plugin"] = "fields";
|
||||
/* Relationship: Comment: Node */
|
||||
$handler->display->display_options["relationships"]["nid"]["id"] = "nid";
|
||||
$handler->display->display_options["relationships"]["nid"]["table"] = "comments";
|
||||
$handler->display->display_options["relationships"]["nid"]["field"] = "nid";
|
||||
/* Field: Comment: Title */
|
||||
$handler->display->display_options["fields"]["subject"]["id"] = "subject";
|
||||
$handler->display->display_options["fields"]["subject"]["table"] = "comments";
|
||||
$handler->display->display_options["fields"]["subject"]["field"] = "subject";
|
||||
$handler->display->display_options["fields"]["subject"]["label"] = "";
|
||||
$handler->display->display_options["fields"]["subject"]["link_to_comment"] = 1;
|
||||
/* Field: Comment: Post date */
|
||||
$handler->display->display_options["fields"]["timestamp"]["id"] = "timestamp";
|
||||
$handler->display->display_options["fields"]["timestamp"]["table"] = "comments";
|
||||
$handler->display->display_options["fields"]["timestamp"]["field"] = "timestamp";
|
||||
$handler->display->display_options["fields"]["timestamp"]["label"] = "";
|
||||
$handler->display->display_options["fields"]["timestamp"]["date_format"] = "time ago";
|
||||
/* Sort criterion: Comment: Post date */
|
||||
$handler->display->display_options["sorts"]["timestamp"]["id"] = "timestamp";
|
||||
$handler->display->display_options["sorts"]["timestamp"]["table"] = "comments";
|
||||
$handler->display->display_options["sorts"]["timestamp"]["field"] = "timestamp";
|
||||
$handler->display->display_options["sorts"]["timestamp"]["order"] = "DESC";
|
||||
/* Filter: Node: Published or admin */
|
||||
$handler->display->display_options["filters"]["status_extra"]["id"] = "status_extra";
|
||||
$handler->display->display_options["filters"]["status_extra"]["table"] = "node";
|
||||
$handler->display->display_options["filters"]["status_extra"]["field"] = "status_extra";
|
||||
$handler->display->display_options["filters"]["status_extra"]["relationship"] = "nid";
|
||||
$handler->display->display_options["filters"]["status_extra"]["group"] = 0;
|
||||
$handler->display->display_options["filters"]["status_extra"]["expose"]["operator"] = FALSE;
|
||||
|
||||
/* Display: Page */
|
||||
$handler = $view->new_display("page", "Page", "page");
|
||||
$handler->display->display_options["defaults"]["items_per_page"] = FALSE;
|
||||
$handler->display->display_options["defaults"]["style_plugin"] = FALSE;
|
||||
$handler->display->display_options["style_plugin"] = "list";
|
||||
$handler->display->display_options["defaults"]["style_options"] = FALSE;
|
||||
$handler->display->display_options["defaults"]["row_plugin"] = FALSE;
|
||||
$handler->display->display_options["row_plugin"] = "fields";
|
||||
$handler->display->display_options["row_options"]["inline"] = array(
|
||||
"title" => "title",
|
||||
"timestamp" => "timestamp",
|
||||
);
|
||||
$handler->display->display_options["row_options"]["separator"] = " ";
|
||||
$handler->display->display_options["defaults"]["row_options"] = FALSE;
|
||||
$handler->display->display_options["defaults"]["fields"] = FALSE;
|
||||
/* Field: Node: 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"]["relationship"] = "nid";
|
||||
$handler->display->display_options["fields"]["title"]["label"] = "Reply to";
|
||||
$handler->display->display_options["fields"]["title"]["link_to_node"] = 1;
|
||||
/* Field: Comment: Post date */
|
||||
$handler->display->display_options["fields"]["timestamp"]["id"] = "timestamp";
|
||||
$handler->display->display_options["fields"]["timestamp"]["table"] = "comments";
|
||||
$handler->display->display_options["fields"]["timestamp"]["field"] = "timestamp";
|
||||
$handler->display->display_options["fields"]["timestamp"]["label"] = "";
|
||||
$handler->display->display_options["fields"]["timestamp"]["date_format"] = "time ago";
|
||||
/* Field: Comment: Title */
|
||||
$handler->display->display_options["fields"]["subject"]["id"] = "subject";
|
||||
$handler->display->display_options["fields"]["subject"]["table"] = "comments";
|
||||
$handler->display->display_options["fields"]["subject"]["field"] = "subject";
|
||||
$handler->display->display_options["fields"]["subject"]["label"] = "";
|
||||
$handler->display->display_options["fields"]["subject"]["link_to_comment"] = 1;
|
||||
/* Field: Comment: Body */
|
||||
$handler->display->display_options["fields"]["comment"]["id"] = "comment";
|
||||
$handler->display->display_options["fields"]["comment"]["table"] = "comments";
|
||||
$handler->display->display_options["fields"]["comment"]["field"] = "comment";
|
||||
$handler->display->display_options["fields"]["comment"]["label"] = "";
|
||||
$handler->display->display_options["path"] = "comments/recent";
|
||||
|
||||
/* Display: Block */
|
||||
$handler = $view->new_display("block", "Block", "block");
|
||||
$handler->display->display_options["block_description"] = "Recent comments view"
|
||||
;';
|
||||
|
||||
return $import;
|
||||
}
|
||||
}
|
290
sites/all/modules/views/tests/views_view.test
Normal file
290
sites/all/modules/views/tests/views_view.test
Normal file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of ViewsViewTest.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Views class tests.
|
||||
*/
|
||||
class ViewsViewTest extends ViewsSqlTest {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Test the view class',
|
||||
'description' => 'Tests some functionality of the view class',
|
||||
'group' => 'Views',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the deconstructor to be sure that every kind of heavy objects are removed.
|
||||
*/
|
||||
function testDestroy() {
|
||||
$view = $this->view_test_destroy();
|
||||
|
||||
$view->preview();
|
||||
$view->destroy();
|
||||
|
||||
$this->assertViewDestroy($view);
|
||||
|
||||
// Manipulate the display variable to test a previous bug.
|
||||
$view = $this->view_test_destroy();
|
||||
$view->preview();
|
||||
|
||||
$view->destroy();
|
||||
$this->assertViewDestroy($view);
|
||||
}
|
||||
|
||||
function assertViewDestroy($view) {
|
||||
$this->assertFalse(isset($view->display['default']->handler), 'Make sure all displays are destroyed.');
|
||||
$this->assertFalse(isset($view->display['attachment_1']->handler), 'Make sure all displays are destroyed.');
|
||||
|
||||
$this->assertFalse(isset($view->filter), 'Make sure all handlers are destroyed');
|
||||
$this->assertFalse(isset($view->field), 'Make sure all handlers are destroyed');
|
||||
$this->assertFalse(isset($view->argument), 'Make sure all handlers are destroyed');
|
||||
$this->assertFalse(isset($view->relationship), 'Make sure all handlers are destroyed');
|
||||
$this->assertFalse(isset($view->sort), 'Make sure all handlers are destroyed');
|
||||
$this->assertFalse(isset($view->area), 'Make sure all handlers are destroyed');
|
||||
|
||||
$keys = array('current_display', 'display_handler', 'field', 'argument', 'filter', 'sort', 'relationship', 'header', 'footer', 'empty', 'query', 'result', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'many_to_one_tables');
|
||||
foreach ($keys as $key) {
|
||||
$this->assertFalse(isset($view->{$key}), $key);
|
||||
}
|
||||
$this->assertEqual($view->built, FALSE);
|
||||
$this->assertEqual($view->executed, FALSE);
|
||||
$this->assertEqual($view->build_info, array());
|
||||
$this->assertEqual($view->attachment_before, '');
|
||||
$this->assertEqual($view->attachment_after, '');
|
||||
}
|
||||
|
||||
function testDelete() {
|
||||
// Delete a database view
|
||||
$view = $this->view_test_delete();
|
||||
$view->save();
|
||||
$view = views_get_view($view->name);
|
||||
$view->delete();
|
||||
|
||||
$view = views_get_view($view->name);
|
||||
$this->assertNotNull($view, 'Make sure that the old view is still in the static cache.');
|
||||
|
||||
$view = views_get_view($view->name, TRUE);
|
||||
$this->assertNull($view, "Make sure that the old view gets cleared by the reset parameter.");
|
||||
}
|
||||
|
||||
function testValidate() {
|
||||
// Test a view with multiple displays.
|
||||
// Validating a view shouldn't change the active display.
|
||||
// @todo: Create an extra validation view.
|
||||
$view = $this->view_test_destroy();
|
||||
$view->set_display('page_1');
|
||||
|
||||
$view->validate();
|
||||
|
||||
$this->assertEqual('page_1', $view->current_display, "The display should be constant while validating");
|
||||
|
||||
// @todo: Write real tests for the validation.
|
||||
// In general the following things could be tested:
|
||||
// - Deleted displays shouldn't be validated
|
||||
// - Multiple displays are validating and the errors are merged together.
|
||||
}
|
||||
|
||||
/**
|
||||
* This view provides some filters, fields, arguments, relationships, sorts, areas and attachments.
|
||||
*/
|
||||
function view_test_destroy() {
|
||||
$view = new view;
|
||||
$view->name = 'test_destroy';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = '';
|
||||
$view->api_version = '3.0-alpha1';
|
||||
$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['access']['type'] = 'none';
|
||||
$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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
/* Header: Global: Text area */
|
||||
$handler->display->display_options['header']['area']['id'] = 'area';
|
||||
$handler->display->display_options['header']['area']['table'] = 'views';
|
||||
$handler->display->display_options['header']['area']['field'] = 'area';
|
||||
$handler->display->display_options['header']['area']['empty'] = FALSE;
|
||||
/* Header: Global: Text area */
|
||||
$handler->display->display_options['header']['area_1']['id'] = 'area_1';
|
||||
$handler->display->display_options['header']['area_1']['table'] = 'views';
|
||||
$handler->display->display_options['header']['area_1']['field'] = 'area';
|
||||
$handler->display->display_options['header']['area_1']['empty'] = FALSE;
|
||||
/* Footer: Global: Text area */
|
||||
$handler->display->display_options['footer']['area']['id'] = 'area';
|
||||
$handler->display->display_options['footer']['area']['table'] = 'views';
|
||||
$handler->display->display_options['footer']['area']['field'] = 'area';
|
||||
$handler->display->display_options['footer']['area']['empty'] = FALSE;
|
||||
/* Footer: Global: Text area */
|
||||
$handler->display->display_options['footer']['area_1']['id'] = 'area_1';
|
||||
$handler->display->display_options['footer']['area_1']['table'] = 'views';
|
||||
$handler->display->display_options['footer']['area_1']['field'] = 'area';
|
||||
$handler->display->display_options['footer']['area_1']['empty'] = FALSE;
|
||||
/* Empty text: 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'] = FALSE;
|
||||
/* Empty text: Global: Text area */
|
||||
$handler->display->display_options['empty']['area_1']['id'] = 'area_1';
|
||||
$handler->display->display_options['empty']['area_1']['table'] = 'views';
|
||||
$handler->display->display_options['empty']['area_1']['field'] = 'area';
|
||||
$handler->display->display_options['empty']['area_1']['empty'] = FALSE;
|
||||
/* Relationship: Comment: Node */
|
||||
$handler->display->display_options['relationships']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['relationships']['nid']['table'] = 'comments';
|
||||
$handler->display->display_options['relationships']['nid']['field'] = 'nid';
|
||||
/* Relationship: Comment: Parent comment */
|
||||
$handler->display->display_options['relationships']['pid']['id'] = 'pid';
|
||||
$handler->display->display_options['relationships']['pid']['table'] = 'comments';
|
||||
$handler->display->display_options['relationships']['pid']['field'] = 'pid';
|
||||
/* Relationship: Comment: User */
|
||||
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
|
||||
$handler->display->display_options['relationships']['uid']['table'] = 'comments';
|
||||
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
|
||||
/* Field: Content: Nid */
|
||||
$handler->display->display_options['fields']['nid']['id'] = 'nid';
|
||||
$handler->display->display_options['fields']['nid']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['nid']['field'] = 'nid';
|
||||
/* Field: Content: Path */
|
||||
$handler->display->display_options['fields']['path']['id'] = 'path';
|
||||
$handler->display->display_options['fields']['path']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['path']['field'] = 'path';
|
||||
/* Field: Content: Post date */
|
||||
$handler->display->display_options['fields']['created']['id'] = 'created';
|
||||
$handler->display->display_options['fields']['created']['table'] = 'node';
|
||||
$handler->display->display_options['fields']['created']['field'] = 'created';
|
||||
/* Sort criterion: Content: In moderation */
|
||||
$handler->display->display_options['sorts']['moderate']['id'] = 'moderate';
|
||||
$handler->display->display_options['sorts']['moderate']['table'] = 'node';
|
||||
$handler->display->display_options['sorts']['moderate']['field'] = 'moderate';
|
||||
/* Sort criterion: Content: Last comment author */
|
||||
$handler->display->display_options['sorts']['last_comment_name']['id'] = 'last_comment_name';
|
||||
$handler->display->display_options['sorts']['last_comment_name']['table'] = 'node_comment_statistics';
|
||||
$handler->display->display_options['sorts']['last_comment_name']['field'] = 'last_comment_name';
|
||||
/* Sort criterion: Content: Last comment time */
|
||||
$handler->display->display_options['sorts']['last_comment_timestamp']['id'] = 'last_comment_timestamp';
|
||||
$handler->display->display_options['sorts']['last_comment_timestamp']['table'] = 'node_comment_statistics';
|
||||
$handler->display->display_options['sorts']['last_comment_timestamp']['field'] = 'last_comment_timestamp';
|
||||
/* Argument: Content: Created date */
|
||||
$handler->display->display_options['arguments']['created_fulldate']['id'] = 'created_fulldate';
|
||||
$handler->display->display_options['arguments']['created_fulldate']['table'] = 'node';
|
||||
$handler->display->display_options['arguments']['created_fulldate']['field'] = 'created_fulldate';
|
||||
$handler->display->display_options['arguments']['created_fulldate']['style_plugin'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['created_fulldate']['default_argument_type'] = 'fixed';
|
||||
/* Argument: Content: Created day */
|
||||
$handler->display->display_options['arguments']['created_day']['id'] = 'created_day';
|
||||
$handler->display->display_options['arguments']['created_day']['table'] = 'node';
|
||||
$handler->display->display_options['arguments']['created_day']['field'] = 'created_day';
|
||||
$handler->display->display_options['arguments']['created_day']['style_plugin'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['created_day']['default_argument_type'] = 'fixed';
|
||||
/* Argument: Content: Created month */
|
||||
$handler->display->display_options['arguments']['created_month']['id'] = 'created_month';
|
||||
$handler->display->display_options['arguments']['created_month']['table'] = 'node';
|
||||
$handler->display->display_options['arguments']['created_month']['field'] = 'created_month';
|
||||
$handler->display->display_options['arguments']['created_month']['style_plugin'] = 'default_summary';
|
||||
$handler->display->display_options['arguments']['created_month']['default_argument_type'] = 'fixed';
|
||||
/* Filter: 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';
|
||||
/* Filter: 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';
|
||||
/* Filter: 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';
|
||||
|
||||
/* Display: Page */
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->display->display_options['path'] = 'test_destroy';
|
||||
|
||||
/* Display: Attachment */
|
||||
$handler = $view->new_display('attachment', 'Attachment', 'attachment_1');
|
||||
$handler->display->display_options['pager']['type'] = 'some';
|
||||
$handler->display->display_options['displays'] = array(
|
||||
'default' => 'default',
|
||||
'page_1' => 'page_1',
|
||||
);
|
||||
|
||||
/* Display: Attachment */
|
||||
$handler = $view->new_display('attachment', 'Attachment', 'attachment_2');
|
||||
$handler->display->display_options['pager']['type'] = 'some';
|
||||
$handler->display->display_options['displays'] = array(
|
||||
'default' => 'default',
|
||||
'page_1' => 'page_1',
|
||||
);
|
||||
$translatables['test_destroy'] = array(
|
||||
t('Master'),
|
||||
t('more'),
|
||||
t('Apply'),
|
||||
t('Reset'),
|
||||
t('Sort By'),
|
||||
t('Asc'),
|
||||
t('Desc'),
|
||||
t('Items per page'),
|
||||
t('- All -'),
|
||||
t('Offset'),
|
||||
t('Text area'),
|
||||
t('Content'),
|
||||
t('Parent comment'),
|
||||
t('User'),
|
||||
t('Nid'),
|
||||
t('Path'),
|
||||
t('Post date'),
|
||||
t('All'),
|
||||
t('Page'),
|
||||
t('Attachment'),
|
||||
);
|
||||
|
||||
return $view;
|
||||
}
|
||||
function view_test_delete() {
|
||||
$view = new view;
|
||||
$view->name = 'test_view_delete';
|
||||
$view->description = '';
|
||||
$view->tag = '';
|
||||
$view->base_table = 'node';
|
||||
$view->human_name = 'test_view_delete';
|
||||
$view->core = 7;
|
||||
$view->api_version = '3.0-alpha1';
|
||||
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
|
||||
|
||||
/* Display: Defaults */
|
||||
$handler = $view->new_display('default', 'Defaults', 'default');
|
||||
$handler->display->display_options['access']['type'] = 'none';
|
||||
$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'] = 'default';
|
||||
$handler->display->display_options['row_plugin'] = 'fields';
|
||||
$translatables['test_view_delete'] = array(
|
||||
t('Defaults'),
|
||||
t('more'),
|
||||
t('Apply'),
|
||||
t('Reset'),
|
||||
t('Sort By'),
|
||||
t('Asc'),
|
||||
t('Desc'),
|
||||
t('Items per page'),
|
||||
t('- All -'),
|
||||
t('Offset'),
|
||||
);
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user