Commit 92f9c916 authored by damiankloip's avatar damiankloip Committed by tim.plunkett

Issue #1754286 by dawehner, damiankloip: Write tests for the default views.

parent d264fd47
......@@ -143,7 +143,7 @@ function render($row) {
}
// Create the RSS item object.
$item = new stdClass();
$item = new \stdClass();
$item->title = $this->get_field($row_index, $this->options['title_field']);
$item->link = url($this->get_field($row_index, $this->options['link_field']), array('absolute' => TRUE));
$item->description = $this->get_field($row_index, $this->options['description_field']);
......
<?php
/**
* @file
* Definition of Drupal\views\Tests\DefaultViewsTest.
*/
namespace Drupal\views\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\views\ViewExecutable;
/**
* Tests for views default views.
*/
class DefaultViewsTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('views', 'node', 'search', 'comment', 'taxonomy', 'block');
/**
* An array of argument arrays to use for default views.
*
* @var array
*/
protected $viewArgMap = array(
'backlinks' => array(1),
'taxonomy_term' => array(1),
'glossary' => array('all'),
);
public static function getInfo() {
return array(
'name' => 'Default views',
'description' => 'Tests the default views provided by views',
'group' => 'Views',
);
}
protected function setUp() {
parent::setUp();
$this->vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => $this->randomName(),
'description' => $this->randomName(),
'machine_name' => drupal_strtolower($this->randomName()),
'langcode' => LANGUAGE_NOT_SPECIFIED,
'help' => '',
'nodes' => array('page' => 'page'),
'weight' => mt_rand(0, 10),
));
taxonomy_vocabulary_save($this->vocabulary);
// Setup a field and instance.
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array(
'field_name' => $this->field_name,
'type' => 'taxonomy_term_reference',
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $this->vocabulary->machine_name,
'parent' => '0',
),
),
)
);
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_select',
),
'display' => array(
'full' => array(
'type' => 'taxonomy_term_reference_link',
),
),
);
field_create_instance($this->instance);
// Create a time in the past for the archive.
$time = time() - 3600;
for ($i = 0; $i <= 10; $i++) {
$user = $this->drupalCreateUser();
$term = $this->createTerm($this->vocabulary);
$values = array('created' => $time, 'type' => 'page');
$values[$this->field_name][LANGUAGE_NOT_SPECIFIED][]['tid'] = $term->tid;
// Make every other node promoted.
if ($i % 2) {
$values['promote'] = TRUE;
}
$values['body'][LANGUAGE_NOT_SPECIFIED][]['value'] = l('Node ' . 1, 'node/' . 1);
$node = $this->drupalCreateNode($values);
search_index($node->nid, 'node', $node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], LANGUAGE_NOT_SPECIFIED);
$comment = array(
'uid' => $user->uid,
'nid' => $node->nid,
);
entity_create('comment', $comment)->save();
}
}
/**
* Test that all Default views work as expected.
*/
public function testDefaultViews() {
// Get all default views.
$controller = entity_get_controller('view');
$views = $controller->load();
foreach ($views as $name => $view_storage) {
$view = new ViewExecutable($view_storage);
$view->initDisplay();
foreach ($view->storage->display as $display_id => $display) {
$view->setDisplay($display_id);
// Add any args if needed.
if (array_key_exists($name, $this->viewArgMap)) {
$view->preExecute($this->viewArgMap[$name]);
}
$this->assert(TRUE, format_string('View @view will be executed.', array('@view' => $view->storage->name)));
$view->execute();
$tokens = array('@name' => $name, '@display_id' => $display_id);
$this->assertTrue($view->executed, format_string('@name:@display_id has been executed.', $tokens));
$count = count($view->result);
$this->assertTrue($count > 0, format_string('@count results returned', array('@count' => $count)));
$view->destroy();
}
}
}
/**
* Returns a new term with random properties in vocabulary $vid.
*/
function createTerm($vocabulary) {
$term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'description' => $this->randomName(),
// Use the first available text format.
'format' => db_query_range('SELECT format FROM {filter_format}', 0, 1)->fetchField(),
'vid' => $vocabulary->vid,
'langcode' => LANGUAGE_NOT_SPECIFIED,
));
taxonomy_term_save($term);
return $term;
}
}
......@@ -7,7 +7,6 @@
namespace Drupal\views\Tests\Handler;
use stdClass;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Plugin\views\HandlerBase;
......@@ -58,7 +57,7 @@ function testFilterInOperatorUi() {
* Tests the breakPhraseString() method.
*/
function testBreakPhraseString() {
$empty_stdclass = new StdClass();
$empty_stdclass = new \stdClass();
$empty_stdclass->operator = 'or';
$empty_stdclass->value = array();
......@@ -113,7 +112,7 @@ function testBreakPhraseString() {
* Tests views_break_phrase function.
*/
function testBreakPhrase() {
$empty_stdclass = new StdClass();
$empty_stdclass = new \stdClass();
$empty_stdclass->operator = 'or';
$empty_stdclass->value = array();
......
......@@ -7,8 +7,6 @@
namespace Drupal\views\Tests\Plugin;
use stdClass;
/**
* Tests some general style plugin related functionality.
*
......@@ -107,16 +105,16 @@ function testGroupingLegacy() {
$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] = new \stdClass();
$expected['Job: Singer'][0]->views_test_data_name = 'John';
$expected['Job: Singer'][0]->views_test_data_job = 'Singer';
$expected['Job: Singer'][0]->views_test_data_id = '1';
$expected['Job: Singer'][1] = new stdClass();
$expected['Job: Singer'][1] = new \stdClass();
$expected['Job: Singer'][1]->views_test_data_name = 'George';
$expected['Job: Singer'][1]->views_test_data_job = 'Singer';
$expected['Job: Singer'][1]->views_test_data_id = '2';
$expected['Job: Drummer'] = array();
$expected['Job: Drummer'][2] = new stdClass();
$expected['Job: Drummer'][2] = new \stdClass();
$expected['Job: Drummer'][2]->views_test_data_name = 'Ringo';
$expected['Job: Drummer'][2]->views_test_data_job = 'Drummer';
$expected['Job: Drummer'][2]->views_test_data_id = '3';
......@@ -126,17 +124,17 @@ function testGroupingLegacy() {
$expected = array();
$expected['Job: Singer'] = array();
$expected['Job: Singer']['group'] = 'Job: Singer';
$expected['Job: Singer']['rows'][0] = new stdClass();
$expected['Job: Singer']['rows'][0] = new \stdClass();
$expected['Job: Singer']['rows'][0]->views_test_data_name = 'John';
$expected['Job: Singer']['rows'][0]->views_test_data_job = 'Singer';
$expected['Job: Singer']['rows'][0]->views_test_data_id = '1';
$expected['Job: Singer']['rows'][1] = new stdClass();
$expected['Job: Singer']['rows'][1] = new \stdClass();
$expected['Job: Singer']['rows'][1]->views_test_data_name = 'George';
$expected['Job: Singer']['rows'][1]->views_test_data_job = 'Singer';
$expected['Job: Singer']['rows'][1]->views_test_data_id = '2';
$expected['Job: Drummer'] = array();
$expected['Job: Drummer']['group'] = 'Job: Drummer';
$expected['Job: Drummer']['rows'][2] = new stdClass();
$expected['Job: Drummer']['rows'][2] = new \stdClass();
$expected['Job: Drummer']['rows'][2]->views_test_data_name = 'Ringo';
$expected['Job: Drummer']['rows'][2]->views_test_data_job = 'Drummer';
$expected['Job: Drummer']['rows'][2]->views_test_data_id = '3';
......@@ -211,14 +209,14 @@ function _testGrouping($stripped = FALSE) {
$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] = new \stdClass();
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_name = 'John';
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_job = 'Singer';
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_age = '25';
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_data_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] = new \stdClass();
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_name = 'George';
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_job = 'Singer';
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_data_age = '27';
......@@ -227,7 +225,7 @@ function _testGrouping($stripped = FALSE) {
$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] = new \stdClass();
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_name = 'Ringo';
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_job = 'Drummer';
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_data_age = '28';
......
......@@ -102,7 +102,7 @@ public function query($group_by = FALSE) {
$this->ensureMyTable();
if (!empty($this->options['break_phrase'])) {
$tids = new stdClass();
$tids = new \stdClass();
$tids->value = $this->argument;
$tids = $this->breakPhrase($this->argument, $tids);
if ($tids->value == array(-1)) {
......
......@@ -79,7 +79,13 @@ function search_views_data() {
$data['search_node_links_from']['table']['group'] = t('Search');
$data['search_node_links_from']['table']['join'] = array(
'node' => array(
'arguments' => array('search_node_links', 'node', 'nid', 'nid', NULL, 'INNER'),
'arguments' => array(
'table' => 'search_node_links',
'left_table' => 'node',
'field' => 'nid',
'left_field' => 'nid',
'type' => 'INNER'
),
),
);
$data['search_node_links_from']['sid'] = array(
......@@ -97,7 +103,13 @@ function search_views_data() {
$data['search_node_links_to']['table']['group'] = t('Search');
$data['search_node_links_to']['table']['join'] = array(
'node' => array(
'arguments' => array('search_node_links', 'node', 'nid', 'sid', NULL, 'INNER'),
'arguments' => array(
'table' => 'search_node_links',
'left_table' => 'node',
'field' => 'sid',
'left_field' => 'nid',
'type' => 'INNER'
),
),
);
$data['search_node_links_to']['nid'] = array(
......
api_version: '3.0'
base_table: node
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
access:
type: none
cache:
type: none
exposed_form:
type: test_exposed_form
pager:
type: full
style:
type: default
row:
type: fields
display_plugin: default
display_title: Master
id: default
position: '0'
human_name: ''
name: test_exposed_form
tag: ''
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment