first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,264 @@
<?php
/**
* @file
* Definition of ViewsPluginStyleTestCase.
*/
/**
* Tests some general style plugin related functionality.
*/
class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase {
public static function getInfo() {
return array(
'name' => 'Styles',
'description' => 'Test general style functionality.',
'group' => 'Views Plugins',
);
}
/**
* Tests the grouping legacy features of styles.
*/
function testGroupingLegacy() {
$view = $this->getBasicView();
// Setup grouping by the job.
$view->init_display();
$view->init_style();
$view->style_plugin->options['grouping'] = 'job';
// Reduce the amount of items to make the test a bit easier.
// Set up the pager.
$view->display['default']->handler->override_option('pager', array(
'type' => 'some',
'options' => array('items_per_page' => 3),
));
// Add the job field .
$view->display['default']->handler->override_option('fields', array(
'name' => array(
'id' => 'name',
'table' => 'views_test',
'field' => 'name',
'relationship' => 'none',
),
'job' => array(
'id' => 'job',
'table' => 'views_test',
'field' => 'job',
'relationship' => 'none',
),
));
// Now run the query and groupby the result.
$this->executeView($view);
// This is the old way to call it.
$sets = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping']);
$expected = array();
// Use Job: as label, so be sure that the label is used for groupby as well.
$expected['Job: Singer'] = array();
$expected['Job: Singer'][0] = new StdClass();
$expected['Job: Singer'][0]->views_test_name = 'John';
$expected['Job: Singer'][0]->views_test_job = 'Singer';
$expected['Job: Singer'][0]->views_test_id = '1';
$expected['Job: Singer'][1] = new StdClass();
$expected['Job: Singer'][1]->views_test_name = 'George';
$expected['Job: Singer'][1]->views_test_job = 'Singer';
$expected['Job: Singer'][1]->views_test_id = '2';
$expected['Job: Drummer'] = array();
$expected['Job: Drummer'][2] = new StdClass();
$expected['Job: Drummer'][2]->views_test_name = 'Ringo';
$expected['Job: Drummer'][2]->views_test_job = 'Drummer';
$expected['Job: Drummer'][2]->views_test_id = '3';
$this->assertEqual($sets, $expected, t('The style plugin should proper group the results with grouping by the rendered output.'));
$expected = array();
$expected['Job: Singer'] = array();
$expected['Job: Singer']['group'] = 'Job: Singer';
$expected['Job: Singer']['rows'][0] = new StdClass();
$expected['Job: Singer']['rows'][0]->views_test_name = 'John';
$expected['Job: Singer']['rows'][0]->views_test_job = 'Singer';
$expected['Job: Singer']['rows'][0]->views_test_id = '1';
$expected['Job: Singer']['rows'][1] = new StdClass();
$expected['Job: Singer']['rows'][1]->views_test_name = 'George';
$expected['Job: Singer']['rows'][1]->views_test_job = 'Singer';
$expected['Job: Singer']['rows'][1]->views_test_id = '2';
$expected['Job: Drummer'] = array();
$expected['Job: Drummer']['group'] = 'Job: Drummer';
$expected['Job: Drummer']['rows'][2] = new StdClass();
$expected['Job: Drummer']['rows'][2]->views_test_name = 'Ringo';
$expected['Job: Drummer']['rows'][2]->views_test_job = 'Drummer';
$expected['Job: Drummer']['rows'][2]->views_test_id = '3';
// The newer api passes the value of the grouping as well.
$sets_new_rendered = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], TRUE);
$sets_new_value = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], FALSE);
$this->assertEqual($sets_new_rendered, $expected, t('The style plugins should proper group the results with grouping by the rendered output.'));
// Reorder the group structure to group by value.
$expected['Singer'] = $expected['Job: Singer'];
$expected['Drummer'] = $expected['Job: Drummer'];
unset($expected['Job: Singer']);
unset($expected['Job: Drummer']);
$this->assertEqual($sets_new_value, $expected, t('The style plugins should proper group the results with grouping by the value.'));
}
function testGrouping() {
$this->_testGrouping(FALSE);
$this->_testGrouping(TRUE);
}
/**
* Tests the grouping features of styles.
*/
function _testGrouping($stripped = FALSE) {
$view = $this->getBasicView();
// Setup grouping by the job and the age field.
$view->init_display();
$view->init_style();
$view->style_plugin->options['grouping'] = array(
array('field' => 'job'),
array('field' => 'age'),
);
// Reduce the amount of items to make the test a bit easier.
// Set up the pager.
$view->display['default']->handler->override_option('pager', array(
'type' => 'some',
'options' => array('items_per_page' => 3),
));
// Add the job and age field.
$view->display['default']->handler->override_option('fields', array(
'name' => array(
'id' => 'name',
'table' => 'views_test',
'field' => 'name',
'relationship' => 'none',
),
'job' => array(
'id' => 'job',
'table' => 'views_test',
'field' => 'job',
'relationship' => 'none',
),
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
),
));
// Now run the query and groupby the result.
$this->executeView($view);
$expected = array();
$expected['Job: Singer'] = array();
$expected['Job: Singer']['group'] = 'Job: Singer';
$expected['Job: Singer']['rows']['Age: 25'] = array();
$expected['Job: Singer']['rows']['Age: 25']['group'] = 'Age: 25';
$expected['Job: Singer']['rows']['Age: 25']['rows'][0] = new StdClass();
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_name = 'John';
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_job = 'Singer';
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_age = '25';
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_id = '1';
$expected['Job: Singer']['rows']['Age: 27'] = array();
$expected['Job: Singer']['rows']['Age: 27']['group'] = 'Age: 27';
$expected['Job: Singer']['rows']['Age: 27']['rows'][1] = new StdClass();
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_name = 'George';
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_job = 'Singer';
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_age = '27';
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_id = '2';
$expected['Job: Drummer'] = array();
$expected['Job: Drummer']['group'] = 'Job: Drummer';
$expected['Job: Drummer']['rows']['Age: 28'] = array();
$expected['Job: Drummer']['rows']['Age: 28']['group'] = 'Age: 28';
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2] = new StdClass();
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_name = 'Ringo';
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_job = 'Drummer';
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_age = '28';
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_id = '3';
// Alter the results to support the stripped case.
if ($stripped) {
// Add some html to the result and expected value.
$rand = '<a data="' . $this->randomName() . '" />';
$view->result[0]->views_test_job .= $rand;
$expected['Job: Singer']['rows']['Age: 25']['rows'][0]->views_test_job = 'Singer' . $rand;
$expected['Job: Singer']['group'] = 'Job: Singer';
$rand = '<a data="' . $this->randomName() . '" />';
$view->result[1]->views_test_job .= $rand;
$expected['Job: Singer']['rows']['Age: 27']['rows'][1]->views_test_job = 'Singer' . $rand;
$rand = '<a data="' . $this->randomName() . '" />';
$view->result[2]->views_test_job .= $rand;
$expected['Job: Drummer']['rows']['Age: 28']['rows'][2]->views_test_job = 'Drummer' . $rand;
$expected['Job: Drummer']['group'] = 'Job: Drummer';
$view->style_plugin->options['grouping'][0] = array('field' => 'job', 'rendered' => TRUE, 'rendered_strip' => TRUE);
$view->style_plugin->options['grouping'][1] = array('field' => 'age', 'rendered' => TRUE, 'rendered_strip' => TRUE);
}
// The newer api passes the value of the grouping as well.
$sets_new_rendered = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], TRUE);
$this->assertEqual($sets_new_rendered, $expected, t('The style plugins should proper group the results with grouping by the rendered output.'));
// Don't test stripped case, because the actual value is not stripped.
if (!$stripped) {
$sets_new_value = $view->style_plugin->render_grouping($view->result, $view->style_plugin->options['grouping'], FALSE);
// Reorder the group structure to grouping by value.
$expected['Singer'] = $expected['Job: Singer'];
$expected['Singer']['rows']['25'] = $expected['Job: Singer']['rows']['Age: 25'];
$expected['Singer']['rows']['27'] = $expected['Job: Singer']['rows']['Age: 27'];
$expected['Drummer'] = $expected['Job: Drummer'];
$expected['Drummer']['rows']['28'] = $expected['Job: Drummer']['rows']['Age: 28'];
unset($expected['Job: Singer']);
unset($expected['Singer']['rows']['Age: 25']);
unset($expected['Singer']['rows']['Age: 27']);
unset($expected['Job: Drummer']);
unset($expected['Drummer']['rows']['Age: 28']);
$this->assertEqual($sets_new_value, $expected, t('The style plugins should proper group the results with grouping by the value.'));
}
}
/**
* Tests custom css classes.
*/
function testCustomRowClasses() {
$view = $this->getBasicView();
// Setup some random css class.
$view->init_display();
$view->init_style();
$random_name = $this->randomName();
$view->style_plugin->options['row_class'] = $random_name . " test-token-[name]";
$rendered_output = $view->preview();
$this->storeViewPreview($rendered_output);
$rows = $this->elements->body->div->div->div;
$count = 0;
foreach ($rows as $row) {
$attributes = $row->attributes();
$class = (string) $attributes['class'][0];
$this->assertTrue(strpos($class, $random_name) !== FALSE, 'Take sure that a custom css class is added to the output.');
// Check token replacement.
$name = $view->field['name']->get_value($view->result[$count]);
$this->assertTrue(strpos($class, "test-token-$name") !== FALSE, 'Take sure that a token in custom css class is replaced.');
$count++;
}
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* @file
* Definition of ViewsPluginStyleTestBase.
*/
/**
* Provides a base foundation for testing style plugins.
*/
abstract class ViewsPluginStyleTestBase extends ViewsSqlTest {
/**
* Stores the SimpleXML representation of the output.
*
* @var SimpleXMLElement
*/
protected $elements;
/**
* Stores a view output in the elements.
*/
function storeViewPreview($output) {
$htmlDom = new DOMDocument();
@$htmlDom->loadHTML($output);
if ($htmlDom) {
// It's much easier to work with simplexml than DOM, luckily enough
// we can just simply import our DOM tree.
$this->elements = simplexml_import_dom($htmlDom);
}
}
}

View File

@@ -0,0 +1,151 @@
<?php
/**
* @file
* Definition of viewsPluginStyleJumpMenuTest.
*/
/**
* Tests jump menu style functionality.
*/
class viewsPluginStyleJumpMenuTest extends ViewsSqlTest {
/**
* Stores all created nodes.
*
* @var array
*/
var $nodes;
public static function getInfo() {
return array(
'name' => 'Jump menu',
'description' => 'Test jump menu style functionality.',
'group' => 'Views Plugins',
);
}
public function setUp() {
parent::setUp();
$this->nodes = array();
$this->nodes['page'][] = $this->drupalCreateNode(array('type' => 'page'));
$this->nodes['page'][] = $this->drupalCreateNode(array('type' => 'page'));
$this->nodes['story'][] = $this->drupalCreateNode(array('type' => 'story'));
$this->nodes['story'][] = $this->drupalCreateNode(array('type' => 'story'));
$this->nodeTitles = array($this->nodes['page'][0]->title, $this->nodes['page'][1]->title, $this->nodes['story'][0]->title, $this->nodes['story'][1]->title);
}
/**
* Tests jump menues with more then one same path but maybe differnet titles.
*/
function testDuplicatePaths() {
$view = $this->getJumpMenuView();
$view->set_display();
$view->init_handlers();
// Setup a [path] which would leed to "duplicate" paths, but still the shouldn't be used for grouping.
$view->field['nothing']->options['alter']['text'] = '[path]';
$view->preview();
$form = $view->style_plugin->render($view->result);
// As there is no grouping setup it should be 4 elements.
$this->assertEqual(count($form['jump']['#options']), 4 + 1);
// Check that all titles are part of the form as well.
$options = array_values($form['jump']['#options']);
foreach ($options as $key => $title) {
// The first one is the choose label.
if ($key == 0) {
continue;
}
$this->assertTrue($this->nodeTitles[$key - 1] == trim($title), t('Title @title should appear on the jump list, as we do not filter', array('@title' => $title)));
}
}
function getJumpMenuView() {
$view = new view;
$view->name = 'test_jump_menu';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'test_jump_menu';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'jump_menu';
$handler->display->display_options['style_options']['hide'] = 0;
$handler->display->display_options['style_options']['path'] = 'nothing';
$handler->display->display_options['style_options']['default_value'] = 0;
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['link_to_node'] = 1;
/* Field: Content: Type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'node';
$handler->display->display_options['fields']['type']['field'] = 'type';
$handler->display->display_options['fields']['type']['exclude'] = 1;
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['alter']['text'] = '[type]';
$handler->display->display_options['fields']['nothing']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['external'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['html'] = 0;
$handler->display->display_options['fields']['nothing']['element_label_colon'] = 1;
$handler->display->display_options['fields']['nothing']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nothing']['hide_empty'] = 0;
$handler->display->display_options['fields']['nothing']['empty_zero'] = 0;
$handler->display->display_options['fields']['nothing']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['nothing']['exclude'] = 1;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
return $view;
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* @file
* Definition of ViewsPluginStyleMappingTest.
*/
/**
* Tests the default/mapping row style.
*/
class ViewsPluginStyleMappingTest extends ViewsPluginStyleTestBase {
public static function getInfo() {
return array(
'name' => 'Style: Mapping',
'description' => 'Test mapping style functionality.',
'group' => 'Views Plugins',
);
}
public function setUp() {
parent::setUp();
// Reset the plugin data.
views_fetch_plugin_data(NULL, NULL, TRUE);
}
protected function viewsPlugins() {
return array(
'style' => array(
'test_mapping' => array(
'title' => t('Field mapping'),
'help' => t('Maps specific fields to specific purposes.'),
'handler' => 'views_test_plugin_style_test_mapping',
'path' => drupal_get_path('module', 'views_test') . '/test_plugins',
'theme' => 'views_view_mapping_test',
'theme path' => drupal_get_path('module', 'views_test'),
'theme file' => 'views_test.module',
'uses row plugin' => FALSE,
'uses fields' => TRUE,
'uses options' => TRUE,
'uses grouping' => FALSE,
'type' => 'normal',
),
),
);
}
/**
* Overrides ViewsTestCase::getBasicView().
*/
protected function getBasicView() {
$view = parent::getBasicView();
$view->display['default']->handler->override_option('style_plugin', 'test_mapping');
$view->display['default']->handler->override_option('style_options', array(
'mapping' => array(
'name_field' => 'name',
'numeric_field' => array(
'age',
),
'title_field' => 'name',
'toggle_numeric_field' => TRUE,
'toggle_title_field' => TRUE,
),
));
$view->display['default']->handler->override_option('fields', array(
'age' => array(
'id' => 'age',
'table' => 'views_test',
'field' => 'age',
'relationship' => 'none',
),
'name' => array(
'id' => 'name',
'table' => 'views_test',
'field' => 'name',
'relationship' => 'none',
),
'job' => array(
'id' => 'job',
'table' => 'views_test',
'field' => 'job',
'relationship' => 'none',
),
));
return $view;
}
/**
* Verifies that the fields were mapped correctly.
*/
public function testMappedOutput() {
$view = $this->getBasicView();
$output = $this->mappedOutputHelper($view);
$this->assertTrue(strpos($output, 'job') === FALSE, 'The job field is added to the view but not in the mapping.');
$view = $this->getBasicView();
$view->display['default']->display_options['style_options']['mapping']['name_field'] = 'job';
$output = $this->mappedOutputHelper($view);
$this->assertTrue(strpos($output, 'job') !== FALSE, 'The job field is added to the view and is in the mapping.');
}
/**
* Tests the mapping of fields.
*
* @param view $view
* The view to test.
*
* @return string
* The view rendered as HTML.
*/
protected function mappedOutputHelper($view) {
$rendered_output = $view->preview();
$this->storeViewPreview($rendered_output);
$rows = $this->elements->body->div->div->div;
$data_set = $this->dataSet();
$count = 0;
foreach ($rows as $row) {
$attributes = $row->attributes();
$class = (string) $attributes['class'][0];
$this->assertTrue(strpos($class, 'views-row-mapping-test') !== FALSE, 'Make sure that each row has the correct CSS class.');
foreach ($row->div as $field) {
// Split up the field-level class, the first part is the mapping name
// and the second is the field ID.
$field_attributes = $field->attributes();
$name = strtok((string) $field_attributes['class'][0], '-');
$field_id = strtok('-');
// The expected result is the mapping name and the field value,
// separated by ':'.
$expected_result = $name . ':' . $data_set[$count][$field_id];
$actual_result = (string) $field;
$this->assertIdentical($expected_result, $actual_result, format_string('The fields were mapped successfully: %name => %field_id', array('%name' => $name, '%field_id' => $field_id)));
}
$count++;
}
return $rendered_output;
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* @file
* Definition of ViewsPluginStyleUnformattedTestCase.
*/
/**
* Tests the default/unformatted row style.
*/
class ViewsPluginStyleUnformattedTestCase extends ViewsPluginStyleTestBase {
public static function getInfo() {
return array(
'name' => 'Style: unformatted',
'description' => 'Test unformatted style functionality.',
'group' => 'Views Plugins',
);
}
/**
* Take sure that the default css classes works as expected.
*/
function testDefaultRowClasses() {
$view = $this->getBasicView();
$rendered_output = $view->preview();
$this->storeViewPreview($rendered_output);
$rows = $this->elements->body->div->div->div;
$count = 0;
$count_result = count($view->result);
foreach ($rows as $row) {
$count++;
$attributes = $row->attributes();
$class = (string) $attributes['class'][0];
// Take sure that each row has a row css class.
$this->assertTrue(strpos($class, "views-row-$count") !== FALSE, 'Take sure that each row has a row css class.');
// Take sure that the odd/even classes are set right.
$odd_even = $count % 2 == 0 ? 'even' : 'odd';
$this->assertTrue(strpos($class, "views-row-$odd_even") !== FALSE, 'Take sure that the odd/even classes are set right.');
if ($count == 1) {
$this->assertTrue(strpos($class, "views-row-first") !== FALSE, 'Take sure that the first class is set right.');
}
else if ($count == $count_result) {
$this->assertTrue(strpos($class, "views-row-last") !== FALSE, 'Take sure that the last class is set right.');
}
$this->assertTrue(strpos($class, 'views-row') !== FALSE, 'Take sure that the views row class is set right.');
}
}
}