You are here

function NodeDisplaysPlugins::testPlugins in Display Suite 6.3

Tests for plugins.

File

modules/nd/tests/nd.plugins.test, line 43
Tests for Node displays (plugins)

Class

NodeDisplaysPlugins
@file Tests for Node displays (plugins)

Code

function testPlugins() {
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer nodes',
    'access display suite',
    'administer nd',
    'configure layout for nd',
    'export and import settings',
    'revert overridden settings',
    'use PHP in custom fields',
    'administer blocks',
  ));
  $this
    ->drupalLogin($admin_user);
  $plugin_settings = variable_get('nd_plugin_settings', array());
  $this
    ->assertEqual($plugin_settings, array(), t('Plugin settings is empty'), t('Plugin tests'));

  // Enable the emptyregionrender plugin.
  $edit = array(
    'plugin_emptyregionrender' => TRUE,
  );
  $this
    ->drupalPost(DS_PATH_MODULES . '/nd/plugins', $edit, t('Save'));
  $plugin_settings = variable_get('nd_plugin_settings', array());
  $this
    ->assertTrue(isset($plugin_settings['emptyregionrender']), t('Empty region render enabled.'), t('Plugin tests'));
  $page_node = $this
    ->drupalCreateNode();

  // First post.
  $edit = array(
    'title[full][region]' => 'header',
    'author[full][region]' => 'middle',
    'body[full][region]' => 'middle',
  );
  $this
    ->drupalPost(DS_PATH_LAYOUT . '/page/full', $edit, t('Save'));

  // Test that footer is not rendered with the emptyregionrender plugin enabled.
  $this
    ->drupalGet('node/' . $page_node->nid);
  $this
    ->assertNoRaw('ds-region-footer', t('Footer is not rendered.'), t('Plugin tests'));

  // Save again.
  $edit = array(
    'title[full][region]' => 'header',
    'author[full][region]' => 'middle',
    'body[full][region]' => 'middle',
    'emptyregionrender[region-render-footer]' => TRUE,
  );
  $this
    ->drupalPost(DS_PATH_LAYOUT . '/page/full', $edit, t('Save'));

  // Test that footer is rendered with the emptyregionrender plugin enabled.
  $this
    ->drupalGet('node/' . $page_node->nid);
  $this
    ->assertRaw('nd-region-footer', t('Footer is rendered.'), t('Plugin tests'));

  // Enable the blocktoregion plugin.
  $edit = array(
    'plugin_emptyregionrender' => FALSE,
    'plugin_regiontoblock' => TRUE,
  );
  $this
    ->drupalPost(DS_PATH_MODULES . '/nd/plugins', $edit, t('Save'));
  $plugin_settings = variable_get('nd_plugin_settings', array());
  $this
    ->assertFalse(isset($plugin_settings['emptyregionrender']), t('Empty region render disabled.'), t('Plugin tests'));
  $this
    ->assertTrue(isset($plugin_settings['regiontoblock']), t('Region to block enabled.'), t('Plugin tests'));

  // Save full node display settings.
  $edit = array(
    'title[full][region]' => 'header',
    'body[full][region]' => 'middle',
    'author[full][region]' => 'right',
  );
  $this
    ->drupalPost(DS_PATH_LAYOUT . '/page/full', $edit, t('Save'));

  // Go to full node and make sure the right ds region is rendered.
  $this
    ->drupalGet('node/' . $page_node->nid);
  $this
    ->assertRaw('nd-region-right', t('Right region is rendered.'), t('Plugin tests'));

  // Save again but assign the right block to a region.
  $edit = array(
    'title[full][region]' => 'header',
    'body[full][region]' => 'middle',
    'author[full][region]' => 'right',
    'regiontoblock[region-block-right]' => TRUE,
  );
  $this
    ->drupalPost(DS_PATH_LAYOUT . '/page/full', $edit, t('Save'));

  // Go to blocks page and put this region into right sidebar.
  $edit = array(
    'ds_b4bd9b390ca7a23ee5c8f8d1858c1ed8[region]' => 'right',
  );
  $this
    ->drupalPost('admin/build/block', $edit, t('Save blocks'));

  // Go to full node and assert the right region is not rendered but the block is.
  $this
    ->drupalGet('node/' . $page_node->nid);
  $this
    ->assertNoRaw('nd-region-right', t('Right region is not rendered.'), t('Plugin tests'));
  $this
    ->assertRaw('id="block-ds-b4bd9b390ca7a23ee5c8f8d1858c1ed8"', t('Block is rendered'), t('Plugin tests'));
  $this
    ->assertRaw('<div class="field field-author">' . $admin_user->name . '</div>', t('Author name rendered'), t('Plugin tests'));
}