summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles
diff options
context:
space:
mode:
Diffstat (limited to 'kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles')
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style.test16
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_base.test33
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test8
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_mapping.test144
-rw-r--r--kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test22
5 files changed, 187 insertions, 36 deletions
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style.test b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style.test
index 87f5b7d..dfc5413 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style.test
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style.test
@@ -8,7 +8,7 @@
/**
* Tests some general style plugin related functionality.
*/
-class ViewsPluginStyleTestCase extends ViewsSqlTest {
+class ViewsPluginStyleTestCase extends ViewsPluginStyleTestBase {
public static function getInfo() {
return array(
'name' => 'Styles',
@@ -232,20 +232,6 @@ class ViewsPluginStyleTestCase extends ViewsSqlTest {
}
}
-
- /**
- * 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);
- }
- }
-
/**
* Tests custom css classes.
*/
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_base.test b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_base.test
new file mode 100644
index 0000000..514077d
--- /dev/null
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_base.test
@@ -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);
+ }
+ }
+
+}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test
index 9a53bfc..dd4eca0 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_jump_menu.test
@@ -9,6 +9,14 @@
* 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',
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_mapping.test b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_mapping.test
new file mode 100644
index 0000000..5785075
--- /dev/null
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_mapping.test
@@ -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;
+ }
+
+}
diff --git a/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test
index 20b7b4d..0c0e882 100644
--- a/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test
+++ b/kolab.org/www/drupal-7.18/sites/all/modules/views/tests/styles/views_plugin_style_unformatted.test
@@ -8,14 +8,7 @@
/**
* Tests the default/unformatted row style.
*/
-class ViewsPluginStyleUnformattedTestCase extends ViewsSqlTest {
-
- /**
- * Stores all created nodes.
- *
- * @var array
- */
- var $nodes;
+class ViewsPluginStyleUnformattedTestCase extends ViewsPluginStyleTestBase {
public static function getInfo() {
return array(
@@ -26,19 +19,6 @@ class ViewsPluginStyleUnformattedTestCase extends ViewsSqlTest {
}
/**
- * 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);
- }
- }
-
- /**
* Take sure that the default css classes works as expected.
*/
function testDefaultRowClasses() {