views_table_highlighter_content_taxonomy.test in Views Table Highlighter 6
Test Views Table Highlighter's interaction with Content Taxonomy.
File
tests/views_table_highlighter_content_taxonomy.testView source
<?php
/**
* @file
* Test Views Table Highlighter's interaction with Content Taxonomy.
*/
class ViewsTableHighlighterContentTaxonomyTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'views_table_highlighter content_taxonomy',
'description' => 'Ensure that views_table_highlighter and content_taxonomy function properly together.',
'group' => 'Views',
);
}
public function setUp() {
parent::setUp('content', 'option_widgets', 'content_taxonomy', 'content_taxonomy_options', 'views', 'views_table_highlighter');
// make sure our immediate dependencies are enabled, since parent::setUp() doesn't check this for us
$this
->assertTrue(module_exists('content_taxonomy_options'), "content_taxonomy_options.module isn't installed");
$this
->assertTrue(module_exists('views'), "views.module isn't installed");
// create a content type to populate
$content_type = $this
->drupalCreateContentType(array(
'type' => 'views_table_highlighter_test',
));
$this
->assertEqual($content_type->type, 'views_table_highlighter_test', "views_table_highlighter_test content type creation failed");
// create a vocabulary for this content type
$vocab = array(
'name' => 'test_vocabulary',
'nodes' => array(
'views_table_highlighter_test',
),
);
$status = taxonomy_save_vocabulary($vocab);
$this
->assertEqual($status, SAVED_NEW, "vocabulary creation failed");
// ...and some terms
$term = array(
'vid' => $vocab->vid,
'name' => 'alpha',
);
$status = taxonomy_save_term($term);
$this
->assertEqual($status, SAVED_NEW, "alpha term creation failed");
$term = array(
'vid' => $vocab->vid,
'name' => 'beta',
);
$status = taxonomy_save_term($term);
$this
->assertEqual($status, SAVED_NEW, "beta term creation failed");
// add a field to our new content type
$field_test_number = array(
'field_name' => 'field_test_term',
'type_name' => 'views_table_highlighter_test',
'type' => 'content_taxonomy',
'vid' => $vocab->vid,
'widget' => array(
'type' => 'content_taxonomy_select',
),
);
content_field_instance_create($field_test_number);
$created_field = content_fields('field_test_term', 'views_table_highlighter_test');
$this
->assertEqual($created_field['field_name'], 'field_test_term', "views_table_highlighter_test field creation failed");
// create some sample content
$terms = array(
'alpha',
'beta',
);
foreach ($terms as $term) {
$term_data = taxonomy_get_term_by_name($term);
$settings = array(
'type' => 'views_table_highlighter_test',
'field_test_term' => array(
'0' => array(
'value' => $term_data[0]->tid,
),
),
);
$node = $this
->drupalCreateNode($settings);
$this
->assertEqual($node->type, 'views_table_highlighter_test', "views_table_highlighter_test node creation failed");
$this
->assertEqual($node->field_test_term[0]['value'], $term_data[0]->tid, "views_table_highlighter_test node field data failed");
}
// add a view
$view = new view();
$view->name = 'views_table_highlighter_test';
$view->base_table = 'node';
$view->core = 6;
$view->api_version = '2';
$handler = $view
->new_display('default', 'Defaults', 'default');
$handler
->override_option('fields', array(
'field_test_term_value' => array(
'id' => 'field_test_term_value',
'table' => 'node_data_field_test_term',
'field' => 'field_test_term_value',
),
));
$handler
->override_option('items_per_page', 0);
$handler
->override_option('style_plugin', 'table_highlighter');
$handler
->override_option('style_options', array(
'views_table_highlighter' => array(
'code' => '$term = taxonomy_get_term_by_name("beta");
if ($node_data_field_test_term_field_test_term_value==$term[0]->tid) return "red";',
),
));
$view
->save();
$this
->assertNotNull(views_get_view('views_table_highlighter_test'), "views_table_highlighter_test view creation failed");
}
public function testNumberField() {
$this
->drupalSetContent(views_embed_view('views_table_highlighter_test'));
$rows = $this
->xpath("//table/tbody/tr");
// since we have 2 nodes, our table should have 2 rows.
$this
->assertEqual(2, count($rows), "view result doesn't have 2 rows");
// row 0 should be unlit
$attr = $rows[0]
->attributes();
$this
->assertEqual($attr['class'], 'odd views-row-first', "row 0 doesn't have the correct classes");
// row 1 should be red
$attr = $rows[1]
->attributes();
$this
->assertEqual($attr['class'], 'even views-row-last views-table-highlighter-red', "row 1 doesn't have the correct classes");
}
}
Classes
Name | Description |
---|---|
ViewsTableHighlighterContentTaxonomyTestCase | @file Test Views Table Highlighter's interaction with Content Taxonomy. |