You are here

skinr_panels.test in Skinr 8.2

Same filename and directory in other branches
  1. 7.2 skinr_panels/tests/skinr_panels.test

Tests for the Skinr Panels module.

File

skinr_panels/tests/skinr_panels.test
View source
<?php

/**
 * @file
 * Tests for the Skinr Panels module.
 */

/**
 * Tests UI functionality for Panels plugin.
 */
class SkinrPanelsTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Plugins UI - Panels',
      'description' => 'Tests Skinr UI functionality for functionality plugin from Panels.',
      'dependencies' => array(
        'ctools',
        'page_manager',
        'panels',
        'panels_node',
        'panels_mini',
      ),
      'group' => 'Skinr',
    );
  }
  function setUp() {
    parent::setUp(array(
      'block',
      'page_manager',
      'panels_node',
      'panels_mini',
      'skinr_panels_test',
      'skinr_ui_test',
    ));
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer blocks',
      'use page manager',
      'administer page manager',
      'create mini panels',
      'administer mini panels',
      '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 panels plugin.
   *
   * @todo The below test doesn't work due to CTools/Panels not passing along
   *   enough data to create unique element ids when panels are in code. Skinr
   *   currently doesn't support panels in code.
   */
  function testPanelsDefault() {

    // Test panels pages.
    // Go to panel page.
    $this
      ->drupalGet('skinr-panels-test-panel');

    // Make sure our contextual link appears on the page.
    $this
      ->assertLinkByHref('admin/structure/skinr/edit/panels/pane__295dc791-d2a3-4f67-82e4-77c0b5ad671f/configure', 0, "Contexual link to edit pane's skin configuration on panel page (stored in code) was found.");
    $this
      ->drupalGet('admin/structure/mini-panels');

    // Test mini panels.
    // Add the mini block to the sidebar.
    $default_theme = variable_get('theme_default', 'bartik');
    db_merge('block')
      ->key(array(
      'theme' => $default_theme,
      'module' => 'panels_mini',
      'delta' => 'skinr_panels_test_mini_panel',
    ))
      ->fields(array(
      'status' => 1,
      'region' => 'sidebar_first',
      'pages' => '',
    ))
      ->execute();

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

    // Make sure our contextual link appears on the page.
    $this
      ->assertLinkByHref('admin/structure/skinr/edit/panels/pane__c9bf0f8f-e48a-42d7-9a38-7a6760791765/configure', 0, 'Contexual link to edit pane\'s skin configuration on mini panel (stored in code) was found.');

    // Make sure this panel's options are returned.
    $this
      ->drupalGet('admin/structure/skinr/add');
    $this
      ->assertOptionExists('element', 'pane__295dc791-d2a3-4f67-82e4-77c0b5ad671f', 'Panel pane was returned by panels_skinr_ui_element_options().');
  }

  /**
   * Tests panels plugin.
   */
  function testPanelsDatabase() {

    // Create a simple panel node.
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'panel',
      'panels_node' => array(
        'layout' => 'onecol',
        'css_id' => '',
        'pipeline' => 'standard',
      ),
    ));

    // Add a block to our panel node.
    $display = panels_load_display($node->panels_node['did']);
    $pane = panels_new_pane('block', 'system-user-menu', TRUE);
    $display
      ->add_pane($pane, 'middle');
    $this
      ->assertTrue(panels_save_display($display), 'Block was successfully added to panel node.');

    // 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/panels/pane__' . $pane->uuid . '/configure', 0, 'Contexual link to edit pane\'s skin configuration on panel node was found.');

    // Test panels pages.
    // Save page to DB.
    $task = page_manager_get_task('page');
    $handler = page_manager_load_task_handler($task, 'skinr_panels_test', 'page_skinr_panels_test_panel_context');
    page_manager_save_task_handler($handler);

    // Go to panel page.
    $this
      ->drupalGet('skinr-panels-test-panel');

    // Make sure our contextual link appears on the page.
    $this
      ->assertLinkByHref('admin/structure/skinr/edit/panels/pane__295dc791-d2a3-4f67-82e4-77c0b5ad671f/configure', 0, "Contexual link to edit pane's skin configuration on panel page (stored in DB) was found.");

    // Test mini panels.
    // Save mini panel to DB.
    $mini = panels_mini_load('skinr_panels_test_mini_panel');
    panels_mini_save($mini);

    // Add the mini block to the sidebar.
    $default_theme = variable_get('theme_default', 'bartik');
    db_merge('block')
      ->key(array(
      'theme' => $default_theme,
      'module' => 'panels_mini',
      'delta' => 'skinr_panels_test_mini_panel',
    ))
      ->fields(array(
      'status' => 1,
      'region' => 'sidebar_first',
      'pages' => '',
    ))
      ->execute();

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

    // Make sure our contextual link appears on the page.
    $this
      ->assertLinkByHref('admin/structure/skinr/edit/panels/pane__c9bf0f8f-e48a-42d7-9a38-7a6760791765/configure', 0, 'Contexual link to edit pane\'s skin configuration on mini panel (stored in DB) was found.');

    // Make sure this panel's options are returned.
    $this
      ->drupalGet('admin/structure/skinr/add');
    $this
      ->assertOptionExists('element', 'pane__' . $pane->uuid, 'Panel pane was returned by panels_skinr_ui_element_options().');

    // Test the returned element title.
    $skin = (object) array(
      'theme' => $default_theme,
      'module' => 'panels',
      'element' => 'pane__295dc791-d2a3-4f67-82e4-77c0b5ad671f',
      '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
      ->verbose($title);
    $this
      ->assertEqual($title, 'Pane <em class="placeholder">295dc791-d2a3-4f67-82e4-77c0b5ad671f</em> on <em class="placeholder">Panels test page</em>', 'Panel title was returned.');
  }

}

Classes

Namesort descending Description
SkinrPanelsTestCase Tests UI functionality for Panels plugin.