Commit ef1f2eac authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1754264 by dawehner: Add a generic testcase for the style base.

parent 8e11815b
......@@ -11,6 +11,8 @@
/**
* Tests some general style plugin related functionality.
*
* @see Drupal\views_test_data\Plugin\views\style\StyleTest.
*/
class StyleTest extends StyleTestBase {
......@@ -22,6 +24,41 @@ public static function getInfo() {
);
}
/**
* Tests the general renderering of styles.
*/
public function testStyle() {
$view = $this->getView();
$view->display_handler->setOption('style_plugin', 'test_style');
$view->initDisplay();
$view->initStyle();
$this->assertTrue($view->style_plugin instanceof \Drupal\views_test_data\Plugin\views\style\StyleTest, 'Make sure the right style plugin class is loaded.');
$random_text = $this->randomName();
// Set some custom text to the output and make sure that this value is
// rendered.
$view->style_plugin->setOutput($random_text);
$output = $view->preview();
$this->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the style plugin appears in the output of the view.');
// This run use the test row plugin and render with it.
$view = $this->getView();
$view->display_handler->setOption('style_plugin', 'test_style');
$view->display_handler->setOption('row_plugin', 'test_row');
$view->initDisplay();
$view->initStyle();
$view->style_plugin->setUsesRowPlugin(TRUE);
// Reinitialize the style as it supports row plugins now.
$view->style_plugin->init($view, $view->display[$view->current_display], array());
$this->assertTrue($view->style_plugin->row_plugin instanceof \Drupal\views_test_data\Plugin\views\row\RowTest, 'Make sure the right row plugin class is loaded.');
$random_text = $this->randomName();
$view->style_plugin->row_plugin->setOutput($random_text);
$output = $view->preview();
$this->assertTrue(strpos($output, $random_text) !== FALSE, 'Take sure that the rendering of the row plugin appears in the output of the view.');
}
/**
* Tests the grouping legacy features of styles.
*/
......
<?php
/**
* @file
* Definition of Drupal\views_test_data\Plugin\views\row\RowTest.
*/
namespace Drupal\views_test_data\Plugin\views\row;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\views\Plugin\views\row\RowPluginBase;
/**
* Provides a general test row plugin.
*
* @ingroup views_row_plugins
*
* @Plugin(
* id = "test_row",
* title = @Translation("Test row plugin"),
* help = @Translation("Provides a generic row test plugin."),
* theme = "views_view_row_test",
* type = "normal"
* )
*/
class RowTest extends RowPluginBase {
/**
* A string which will be output when the view is rendered.
*
* @var string
*/
public $output;
/**
* Sets the output property.
*
* @param string $output
* The string to output by this plugin.
*/
public function setOutput($output) {
$this->output = $output;
}
/**
* Returns the output property.
*
* @return string
*/
public function getOutput() {
return $this->output;
}
/**
* Overrides Drupal\views\Plugin\views\row\RowPluginBase::render()
*/
public function render($row) {
return $this->getOutput();
}
}
<?php
/**
* @file
* Definition of Drupal\views_test_data\Plugin\views\style\StyleTest.
*/
namespace Drupal\views_test_data\Plugin\views\style;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\views\Plugin\views\style\StylePluginBase;
/**
* Provides a general test style plugin.
*
* @ingroup views_style_plugins
*
* @Plugin(
* id = "test_style",
* title = @Translation("Test style plugin"),
* help = @Translation("Provides a generic style test plugin."),
* theme = "views_view_style_test",
* type = "normal"
* )
*/
class StyleTest extends StylePluginBase {
/**
* A string which will be output when the view is rendered.
*
* @var string
*/
public $output;
function usesRowPlugin() {
return parent::usesRowPlugin();
}
/**
* Sets the usesRowPlugin property.
*
* @param bool $status
* TRUE if this style plugin should use rows.
*/
public function setUsesRowPlugin($status) {
$this->usesRowPlugin = $status;
}
/**
* Sets the output property.
*
* @param string $output
* The string to output by this plugin.
*/
public function setOutput($output) {
$this->output = $output;
}
/**
* Returns the output property.
*
* @return string
*/
public function getOutput() {
return $this->output;
}
/**
* Overrides Drupal\views\Plugin\views\style\StylePluginBase::render()
*/
public function render() {
$output = '';
if (!$this->usesRowPlugin()) {
$output = $this->getOutput();
}
else {
foreach ($this->view->result as $index => $row) {
$this->view->row_index = $index;
$output .= $this->row_plugin->render($row) . "\n";
}
}
return $output;
}
}
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