Commit 41ae1ead authored by catch's avatar catch

Issue #1856272 by tim.plunkett: Speed up tests by only installing the views used by that tests.

parent 52218869
......@@ -12,6 +12,13 @@
*/
class BasicTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view', 'test_simple_argument');
public static function getInfo() {
return array(
'name' => 'Basic query tests',
......@@ -101,56 +108,8 @@ public function testSimpleFiltering() {
* Tests simple argument.
*/
public function testSimpleArgument() {
$view = views_get_view('test_view');
$view->setDisplay();
// Add a argument.
$view->displayHandlers['default']->overrideOption('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' => array(
'type' => 'none',
'fail' => 'not found',
),
'break_phrase' => 0,
'not' => 0,
'id' => 'age',
'table' => 'views_test_data',
'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 = views_get_view('test_simple_argument');
$view->setArguments(array(27));
$this->executeView($view);
......@@ -171,7 +130,7 @@ public function testSimpleArgument() {
));
// Test "show all" if no argument is present.
$view = $saved_view->cloneView();
$view = views_get_view('test_simple_argument');
$this->executeView($view);
// Build the expected result.
......
......@@ -12,6 +12,13 @@
*/
class ArgumentUserUIDTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_comment_user_uid');
public static function getInfo() {
return array(
'name' => 'Comment: User UID Argument',
......@@ -21,7 +28,8 @@ public static function getInfo() {
}
function testCommentUserUIDTest() {
$this->executeView($this->view, array($this->account->uid));
$view = views_get_view('test_comment_user_uid');
$this->executeView($view, array($this->account->uid));
$result_set = array(
array(
'nid' => $this->node_user_posted->nid,
......@@ -30,8 +38,8 @@ function testCommentUserUIDTest() {
'nid' => $this->node_user_commented->nid,
),
);
$this->column_map = array('nid' => 'nid');
$this->assertIdenticalResultset($this->view, $result_set, $this->column_map);
$column_map = array('nid' => 'nid');
$this->assertIdenticalResultset($view, $result_set, $column_map);
}
}
......@@ -42,11 +42,4 @@ function setUp() {
entity_create('comment', $comment)->save();
}
/**
* Overrides Drupal\views\Tests\ViewTestBase::getBasicView().
*/
protected function getBasicView() {
return $this->createViewFromConfig('test_comment_user_uid');
}
}
......@@ -14,6 +14,13 @@
*/
class FilterUserUIDTest extends CommentTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_comment_user_uid');
public static function getInfo() {
return array(
'name' => 'Comment: User UID Filter',
......@@ -23,7 +30,9 @@ public static function getInfo() {
}
function testCommentUserUIDTest() {
$this->view->setItem('default', 'argument', 'uid_touch', NULL);
$view = views_get_view('test_comment_user_uid');
$view->setDisplay();
$view->setItem('default', 'argument', 'uid_touch', NULL);
$options = array(
'id' => 'uid_touch',
......@@ -31,8 +40,8 @@ function testCommentUserUIDTest() {
'field' => 'uid_touch',
'value' => array($this->loggedInUser->uid),
);
$this->view->addItem('default', 'filter', 'node', 'uid_touch', $options);
$this->executeView($this->view, array($this->account->uid));
$view->addItem('default', 'filter', 'node', 'uid_touch', $options);
$this->executeView($view, array($this->account->uid));
$result_set = array(
array(
'nid' => $this->node_user_posted->nid,
......@@ -42,7 +51,7 @@ function testCommentUserUIDTest() {
),
);
$this->column_map = array('nid' => 'nid');
$this->assertIdenticalResultset($this->view, $result_set, $this->column_map);
$this->assertIdenticalResultset($view, $result_set, $this->column_map);
}
}
......@@ -14,6 +14,12 @@
*/
class FieldEntityTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_field_get_entity');
/**
* Modules to enable.
......
......@@ -7,6 +7,8 @@
namespace Drupal\views\Tests\Field;
use Drupal\views\ViewExecutable;
/**
* Tests the field_field handler.
* @TODO
......@@ -17,6 +19,13 @@
*/
class HandlerFieldFieldTest extends FieldTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view_fieldapi');
public $nodes;
public static function getInfo() {
......@@ -27,6 +36,9 @@ public static function getInfo() {
);
}
/**
* @todo.
*/
protected function setUp() {
parent::setUp();
......@@ -59,19 +71,21 @@ protected function setUp() {
$this->nodes[$i] = $this->drupalCreateNode($edit);
}
foreach ($this->fields as $key => $field) {
$this->view->display_handler->display['display_options']['fields'][$field['field_name']]['id'] = $field['field_name'];
$this->view->display_handler->display['display_options']['fields'][$field['field_name']]['table'] = 'field_data_' . $field['field_name'];
$this->view->display_handler->display['display_options']['fields'][$field['field_name']]['field'] = $field['field_name'];
}
}
/**
* Overrides Drupal\views\Tests\ViewTestBase::getBasicView().
* Sets up the testing view with random field data.
*
* @param \Drupal\views\ViewExecutable $view
* The view to add field data to.
*/
protected function getBasicView() {
return $this->createViewFromConfig('test_view_fieldapi');
protected function prepareView(ViewExecutable $view) {
$view->initDisplay();
foreach ($this->fields as $key => $field) {
$view->display_handler->options['fields'][$field['field_name']]['id'] = $field['field_name'];
$view->display_handler->options['fields'][$field['field_name']]['table'] = 'field_data_' . $field['field_name'];
$view->display_handler->options['fields'][$field['field_name']]['field'] = $field['field_name'];
}
}
public function testFieldRender() {
......@@ -81,7 +95,8 @@ public function testFieldRender() {
}
public function _testSimpleFieldRender() {
$view = $this->getView();
$view = views_get_view('test_view_fieldapi');
$this->prepareView($view);
$this->executeView($view);
// Tests that the rendered fields match the actual value of the fields.
......@@ -99,7 +114,8 @@ public function _testSimpleFieldRender() {
* Tests that fields with formatters runs as expected.
*/
public function _testFormatterSimpleFieldRender() {
$view = $this->getView();
$view = views_get_view('test_view_fieldapi');
$this->prepareView($view);
$view->displayHandlers['default']->options['fields'][$this->fields[0]['field_name']]['type'] = 'text_trimmed';
$view->displayHandlers['default']->options['fields'][$this->fields[0]['field_name']]['settings'] = array(
'trim_length' => 3,
......@@ -115,11 +131,11 @@ public function _testFormatterSimpleFieldRender() {
}
public function _testMultipleFieldRender() {
$view = $this->getView();
$view = views_get_view('test_view_fieldapi');
$field_name = $this->fields[3]['field_name'];
// Test delta limit.
$view->initDisplay();
$this->prepareView($view);
$view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE;
$view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 3;
$this->executeView($view);
......@@ -141,7 +157,7 @@ public function _testMultipleFieldRender() {
$view->destroy();
// Test delta limit + offset
$view->initDisplay();
$this->prepareView($view);
$view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE;
$view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 3;
$view->displayHandlers['default']->options['fields'][$field_name]['delta_offset'] = 1;
......@@ -160,7 +176,7 @@ public function _testMultipleFieldRender() {
$view->destroy();
// Test delta limit + reverse.
$view->initDisplay();
$this->prepareView($view);
$view->displayHandlers['default']->options['fields'][$field_name]['delta_offset'] = 0;
$view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE;
$view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 3;
......@@ -181,7 +197,7 @@ public function _testMultipleFieldRender() {
$view->destroy();
// Test delta first last.
$view->initDisplay();
$this->prepareView($view);
$view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE;
$view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 0;
$view->displayHandlers['default']->options['fields'][$field_name]['delta_first_last'] = TRUE;
......@@ -199,7 +215,7 @@ public function _testMultipleFieldRender() {
$view->destroy();
// Test delta limit + custom seperator.
$view->initDisplay();
$this->prepareView($view);
$view->displayHandlers['default']->options['fields'][$field_name]['delta_first_last'] = FALSE;
$view->displayHandlers['default']->options['fields'][$field_name]['delta_limit'] = 3;
$view->displayHandlers['default']->options['fields'][$field_name]['group_rows'] = TRUE;
......
......@@ -15,6 +15,13 @@
*/
class AreaTest extends HandlerTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_example_area');
/**
* Modules to enable.
*
......
......@@ -16,6 +16,13 @@
*/
class AreaTextTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Area: Text',
......
......@@ -14,6 +14,13 @@
*/
class ArgumentNullTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Argument: Null',
......
......@@ -12,6 +12,13 @@
*/
class ArgumentStringTest extends HandlerTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_glossary');
public static function getInfo() {
return array(
'name' => 'Argument: String',
......@@ -35,7 +42,7 @@ function testGlossary() {
}
}
$view = $this->createViewFromConfig('test_glossary');
$view = views_get_view('test_glossary');
$this->executeView($view);
$count_field = 'nid';
......
......@@ -14,6 +14,13 @@
*/
class FieldBooleanTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Field: Boolean',
......
......@@ -14,6 +14,13 @@
*/
class FieldCounterTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Field: Counter',
......
......@@ -14,6 +14,13 @@
*/
class FieldCustomTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Field: Custom',
......
......@@ -14,6 +14,13 @@
*/
class FieldDateTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Field: Date',
......
......@@ -16,6 +16,13 @@
*/
class FieldFileSizeTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Field: File size',
......
......@@ -16,6 +16,13 @@
*/
class FieldUnitTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view', 'test_field_tokens', 'test_field_output');
protected $column_map = array(
'views_test_data_name' => 'name',
);
......
......@@ -14,6 +14,13 @@
*/
class FieldUrlTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Field: URL',
......
......@@ -14,6 +14,13 @@
*/
class FieldWebTest extends HandlerTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view', 'test_field_classes', 'test_field_output', 'test_click_sort');
protected $column_map = array(
'views_test_data_name' => 'name',
);
......
......@@ -16,6 +16,13 @@
*/
class FieldXssTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
public static function getInfo() {
return array(
'name' => 'Field: XSS',
......
......@@ -14,6 +14,13 @@
*/
class FilterCombineTest extends ViewUnitTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_view');
protected $column_map = array(
'views_test_data_name' => 'name',
'views_test_data_job' => 'job',
......
......@@ -12,6 +12,13 @@
*/
class FilterDateTest extends HandlerTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_filter_date_between');
/**
* Modules to enable.
*
......@@ -41,14 +48,22 @@ function setUp() {
);
}
/**
* Runs other test methods.
*/
protected function testDateFilter() {
$this->_testOffset();
$this->_testBetween();
$this->_testUiValidation();
}
/**
* Test the general offset functionality.
*/
function testOffset() {
$saved_view = $this->createViewFromConfig('test_filter_date_between');
protected function _testOffset() {
$view = views_get_view('test_filter_date_between');
// Test offset for simple operator.
$view = $this->getView($saved_view);
$view->initHandlers();
$view->filter['created']->operator = '>';
$view->filter['created']->value['type'] = 'offset';
......@@ -58,9 +73,9 @@ function testOffset() {
array('nid' => $this->nodes[3]->nid),
);
$this->assertIdenticalResultset($view, $expected_result, $this->map);
$view->destroy();
// Test offset for between operator.
$view = $this->getView($saved_view);
$view->initHandlers();
$view->filter['created']->operator = 'between';
$view->filter['created']->value['type'] = 'offset';
......@@ -76,11 +91,10 @@ function testOffset() {
/**
* Tests the filter operator between/not between.
*/
function testBetween() {
$saved_view = $this->createViewFromConfig('test_filter_date_between');
protected function _testBetween() {
$view = views_get_view('test_filter_date_between');
// Test between with min and max.
$view = $this->getView($saved_view);
$view->initHandlers();
$view->filter['created']->operator = 'between';
$view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:s');
......@@ -90,9 +104,9 @@ function testBetween() {
array('nid' => $this->nodes[1]->nid),
);
$this->assertIdenticalResultset($view, $expected_result, $this->map);
$view->destroy();
// Test between with just max.
$view = $this->getView($saved_view);
$view->initHandlers();
$view->filter['created']->operator = 'between';
$view->filter['created']->value['max'] = format_date(250000, 'custom', 'Y-m-d H:s');
......@@ -102,9 +116,9 @@ function testBetween() {
array('nid' => $this->nodes[1]->nid),
);
$this->assertIdenticalResultset($view, $expected_result, $this->map);
$view->destroy();
// Test not between with min and max.
$view = $this->getView($saved_view);
$view->initHandlers();
$view->filter['created']->operator = 'not between';
$view->filter['created']->value['min'] = format_date(150000, 'custom', 'Y-m-d H:s');
......@@ -116,9 +130,9 @@ function testBetween() {
array('nid' => $this->nodes[3]->nid),
);
$this->assertIdenticalResultset($view, $expected_result, $this->map);
$view->destroy();
// Test not between with just max.
$view = $this->getView($saved_view);
$view->initHandlers();
$view->filter['created']->operator = 'not between';
$view->filter['created']->value['max'] = format_date(150000, 'custom', 'Y-m-d H:s');
......@@ -134,9 +148,8 @@ function testBetween() {
/**