You are here

public function ViewsTableHighlighterContentTaxonomyTestCase::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_content_taxonomy.test, line 17
Test Views Table Highlighter's interaction with Content Taxonomy.

Class

ViewsTableHighlighterContentTaxonomyTestCase
@file Test Views Table Highlighter's interaction with Content Taxonomy.

Code

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");
}