You are here

class SkinrUIPluginViewsTestCase in Skinr 8.2

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

Tests UI functionality for Block plugin.

Hierarchy

Expanded class hierarchy of SkinrUIPluginViewsTestCase

File

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

View source
class SkinrUIPluginViewsTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Plugins UI - Views',
      'description' => 'Tests Skinr UI functionality for functionality plugin from Views.',
      'dependencies' => array(
        'views',
        'views_ui',
      ),
      'group' => 'Skinr',
    );
  }
  function setUp() {
    parent::setUp(array(
      'views_ui',
      'skinr_ui_test',
    ));
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer views',
      'access all views',
      'access contextual links',
      'administer skinr',
      'edit skin settings',
      'edit advanced skin settings',
    ));
    $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 views plugin.
   */
  function testViews() {
    $default_theme = variable_get('theme_default', 'bartik');

    // Go to the view's page.
    $this
      ->drupalGet('skinr-ui-test-view');

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

    // Make sure this view's options are returned.
    $this
      ->drupalGet('admin/structure/skinr/add');
    $this
      ->assertOptionExists('element', 'skinr_ui_test__default', 'Default display for our view was returned by views_skinr_ui_element_options().');
    $this
      ->assertOptionExists('element', 'skinr_ui_test__page', 'Page display for our view was returned by views_skinr_ui_element_options().');

    // Test the returned element title.
    $skin = (object) array(
      'theme' => $default_theme,
      'module' => 'views',
      'element' => 'skinr_ui_test__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, 'Skinr UI Test', 'View title was returned.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SkinrUIPluginViewsTestCase::assertOptionExists protected function Asserts that a select option in the current page exists.
SkinrUIPluginViewsTestCase::getInfo public static function
SkinrUIPluginViewsTestCase::setUp function
SkinrUIPluginViewsTestCase::testViews function Tests views plugin.