Commit f200debb authored by tim.plunkett's avatar tim.plunkett

Issue #1760586 by tim.plunkett: Refactor and reorganize the tests.

parent 3e354810
......@@ -10,12 +10,12 @@
/**
* Tests the views analyze system.
*/
class AnalyzeTest extends ViewsSqlTest {
class AnalyzeTest extends ViewTestBase {
public static function getInfo() {
return array(
'name' => 'Views Analyze',
'description' => 'Test the views analyze system.',
'description' => 'Tests the views analyze system.',
'group' => 'Views',
);
}
......@@ -46,4 +46,5 @@ function testAnalyzeBasic() {
// This redirects the user back to the main views edit page.
$this->drupalPost(NULL, array(), t('Ok'));
}
}
......@@ -10,15 +10,22 @@
/**
* Basic test class for Views query builder tests.
*/
class BasicTest extends ViewsSchemaTestBase {
class BasicTest extends ViewTestBase {
public static function getInfo() {
return array(
'name' => 'Basic query test',
'name' => 'Basic query tests',
'description' => 'A basic query test for Views.',
'group' => 'Views'
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
/**
* Tests a trivial result set.
*/
......@@ -177,4 +184,5 @@ public function testSimpleArgument() {
'views_test_age' => 'age',
));
}
}
<?php
/**
* @file
* Definition of Drupal\views\Tests\Comment\ArgumentUserUIDTest.
*/
namespace Drupal\views\Tests\Comment;
use Drupal\views\View;
/**
* Tests the argument_comment_user_uid handler.
*/
class ArgumentUserUIDTest extends CommentTestBase {
public static function getInfo() {
return array(
'name' => 'Comment: User UID Argument',
'description' => 'Tests the user posted or commented argument handler.',
'group' => 'Views Modules',
);
}
function testCommentUserUIDTest() {
$view = $this->view_comment_user_uid();
$this->executeView($view, array($this->account->uid));
$result_set = array(
array(
'nid' => $this->node_user_posted->nid,
),
array(
'nid' => $this->node_user_commented->nid,
),
);
$this->column_map = array('nid' => 'nid');
$this->assertIdenticalResultset($view, $result_set, $this->column_map);
}
}
......@@ -2,75 +2,40 @@
/**
* @file
* Definition of Drupal\views\Tests\Comment\ArgumentCommentUserUidTest.
* Definition of Drupal\views\Tests\Comment\CommentTestBase.
*/
namespace Drupal\views\Tests\Comment;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\View;
/**
* Tests the argument_comment_user_uid handler.
*/
class ArgumentCommentUserUidTest extends ViewsSqlTest {
protected $profile = 'standard';
abstract class CommentTestBase extends ViewTestBase {
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 entity_create('comment', $comment)->save();
}
protected $profile = 'standard';
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.
// 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,
),
$comment = array(
'uid' => $this->loggedInUser->uid,
'nid' => $this->node_user_commented->nid,
'cid' => '',
'pid' => '',
);
$this->column_map = array('nid' => 'nid');
debug($view->result);
$this->assertIdenticalResultset($view, $resultset, $this->column_map);
entity_create('comment', $comment)->save();
}
function view_comment_user_uid() {
......@@ -110,4 +75,5 @@ function view_comment_user_uid() {
return $view;
}
}
......@@ -2,21 +2,24 @@
/**
* @file
* Definition of Drupal\views\Tests\Comment\FilterCommentUserUidTest.
* Definition of Drupal\views\Tests\Comment\FilterUserUIDTest.
*/
namespace Drupal\views\Tests\Comment;
use Drupal\views\View;
/**
* Tests the filter_comment_user_uid handler.
*
* The actual stuff is done in the parent class.
*/
class FilterCommentUserUidTest extends ArgumentCommentUserUidTest {
class FilterUserUIDTest extends CommentTestBase {
public static function getInfo() {
return array(
'name' => 'Tests handler filter_comment_user_uid',
'description' => 'Tests the user posted or commented filter handler',
'name' => 'Comment: User UID Filter',
'description' => 'Tests the user posted or commented filter handler.',
'group' => 'Views Modules',
);
}
......@@ -40,4 +43,21 @@ function view_comment_user_uid() {
return $view;
}
function testCommentUserUIDTest() {
$view = $this->view_comment_user_uid();
$this->executeView($view, array($this->account->uid));
$result_set = array(
array(
'nid' => $this->node_user_posted->nid,
),
array(
'nid' => $this->node_user_commented->nid,
),
);
$this->column_map = array('nid' => 'nid');
$this->assertIdenticalResultset($view, $result_set, $this->column_map);
}
}
......@@ -10,7 +10,7 @@
/**
* Test the produced views_data.
*/
class ApiDataTest extends ApiTestBase {
class ApiDataTest extends FieldTestBase {
/**
* Stores the fields for this test case.
*/
......@@ -18,8 +18,8 @@ class ApiDataTest extends ApiTestBase {
public static function getInfo() {
return array(
'name' => 'Fieldapi: Views Data',
'description' => 'Tests the fieldapi views data.',
'name' => 'Field: Views Data',
'description' => 'Tests the Field Views data.',
'group' => 'Views Modules',
);
}
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\views\Test\Field\ApiTestHelper.
* Definition of Drupal\views\Test\Field\FieldTestBase.
*/
/**
......@@ -18,12 +18,13 @@
namespace Drupal\views\Tests\Field;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\Tests\ViewTestBase;
/**
* Provides some helper methods for testing fieldapi integration into views.
*/
abstract class ApiTestBase extends ViewsSqlTest {
abstract class FieldTestBase extends ViewTestBase {
protected $profile = 'standard';
/**
......@@ -71,4 +72,5 @@ function clearViewsCaches() {
$cache = NULL;
$recursion_protection = NULL;
}
}
......@@ -17,13 +17,13 @@
* Check locale:disabled, locale:enabled and locale:enabled with another language
* Check revisions
*/
class HandlerFieldFieldTest extends ApiTestBase {
class HandlerFieldFieldTest extends FieldTestBase {
public $nodes;
public static function getInfo() {
return array(
'name' => 'Fieldapi: Field handler',
'description' => 'Tests the field itself of the fieldapi integration',
'name' => 'Field: Field handler',
'description' => 'Tests the field itself of the Field integration.',
'group' => 'Views Modules'
);
}
......
......@@ -10,11 +10,11 @@
/**
* Tests glossary view ( summary of arguments ).
*/
class GlossaryTest extends ViewsSqlTest {
class GlossaryTest extends ViewTestBase {
public static function getInfo() {
return array(
'name' => 'Glossary Test',
'name' => 'Glossary tests',
'description' => 'Tests glossary functionality of views.',
'group' => 'Views',
);
......@@ -56,4 +56,5 @@ public function testGlossaryView() {
$this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
}
}
}
......@@ -7,14 +7,12 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the text area handler.
*
* @see views_handler_area_text
*/
class AreaTextTest extends ViewsSchemaTestBase {
class AreaTextTest extends HandlerTestBase {
public static function getInfo() {
return array(
......@@ -24,6 +22,12 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
public function testAreaText() {
$view = $this->getBasicView();
......
......@@ -7,12 +7,11 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the core Drupal\views\Plugin\views\argument\Null handler.
*/
class ArgumentNullTest extends ViewsSchemaTestBase {
class ArgumentNullTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Argument: Null',
......@@ -21,6 +20,12 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test']['id']['argument']['id'] = 'null';
......
......@@ -7,13 +7,12 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\View;
/**
* Tests the core Drupal\views\Plugin\views\argument\String handler.
*/
class ArgumentStringTest extends ViewsSqlTest {
class ArgumentStringTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Argument: String',
......
......@@ -7,12 +7,11 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Boolean handler.
*/
class FieldBooleanTest extends ViewsSchemaTestBase {
class FieldBooleanTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Field: Boolean',
......@@ -21,6 +20,12 @@ 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();
......@@ -77,4 +82,5 @@ public function testFieldBoolean() {
$this->assertEqual(t('Test-True'), $view->field['age']->advanced_render($view->result[1]));
}
}
......@@ -7,12 +7,11 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the Drupal\views\Plugin\views\field\Counter handler.
*/
class FieldCounterTest extends ViewsSchemaTestBase {
class FieldCounterTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Field: Counter',
......@@ -21,6 +20,12 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function testSimple() {
$view = $this->getBasicView();
$view->display['default']->handler->override_option('fields', array(
......@@ -71,4 +76,5 @@ function testSimple() {
// @TODO: Write tests for pager.
function testPager() {
}
}
......@@ -7,12 +7,11 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Custom handler.
*/
class FieldCustomTest extends ViewsSchemaTestBase {
class FieldCustomTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Field: Custom',
......@@ -21,6 +20,12 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test']['name']['field']['id'] = 'custom';
......@@ -48,4 +53,5 @@ public function testFieldCustom() {
$this->assertEqual($random, $view->style_plugin->get_field(0, 'name'));
}
}
......@@ -7,12 +7,11 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Date handler.
*/
class FieldDateTest extends ViewsSchemaTestBase {
class FieldDateTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Field: Date',
......@@ -21,6 +20,12 @@ public static function getInfo() {
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test']['created']['field']['id'] = 'date';
......@@ -88,4 +93,5 @@ protected function assertRenderedDatesEqual($view, $map, $timezone = NULL) {
$this->assertEqual($expected_result, $actual_result, $message);
}
}
}
......@@ -7,22 +7,27 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\FileSize handler.
*
* @see CommonXssUnitTest
*/
class FieldFileSizeTest extends ViewsSchemaTestBase {
class FieldFileSizeTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Field: file_size',
'name' => 'Field: File size',
'description' => 'Test the core Drupal\views\Plugin\views\field\FileSize handler.',
'group' => 'Views Handlers',
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function dataSet() {
$data = parent::dataSet();
$data[0]['age'] = 0;
......@@ -65,4 +70,5 @@ public function testFieldFileSize() {
$this->assertEqual($view->field['age']->advanced_render($view->result[2]), 1000);
$this->assertEqual($view->field['age']->advanced_render($view->result[3]), 10000);
}
}
......@@ -7,14 +7,13 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the generic field handler
*
* @see views_handler_field
*/
class FieldTest extends ViewsSchemaTestBase {
class FieldTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Field',
......@@ -25,6 +24,9 @@ public static function getInfo() {
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->column_map = array(
'views_test_name' => 'name',
);
......
......@@ -7,19 +7,25 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Url handler.
*/
class FieldUrlTest extends ViewsSchemaTestBase {
class FieldUrlTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Field: Url',
'name' => 'Field: URL',
'description' => 'Test the core Drupal\views\Plugin\views\field\Url handler.',
'group' => 'Views Handlers',
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test']['name']['field']['id'] = 'url';
......@@ -60,4 +66,5 @@ public function testFieldUrl() {
$this->assertEqual(l('John', 'John'), $view->field['name']->advanced_render($view->result[0]));
}
}
......@@ -7,22 +7,27 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the core Drupal\views\Plugin\views\field\Xss handler.
*
* @see CommonXssUnitTest
*/
class FieldXssTest extends ViewsSchemaTestBase {
class FieldXssTest extends HandlerTestBase {
public static function getInfo() {
return array(
'name' => 'Field: Xss',
'name' => 'Field: XSS',
'description' => 'Test the core Drupal\views\Plugin\views\field\Xss handler.',
'group' => 'Views Handlers',
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function dataHelper() {
$map = array(
'John' => 'John',
......@@ -61,4 +66,5 @@ public function testFieldXss() {
$counter++;
}
}
}
......@@ -7,12 +7,11 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSchemaTestBase;
/**
* Tests the combine filter handler.
*/
class FilterCombineTest extends ViewsSchemaTestBase {
class FilterCombineTest extends HandlerTestBase {
var $column_map = array();
public static function getInfo() {
......@@ -25,6 +24,9 @@ public static function getInfo() {
function setUp() {
parent::setUp();
$this->enableViewsTestModule();
$this->column_map = array(
'views_test_name' => 'name',
'views_test_job' => 'job',
......@@ -106,4 +108,5 @@ protected function schemaDefinition() {
unset($schema['views_test']['fields']['job']['not null']);
return $schema;
}
}
......@@ -7,13 +7,13 @@
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewsSqlTest;
use Drupal\views\View;
/**
* Tests the core Drupal\views\Plugin\views\filter\Date handler.
*/