You are here

class SkinrUIPluginTestCase in Skinr 8.2

Same name and namespace in other branches
  1. 7.2 tests/skinr_ui.test \SkinrUIPluginTestCase

Tests UI functionality for Block plugin.

Hierarchy

Expanded class hierarchy of SkinrUIPluginTestCase

File

skinr_ui/src/Tests/skinr_ui.test, line 514
Tests for the Skinr UI module.

View source
class SkinrUIPluginTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Plugins UI - Core',
      'description' => 'Tests Skinr UI functionality for functionality plugins from Drupal core.',
      'group' => 'Skinr',
    );
  }
  function setUp() {
    parent::setUp(array(
      'block',
      'comment',
      'node',
      'skinr_ui',
      'skinr_ui_test',
    ));
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer blocks',
      'access comments',
      'access content',
      'post comments',
      'skip comment approval',
      'access contextual links',
      'administer skinr',
      'edit skin settings',
      'edit advanced skin settings',
      'bypass node access',
    ));
    $this
      ->drupalLogin($this->admin_user);
  }

  /**
   * Asserts that a select option in the current page exists.
   *
   * @param $name
   *   Id of select field to assert.
   * @param $option
   *   Option to assert.
   * @param $message
   *   Message to display.
   * @return
   *   TRUE on pass, FALSE on fail.
   */
  protected function assertOptionExists($name, $option, $message = '') {
    $elements = $this
      ->xpath('//select[@name=:name]//option[@value=:option]', array(
      ':name' => $name,
      ':option' => $option,
    ));
    return $this
      ->assertTrue(isset($elements[0]), $message ? $message : t('Option @option for field @name exists.', array(
      '@option' => $option,
      '@name' => $name,
    )), t('Browser'));
  }

  /**
   * Tests block plugin.
   */
  function testBlock() {

    // Enable user menu block for the first sidebar.
    // @see http://drupal.org/node/913086
    $default_theme = variable_get('theme_default', 'bartik');
    db_merge('block')
      ->key(array(
      'theme' => $default_theme,
      'module' => 'system',
      'delta' => 'user-menu',
    ))
      ->fields(array(
      'status' => 1,
      'region' => 'sidebar_first',
      'pages' => '',
    ))
      ->execute();

    // Get front page.
    $this
      ->drupalGet('');

    // Make sure our contextual link appears on the page.
    $this
      ->assertLinkByHref('admin/structure/skinr/edit/block/system__user-menu/configure', 0, 'Contexual link to edit block\'s skin configuration was found.');

    // Make sure this block's options are returned.
    $this
      ->drupalGet('admin/structure/skinr/add');
    $this
      ->assertOptionExists('element', 'system__user-menu', 'User menu block was returned by block_skinr_ui_element_options().');

    // Test the returned element title.
    $skin = (object) array(
      'theme' => $default_theme,
      'module' => 'block',
      'element' => 'system__user-menu',
      'skin' => 'skinr_ui_test_bgcolor',
      'options' => array(
        'bgcolor_red',
      ),
      'status' => 1,
    );
    skinr_skin_save($skin);
    $title = skinr_invoke_all('skinr_ui_element_title', $skin->module, $skin->element, $skin->theme);
    $title = reset($title);
    $this
      ->assertTrue($title == 'User menu', 'Block title was returned.');
  }

  /**
   * Tests comment plugin.
   */
  function testComment() {
    $default_theme = variable_get('theme_default', 'bartik');

    // Create a node.
    $node1 = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));

    // Go to node.
    $uri = entity_uri('node', $node1);
    $this
      ->drupalGet($uri['path']);

    // Add a comment to the node. With bartik the contextual links won't
    // display until there is at least one comment.
    $edit = array(
      'comment_body[und][0][value]' => $this
        ->randomString(128),
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));

    // Make sure our contextual link appears on the page.
    $this
      ->assertLinkByHref('admin/structure/skinr/edit/comment/page/configure', 0, 'Contexual link to edit comment\'s skin configuration was found.');

    // Make sure this block's options are returned.
    $this
      ->drupalGet('admin/structure/skinr/add');
    $this
      ->assertOptionExists('element', 'page', 'Node type was returned by node_skinr_ui_element_options().');

    // Test the returned element title.
    $skin = (object) array(
      'theme' => $default_theme,
      'module' => 'comment',
      'element' => 'page',
      'skin' => 'skinr_ui_test_bgcolor',
      'options' => array(
        'bgcolor_red',
      ),
      'status' => 1,
    );
    skinr_skin_save($skin);
    $title = skinr_invoke_all('skinr_ui_element_title', $skin->module, $skin->element, $skin->theme);
    $title = reset($title);
    $this
      ->assertEqual($title, 'Basic page', 'Node type title was returned.');
  }

  /**
   * Tests node plugin.
   */
  function testNode() {
    $default_theme = variable_get('theme_default', 'bartik');

    // Create a node.
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'article',
    ));

    // Go to node.
    $uri = entity_uri('node', $node);
    $this
      ->drupalGet($uri['path']);

    // Make sure our contextual link appears on the page.
    $this
      ->assertLinkByHref('admin/structure/skinr/edit/node/article/configure', 0, 'Contexual link to edit node\'s skin configuration was found.');

    // Make sure this block's options are returned.
    $this
      ->drupalGet('admin/structure/skinr/add');
    $this
      ->assertOptionExists('element', 'article', 'Node type was returned by node_skinr_ui_element_options().');

    // Test the returned element title.
    $skin = (object) array(
      'theme' => $default_theme,
      'module' => 'node',
      'element' => 'article',
      'skin' => 'skinr_ui_test_bgcolor',
      'options' => array(
        'bgcolor_red',
      ),
      'status' => 1,
    );
    skinr_skin_save($skin);
    $title = skinr_invoke_all('skinr_ui_element_title', $skin->module, $skin->element, $skin->theme);
    $title = reset($title);
    $this
      ->assertEqual($title, 'Article', 'Node type title was returned.');
  }

  /**
   * Tests node plugin.
   */
  function testSystem() {

    // @todo Add tests for html and region hooks.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SkinrUIPluginTestCase::assertOptionExists protected function Asserts that a select option in the current page exists.
SkinrUIPluginTestCase::getInfo public static function
SkinrUIPluginTestCase::setUp function
SkinrUIPluginTestCase::testBlock function Tests block plugin.
SkinrUIPluginTestCase::testComment function Tests comment plugin.
SkinrUIPluginTestCase::testNode function Tests node plugin.
SkinrUIPluginTestCase::testSystem function Tests node plugin.