public function ViewsTableHighlighterTestCase::setUp in Views Table Highlighter 6
Generates a random database prefix, runs the install scripts on the prefixed database and enable the specified modules. After installation many caches are flushed and the internal browser is setup so that the page requests will run on the new prefix. A temporary files directory is created with the same name as the database prefix.
Parameters
...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.
Overrides DrupalWebTestCase::setUp
File
- tests/
views_table_highlighter.test, line 17 - Test Views Table Highlighter.
Class
- ViewsTableHighlighterTestCase
- @file Test Views Table Highlighter.
Code
public function setUp() {
parent::setUp('content', 'number', 'views', 'views_table_highlighter');
// make sure our immediate dependencies are enabled, since parent::setUp() doesn't check this for us
$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");
// add a field to our new content type
$field_test_number = array(
'field_name' => 'field_test_number',
'type_name' => 'views_table_highlighter_test',
'type' => 'number_integer',
'widget' => array(
'type' => 'number',
),
);
content_field_instance_create($field_test_number);
$created_field = content_fields('field_test_number', 'views_table_highlighter_test');
$this
->assertEqual($created_field['field_name'], 'field_test_number', "views_table_highlighter_test field creation failed");
// create some sample content
$numbers = array(
1,
2,
3,
);
foreach ($numbers as $number) {
$settings = array(
'type' => 'views_table_highlighter_test',
'field_test_number' => array(
'0' => array(
'value' => $number,
),
),
);
$node = $this
->drupalCreateNode($settings);
$this
->assertEqual($node->type, 'views_table_highlighter_test', "views_table_highlighter_test node creation failed");
$this
->assertEqual($node->field_test_number[0]['value'], $number, "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_number_value' => array(
'id' => 'field_test_number_value',
'table' => 'node_data_field_test_number',
'field' => 'field_test_number_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' => 'if ($node_data_field_test_number_field_test_number_value > 2) return \'red\';
if ($node_data_field_test_number_field_test_number_value == 2) return \'blue\';',
),
));
$view
->save();
$this
->assertNotNull(views_get_view('views_table_highlighter_test'), "views_table_highlighter_test view creation failed");
}