1 layout.test LayoutInterfaceTest::testTaxonomyContext()

Tests Taxonomy contexts within layouts.

File

core/modules/layout/tests/layout.test, line 1753
Tests for the Layout module.

Class

LayoutInterfaceTest
Tests the interface for adding, removing, and moving blocks.

Code

function testTaxonomyContext() {
  module_enable(array('taxonomy'));

  // Create a default vocabulary named "Tags", enabled for the 'post' content type.
  $vocabulary = new TaxonomyVocabulary(array(
    'name' => 'Tags',
    'description' => 'Use tags to group posts on similar topics into categories.',
    'machine_name' => 'tags',
  ));
  taxonomy_vocabulary_save($vocabulary);

  $field = array(
    'field_name' => 'field_' . $vocabulary->machine_name,
    'type' => 'taxonomy_term_reference',
    // Set cardinality to unlimited for tagging.
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);

  $instance = array(
    'field_name' => 'field_' . $vocabulary->machine_name,
    'entity_type' => 'node',
    'label' => 'Tags',
    'bundle' => 'post',
    'widget' => array(
      'type' => 'taxonomy_autocomplete',
    ),
  );
  field_create_instance($instance);

  // Make a new layout that creates a custom path with placeholders.
  $layout_title = $this->randomName();
  $layout_name = strtolower($layout_title);
  $layout_path = 'taxonomy/term/%';
  $edit = array(
    'title' => $layout_title,
    'name' => $layout_name,
    'layout_template' => 'moscone_flipped',
    'path' => $layout_path,
  );
  // Check the path first to populate available contexts.
  $this->backdropPost('admin/structure/layouts/add', $edit, t('Check path'));

  // Try to add a condition to the layout itself to only show on the Tag
  // vocabulary.
  $this->backdropPost(NULL, array(), t('Add visibility condition'));

  $this->backdropPost(NULL, array('condition' => 'taxonomy_term_vocabulary'), t('Load condition'));
  $this->backdropPost(NULL, array('bundles[tags]' => TRUE), t('Add visibility condition'));
  $this->backdropPost(NULL, array(), t('Create layout'));

  $this->assertText(t('Layout created. Blocks may now be added to this layout.'));
}