Commit cd5a483b authored by webchick's avatar webchick

Issue #1828642 by tim.plunkett, xjm, dawehner: Convert as many Views tests as...

Issue #1828642 by tim.plunkett, xjm, dawehner: Convert as many Views tests as possible to DrupalUnitTestBase.
parent 0ee01627
......@@ -10,7 +10,7 @@
/**
* Basic test class for Views query builder tests.
*/
class BasicTest extends ViewTestBase {
class BasicTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -20,17 +20,12 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
/**
* Tests a trivial result set.
*/
public function testSimpleResultSet() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// Execute the view.
$this->executeView($view);
......@@ -47,7 +42,8 @@ public function testSimpleResultSet() {
* Tests filtering of the result set.
*/
public function testSimpleFiltering() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// Add a filter.
$view->displayHandlers['default']->overrideOption('filters', array(
......@@ -105,7 +101,8 @@ public function testSimpleFiltering() {
* Tests simple argument.
*/
public function testSimpleArgument() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// Add a argument.
$view->displayHandlers['default']->overrideOption('arguments', array(
......
......@@ -7,12 +7,14 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the text area handler.
*
* @see Drupal\views\Plugin\views\area\Text
*/
class AreaTextTest extends HandlerTestBase {
class AreaTextTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -25,11 +27,13 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->enableModules(array('system'));
$this->enableModules(array('filter'));
}
public function testAreaText() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// add a text header
$string = $this->randomName();
......
......@@ -7,10 +7,12 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\argument\Null handler.
*/
class ArgumentNullTest extends HandlerTestBase {
class ArgumentNullTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -20,12 +22,6 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['id']['argument']['id'] = 'null';
......@@ -35,7 +31,8 @@ function viewsData() {
public function testAreaText() {
// Test validation
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// Add a null argument.
$string = $this->randomString();
......@@ -60,7 +57,8 @@ public function testAreaText() {
$this->assertTrue($view->argument['null']->validateArgument(NULL), 'must_not_be returns TRUE, if there is no argument');
// Test execution.
$view = $this->getView();
$view->destroy();
$view->setDisplay();
// Add a argument, which has null as handler.
$string = $this->randomString();
......
......@@ -7,10 +7,12 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Boolean handler.
*/
class FieldBooleanTest extends HandlerTestBase {
class FieldBooleanTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -20,12 +22,6 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function dataSet() {
// Use default dataset but remove the age from john and paul
$data = parent::dataSet();
......@@ -41,7 +37,8 @@ function viewsData() {
}
public function testFieldBoolean() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('fields', array(
'age' => array(
......
......@@ -7,10 +7,12 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the Drupal\views\Plugin\views\field\Counter handler.
*/
class FieldCounterTest extends HandlerTestBase {
class FieldCounterTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -23,11 +25,12 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->enableModules(array('user'));
}
function testSimple() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('fields', array(
'counter' => array(
'id' => 'counter',
......@@ -44,7 +47,6 @@ function testSimple() {
));
$view->preview();
$counter = $view->style_plugin->rendered_fields[0]['counter'];
$this->assertEqual($counter, 1, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', array('@expected' => 1, '@counter' => $counter)));
$counter = $view->style_plugin->rendered_fields[1]['counter'];
......@@ -53,7 +55,7 @@ function testSimple() {
$this->assertEqual($counter, 3, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', array('@expected' => 3, '@counter' => $counter)));
$view->destroy();
$view = $this->getView();
$view->setDisplay();
$rand_start = rand(5, 10);
$view->displayHandlers['default']->overrideOption('fields', array(
'counter' => array(
......
......@@ -7,10 +7,12 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Custom handler.
*/
class FieldCustomTest extends HandlerTestBase {
class FieldCustomTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -20,12 +22,6 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['name']['field']['id'] = 'custom';
......@@ -33,7 +29,8 @@ function viewsData() {
}
public function testFieldCustom() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// Alter the text of the field to a random string.
$random = $this->randomName();
......
......@@ -7,10 +7,12 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Date handler.
*/
class FieldDateTest extends HandlerTestBase {
class FieldDateTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -20,12 +22,6 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['created']['field']['id'] = 'date';
......@@ -33,7 +29,8 @@ function viewsData() {
}
public function testFieldDate() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('fields', array(
'created' => array(
......
......@@ -7,12 +7,14 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\FileSize handler.
*
* @see CommonXssUnitTest
*/
class FieldFileSizeTest extends HandlerTestBase {
class FieldFileSizeTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -22,12 +24,6 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function dataSet() {
$data = parent::dataSet();
$data[0]['age'] = 0;
......@@ -46,7 +42,8 @@ function viewsData() {
}
public function testFieldFileSize() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('fields', array(
'age' => array(
......
......@@ -7,10 +7,12 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Url handler.
*/
class FieldUrlTest extends HandlerTestBase {
class FieldUrlTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -20,12 +22,6 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['name']['field']['id'] = 'url';
......@@ -33,7 +29,8 @@ function viewsData() {
}
public function testFieldUrl() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('fields', array(
'name' => array(
......@@ -51,7 +48,7 @@ public function testFieldUrl() {
// Make the url a link.
$view->destroy();
$view = $this->getView();
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('fields', array(
'name' => array(
......
......@@ -7,12 +7,14 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Xss handler.
*
* @see CommonXssUnitTest
*/
class FieldXssTest extends HandlerTestBase {
class FieldXssTest extends ViewUnitTestBase {
public static function getInfo() {
return array(
......@@ -22,12 +24,6 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function dataHelper() {
$map = array(
'John' => 'John',
......@@ -47,7 +43,8 @@ function viewsData() {
}
public function testFieldXss() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('fields', array(
'name' => array(
......
......@@ -7,12 +7,17 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the combine filter handler.
*/
class FilterCombineTest extends HandlerTestBase {
class FilterCombineTest extends ViewUnitTestBase {
var $column_map = array();
protected $column_map = array(
'views_test_data_name' => 'name',
'views_test_data_job' => 'job',
);
public static function getInfo() {
return array(
......@@ -22,30 +27,19 @@ public static function getInfo() {
);
}
function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->column_map = array(
'views_test_data_name' => 'name',
'views_test_data_job' => 'job',
);
}
protected function getBasicView() {
$view = parent::getBasicView();
$view->displayHandlers['default']->display['display_options']['fields']['job'] = array(
'id' => 'job',
'table' => 'views_test_data',
'field' => 'job',
'relationship' => 'none',
);
return $view;
}
public function testFilterCombineContains() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
$fields = $view->displayHandlers['default']->getOption('fields');
$view->displayHandlers['default']->overrideOption('fields', $fields + array(
'job' => array(
'id' => 'job',
'table' => 'views_test_data',
'field' => 'job',
'relationship' => 'none',
),
));
// Change the filtering.
$view->displayHandlers['default']->overrideOption('filters', array(
......
......@@ -7,10 +7,16 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\filter\Equality handler.
*/
class FilterEqualityTest extends HandlerTestBase {
class FilterEqualityTest extends ViewUnitTestBase {
protected $column_map = array(
'views_test_data_name' => 'name',
);
public static function getInfo() {
return array(
......@@ -20,25 +26,22 @@ public static function getInfo() {
);
}
function setUp() {
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->column_map = array(
'views_test_data_name' => 'name',
);
$this->enableModules(array('system'));
$this->enableModules(array('menu'));
}
function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['name']['filter']['id'] = 'equality';
return $data;
}
function testEqual() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// Change the filtering
$view->displayHandlers['default']->overrideOption('filters', array(
......@@ -63,7 +66,8 @@ function testEqual() {
public function testEqualGroupedExposed() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
$view = views_get_view('test_view');
$view->storage->newDisplay('page', 'Page', 'page_1');
// Filter: Name, Operator: =, Value: Ringo
$filters['name']['group_info']['default_group'] = 1;
......@@ -80,7 +84,8 @@ public function testEqualGroupedExposed() {
}
function testNotEqual() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// Change the filtering
$view->displayHandlers['default']->overrideOption('filters', array(
......@@ -114,7 +119,8 @@ function testNotEqual() {
public function testEqualGroupedNotExposed() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
$view = views_get_view('test_view');
$view->storage->newDisplay('page', 'Page', 'page_1');
// Filter: Name, Operator: !=, Value: Ringo
$filters['name']['group_info']['default_group'] = 2;
......
......@@ -7,10 +7,17 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the core Drupal\views\Plugin\views\filter\InOperator handler.
*/
class FilterInOperatorTest extends HandlerTestBase {
class FilterInOperatorTest extends ViewUnitTestBase {
protected $column_map = array(
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
);
public static function getInfo() {
return array(
......@@ -23,18 +30,19 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->enableModules(array('system'));
$this->enableModules(array('menu'));
}
function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['age']['filter']['id'] = 'in_operator';
return $data;
}
public function testFilterInOperatorSimple() {
$view = $this->getView();
$view = views_get_view('test_view');
$view->setDisplay();
// Add a in_operator ordering.
$view->displayHandlers['default']->overrideOption('filters', array(
......@@ -61,12 +69,10 @@ public function testFilterInOperatorSimple() {
);
$this->assertEqual(2, count($view->result));
$this->assertIdenticalResultset($view, $expected_result, array(
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
));
$this->assertIdenticalResultset($view, $expected_result, $this->column_map);
$view = $this->getView();
$view->destroy();
$view->setDisplay();
// Add a in_operator ordering.
$view->displayHandlers['default']->overrideOption('filters', array(
......@@ -97,20 +103,17 @@ public function testFilterInOperatorSimple() {
);
$this->assertEqual(3, count($view->result));
$this->assertIdenticalResultset($view, $expected_result, array(
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
));
$this->assertIdenticalResultset($view, $expected_result, $this->column_map);
}
public function testFilterInOperatorGroupedExposedSimple() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
$view = views_get_view('test_view');
// Filter: Age, Operator: in, Value: 26, 30
$filters['age']['group_info']['default_group'] = 1;
$view->setDisplay('page_1');
$view->displayHandlers['page_1']->overrideOption('filters', $filters);
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('filters', $filters);
$this->executeView($view);
......@@ -126,20 +129,17 @@ public function testFilterInOperatorGroupedExposedSimple() {
);
$this->assertEqual(2, count($view->result));
$this->assertIdenticalResultset($view, $expected_result, array(
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
));
$this->assertIdenticalResultset($view, $expected_result, $this->column_map);
}
public function testFilterNotInOperatorGroupedExposedSimple() {
$filters = $this->getGroupedExposedFilters();
$view = $this->getBasicPageView();
$view = views_get_view('test_view');
// Filter: Age, Operator: in, Value: 26, 30
$filters['age']['group_info']['default_group'] = 2;
$view->setDisplay('page_1');
$view->displayHandlers['page_1']->overrideOption('filters', $filters);
$view->setDisplay();
$view->displayHandlers['default']->overrideOption('filters', $filters);
$this->executeView($view);
......@@ -159,10 +159,7 @@ public function testFilterNotInOperatorGroupedExposedSimple() {
);
$this->assertEqual(3, count($view->result));
$this->assertIdenticalResultset($view, $expected_result, array(
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
));
$this->assertIdenticalResultset($view, $expected_result, $this->column_map);
}
protected function getGroupedExposedFilters() {
......
......@@ -7,12 +7,17 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewUnitTestBase;
/**
* Tests the numeric filter handler.
*/
class FilterNumericTest extends HandlerTestBase {
class FilterNumericTest extends ViewUnitTestBase {
var $column_map = array();
protected $column_map = array(
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
);
public static function getInfo() {
return array(
......@@ -22,15 +27,11 @@ public static function getInfo() {
);
}
function setUp() {
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->column_map = array(
'views_test_data_name' => 'name',
'views_test_data_age' => 'age',
);
$this->enableModules(array('system'));
$this->enableModules(array('menu