Commit 3380c465 authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1754244 by dawehner: Add a generic testcase for the field base.

parent be82cf3b
......@@ -268,6 +268,7 @@ function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
function get_elements() {
static $elements = NULL;
if (!isset($elements)) {
// @todo Add possible html5 elements.
$elements = variable_get('views_field_rewrite_elements', array(
'' => t('- Use default -'),
'0' => t('- None -'),
......
api_version: '3.0'
base_table: views_test
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
access:
type: none
cache:
type: none
exposed_form:
type: basic
pager:
type: full
query:
type: views_query
row_plugin: fields
style_plugin: default
fields:
name:
id: name
table: views_test
field: name
name_1:
id: name_1
table: views_test
field: name
name_2:
id: name_2
table: views_test
field: name
job:
id: job
table: views_test
field: job
display_plugin: default
display_title: Defaults
id: default
position: '0'
name: test_field_tokens
tag: ''
api_version: '3.0'
base_table: views_test
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
fields:
id:
id: id
table: views_test
field: id
name:
id: name
table: views_test
field: name
created:
id: created
table: views_test
field: created
display_options:
access:
type: none
cache:
type: none
style_plugin: table
style_options:
info:
id:
sortable: 1
default_sort_order: asc
name:
sortable: 1
default_sort_order: desc
created:
sortable: 0
display_plugin: default
display_title: Master
id: default
position: '0'
page_1:
display_options:
path: test_click_sort
display_plugin: page
display_title: Page
id: page_1
position: '0'
human_name: { }
name: test_click_sort
tag: ''
api_version: '3.0'
base_table: views_test
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
access:
type: none
cache:
type: none
fields:
id:
id: id
table: views_test
field: id
style_plugin: html_list
display_plugin: default
display_title: Master
id: default
position: '0'
page_1:
display_options:
path: test_field_classes
display_plugin: page
display_title: Page
id: page_1
position: '0'
human_name: { }
name: test_field_classes
tag: ''
api_version: '3.0'
base_table: views_test
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
access:
type: none
cache:
type: none
fields:
name:
id: name
table: views_test
field: name
style_plugin: html_list
display_plugin: default
display_title: Master
id: default
position: '0'
human_name: ""
name: test_field_output
tag: ''
<?php
/**
* @file
* Definition of Drupal\views_test_data\Plugin\views\field\FieldTest.
*/
namespace Drupal\views_test_data\Plugin\views\field;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\views\Plugin\views\field\FieldPluginBase;
/**
* @Plugin(
* id = "test_field",
* title = @Translation("Test field plugin"),
* help = @Translation("Provides a generic field test plugin.")
* )
*/
class FieldTest extends FieldPluginBase {
/**
* A temporary stored test value for the test.
*
* @var string
*/
protected $testValue;
/**
* Sets the testValue property.
*
* @param string $value
* The test value to set.
*/
public function setTestValue($value) {
$this->testValue = $value;
}
/**
* Returns the testValue property.
*
* @return string
*/
public function getTestValue() {
return $this->testValue;
}
/**
* Overrides Drupal\views\Plugin\views\field\FieldPluginBase::add_self_tokens().
*/
function add_self_tokens(&$tokens, $item) {
$tokens['[test-token]'] = $this->getTestValue();
}
/**
* Overrides Drupal\views\Plugin\views\field\FieldPluginBase::render().
*/
function render($values) {
return $this->sanitizeValue($this->getTestValue());
}
}
......@@ -11,3 +11,27 @@
function views_test_data_schema() {
return variable_get('views_test_schema', array());
}
/**
* Implements hook_install().
*/
function views_test_data_install() {
// Add the marquee tag to possible html elements to test the field handler.
$default_values = array(
'' => t('- Use default -'),
'0' => t('- None -'),
'div' => 'DIV',
'span' => 'SPAN',
'h1' => 'H1',
'h2' => 'H2',
'h3' => 'H3',
'h4' => 'H4',
'h5' => 'H5',
'h6' => 'H6',
'p' => 'P',
'strong' => 'STRONG',
'em' => 'EM',
);
$default_values['marquee'] = 'MARQUEE';
variable_set('views_field_rewrite_elements', $default_values);
}
......@@ -2382,7 +2382,6 @@ function _field_view_formatter_options($field_type = NULL) {
function views_trim_text($alter, $value) {
if (drupal_strlen($value) > $alter['max_length']) {
$value = drupal_substr($value, 0, $alter['max_length']);
// TODO: replace this with cleanstring of ctools
if (!empty($alter['word_boundary'])) {
$regex = "(.*)\b.+";
if (function_exists('mb_ereg')) {
......@@ -2400,6 +2399,7 @@ function views_trim_text($alter, $value) {
$value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
if (!empty($alter['ellipsis'])) {
// @todo: What about changing this to a real ellipsis?
$value .= t('...');
}
}
......
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