Commit 4abfc832 authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1754220 by dawehner: Add a generic testcase for the area base.

parent 0bdc693c
......@@ -33,7 +33,7 @@ abstract class AreaPluginBase extends HandlerBase {
public function init(&$view, &$options) {
$this->setOptionDefaults($this->options, $this->defineOptions());
parent::init($view, $options);
if ($this->handler_type == 'empty') {
if ($this->definition['plugin_type'] == 'empty') {
$this->options['empty'] = TRUE;
}
}
......@@ -43,7 +43,7 @@ public function init(&$view, &$options) {
*/
public function label() {
if (!isset($this->options['label'])) {
return $this->admin_label();
return $this->adminLabel();
}
return $this->options['label'];
}
......
<?php
/**
* @file
* Definition of Drupal\views\Tests\Handler\AreaTest.
*/
namespace Drupal\views\Tests\Handler;
/**
* Tests the abstract area handler.
*
* @see Drupal\views\Plugin\views\area\AreaPluginBase
* @see Drupal\views_test\Plugin\views\area\TestExample
*/
class AreaTest extends HandlerTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('views_ui');
public static function getInfo() {
return array(
'name' => 'Area: Base',
'description' => 'Test the plugin base of the area handler.',
'group' => 'Views Handlers',
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
protected function viewsData() {
$data = parent::viewsData();
$data['views']['test_example'] = array(
'title' => 'Test Example area',
'help' => 'A area handler which just exists for tests.',
'area' => array(
'id' => 'test_example'
)
);
return $data;
}
/**
* Tests the generic UI of a area handler.
*/
public function testUI() {
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
$this->drupalLogin($admin_user);
$types = array('header', 'footer', 'empty');
$labels = array();
foreach ($types as $type) {
$edit_path = 'admin/structure/views/nojs/config-item/test_example_area/default/' . $type .'/test_example';
// First setup an empty label.
$this->drupalPost($edit_path, array(), t('Apply'));
$this->assertText('Test Example area');
// Then setup a no empty label.
$labels[$type] = $this->randomName();
$this->drupalPost($edit_path, array('options[label]' => $labels[$type]), t('Apply'));
// Make sure that the new label appears on the site.
$this->assertText($labels[$type]);
// Test that the settings (empty/label) are accessible.
$this->drupalGet($edit_path);
$this->assertField('options[label]');
if ($type !== 'empty') {
$this->assertField('options[empty]');
}
}
}
/**
* Tests the rendering of an area.
*/
public function testRenderArea() {
$view = views_get_view('test_example_area');
$view->initDisplay();
$view->initHandlers();
// Insert a random string to the test area plugin and see whether it is
// rendered for both header, footer and empty text.
$header_string = $this->randomString();
$footer_string = $this->randomString();
$empty_string = $this->randomString();
$view->header['test_example']->options['string'] = $header_string;
$view->footer['test_example']->options['string'] = $footer_string;
$view->empty['test_example']->options['string'] = $empty_string;
// Check whether the strings exists in the output.
$output = $view->preview();
$this->assertTrue(strpos($output, $header_string) !== FALSE);
$this->assertTrue(strpos($output, $footer_string) !== FALSE);
$this->assertTrue(strpos($output, $empty_string) !== FALSE);
}
}
......@@ -10,7 +10,7 @@
/**
* Tests the text area handler.
*
* @see views_handler_area_text
* @see Drupal\views\Plugin\views\area\Text
*/
class AreaTextTest extends HandlerTestBase {
......
......@@ -9,6 +9,9 @@
/**
* Basic test for pluggable access.
*
* @todo It probably make sense to split the test up by one for role/perm/none
* and the two generic ones.
*/
class AccessTest extends PluginTestBase {
......@@ -83,6 +86,8 @@ function testAccessRole() {
/**
* Tests static access check.
*
* @see Drupal\views_test\Plugin\views\access\StaticTest
*/
function testStaticAccessPlugin() {
$view = $this->createViewFromConfig('test_access_static');
......@@ -109,6 +114,8 @@ function testStaticAccessPlugin() {
/**
* Tests dynamic access plugin.
*
* @see Drupal\views_test\Plugin\views\access\DyamicTest
*/
function testDynamicAccessPlugin() {
$view = $this->createViewFromConfig('test_access_dynamic');
......
api_version: '3.0'
base_table: node
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
access:
type: none
cache:
type: none
header:
test_example:
field: test_example
id: test_example
table: views
footer:
test_example:
field: test_example
id: test_example
table: views
empty:
test_example:
field: test_example
id: test_example
table: views
display_plugin: default
display_title: Master
id: default
position: '0'
human_name: { }
name: test_example_area
tag: ''
<?php
/**
* @file
* Definition of Drupal\views_test_data\Plugin\views\area\TestExample
*/
namespace Drupal\views_test_data\Plugin\views\area;
use Drupal\views\Plugin\views\area\AreaPluginBase;
use Drupal\Core\Annotation\Plugin;
/**
* Test area plugin.
*
* @see Drupal\views\Tests\Handler\AreaTest
*
* @Plugin(
* id = "test_example"
* )
*/
class TestExample extends AreaPluginBase {
/**
* Overrides Drupal\views\Plugin\views\area\AreaPluginBase::option_definition().
*/
public function defineOptions() {
$options = parent::defineOptions();
$options['string'] = array('default' => '');
return $options;
}
/**
* Overrides Drupal\views\Plugin\views\area\AreaPluginBase::render().
*/
public function render($empty = FALSE) {
return $this->options['string'];
}
}
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