You are here

skinr_context_ui.test in Skinr 8.2

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

Tests for the Skinr UI module.

File

skinr_context/tests/skinr_context_ui.test
View source
<?php

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

/**
 * Base class for Skinr Context UI tests.
 */
class SkinrContextUITestCase extends SkinrUITestCase {
  protected $profile = 'testing';
  function setUp() {
    $modules = func_get_args();
    if (isset($modules[0]) && is_array($modules[0])) {
      $modules = $modules[0];
    }
    parent::setUp(array_merge(array(
      'skinr_context',
      'skinr_context_ui',
    ), $modules));
  }

}

/**
 * Tests UI functionality.
 */
class SkinrContextUIBasicTestCase extends SkinrContextUITestCase {
  public static function getInfo() {
    return array(
      'name' => 'Context UI',
      'description' => 'Tests administrative Skinr Context UI functionality.',
      'dependencies' => array(
        'ctools',
        'context',
        'context_ui',
      ),
      'group' => 'Skinr',
    );
  }
  function setUp() {
    parent::setUp(array(
      'skinr_test',
      'skinr_context_test_default',
    ));
  }

  /**
   * Tests basic configuration and applying of a skin.
   */
  function testGroupList() {

    // Add a group.
    $group = (object) array(
      'gid' => 'block:system__user-menu:default',
      'module' => 'block',
      'element' => 'system__user-menu',
      'title' => 'Default',
      'description' => '',
      'conditions' => array(
        'sitewide' => array(
          'values' => array(
            1 => 1,
          ),
        ),
      ),
      'condition_mode' => CONTEXT_CONDITION_MODE_OR,
      'weight' => 0,
      'status' => 1,
    );
    skinr_context_group_save($group);
    $this
      ->drupalGet('');

    // Click the first (index 0) 'Edit skin' link on the page, which should be
    // the link in the contextual links of the user menu block, since no other
    // skinnable elements are visible on the page.
    $this
      ->clickLink(t('Edit skin'), 0);

    // Verify that we end up on the expected URL.
    $front = variable_get('site_frontpage', 'node');
    $this
      ->assertUrl('admin/structure/skinr/edit/block/system__user-menu/configure', array(
      'query' => array(
        'destination' => $front,
      ),
    ));

    // Make sure the group list is showing instead of the skin settings edit page.
    $this
      ->assertText('Skin settings group', 'Skin settings groups are listed.');

    // Click the first 'edit' link which should bring us to the group's edit
    // skin settings page.
    $this
      ->clickLink(t('edit'), 0);

    // Verify that we end up on the expected URL to configure skins for our group.
    $this
      ->assertUrl('admin/structure/skinr/edit/block/system__user-menu/' . $group->gid, array(
      'query' => array(
        'destination' => 'admin/structure/skinr/edit/block/system__user-menu/configure?destination=' . $front,
      ),
    ));

    // Verify that we can apply the skinr_ui_test_border skin to the block, and
    // limit the groups visibility to the front page.
    $edit = array(
      'skinr_group[title]' => 'SkinrContextGroupTitle',
      'skinr_group[description]' => 'SkinrContextGroupDescription',
      'skinr_settings[bartik][groups][general][skinr_ui_test_bgcolor]' => 'bgcolor_red',
      'conditions[state]' => 'path',
      'conditions[plugins][path][values]' => '<front>',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));

    // Verify that we were redirected back to the originating page.
    $this
      ->assertUrl('admin/structure/skinr/edit/block/system__user-menu/configure', array(
      'query' => array(
        'destination' => $front,
      ),
    ));

    // Make sure the group title and description were updated.
    $this
      ->assertText('SkinrContextGroupTitle', 'Skin settings group title was updated.');
    $this
      ->assertText('SkinrContextGroupDescription', 'Skin settings group description was updated.');

    // Click the done link.
    $this
      ->clickLink(t('Done'), 0);

    // Verify that we were redirected to the originating page.
    $this
      ->assertUrl($front);

    // Verify that the skin has been applied.
    $this
      ->assertSkinrClass('block-system-user-menu', 'bgcolor-red', 'CSS class of configured skin option found.');

    // Verify that the skin has only been applied to the front page.
    $this
      ->drupalGet('user');
    $this
      ->assertNoSkinrClass('block-system-user-menu', 'bgcolor-red', 'CSS class of configured skin option not found on other pages.');
  }

  /**
   * Tests adding a group to an element.
   */
  function testGroupAdd() {
    $this
      ->drupalGet('');
    $this
      ->clickLink(t('Edit skin'), 0);

    // Verify that we end up on the expected URL.
    $front = variable_get('site_frontpage', 'node');
    $this
      ->assertUrl('admin/structure/skinr/edit/block/system__user-menu/configure', array(
      'query' => array(
        'destination' => $front,
      ),
    ));

    // Make sure the add group link is present.
    $this
      ->assertLink('Add group', 0, 'Add group link is present.');

    // Click on the 'Add group' link.
    $this
      ->clickLink(t('Add group'), 0);

    // Verify that we end up on the expected URL to configure skins for our group.
    $this
      ->assertUrl('admin/structure/skinr/edit/block/system__user-menu/add', array(
      'query' => array(
        'destination' => 'admin/structure/skinr/edit/block/system__user-menu/configure?destination=' . $front,
      ),
    ));

    // Post the form.
    $edit = array(
      'title' => 'SkinrContextGroupTest',
      'gid' => 'skinrcontextgrouptest',
    );
    $this
      ->drupalPost(NULL, $edit, t('Add group'));

    // Verify that we were redirected back to the originating page.
    $this
      ->assertUrl('admin/structure/skinr/edit/block/system__user-menu/configure', array(
      'query' => array(
        'destination' => $front,
      ),
    ));

    // Verify that the new group is added.
    $this
      ->assertText('SkinrContextGroupTest', 'Successfully added a skin settings group.');
  }

}

/**
 * Tests UI functionality.
 */
class SkinrContextUIAdminTestCase extends SkinrContextUITestCase {
  public static function getInfo() {
    return array(
      'name' => 'Context UI - Administration',
      'description' => 'Tests administrative Skinr Context UI functionality.',
      'dependencies' => array(
        'ctools',
        'context',
        'context_ui',
      ),
      'group' => 'Skinr',
    );
  }
  function setUp() {
    parent::setUp(array(
      'skinr_test',
      'skinr_context_test_default',
    ));
  }

  /**
   * Tests skin configuration listing functionality.
   */
  function testSkinListingWithGroups() {
    $group = (object) array(
      'gid' => 'block:system__user-menu:skinlistingwithgroup',
      'module' => 'block',
      'element' => 'system__user-menu',
      'title' => 'SkinListingWithGroup',
      'description' => '',
      'conditions' => array(
        'sitewide' => array(
          'values' => array(
            1 => 1,
          ),
        ),
      ),
      'condition_mode' => CONTEXT_CONDITION_MODE_OR,
      'weight' => 0,
      'status' => 1,
    );
    skinr_context_group_save($group);
    $skin = (object) array(
      'theme' => 'skinr_test_subtheme',
      'module' => 'block',
      'element' => 'system__user-menu',
      'gid' => $group->gid,
      'skin' => 'skinr_test_subtheme',
      'options' => array(
        'option1',
        'option2',
      ),
      'status' => 1,
    );
    skinr_skin_save($skin);

    // Verify that the skin configuration appears on the skin configurations overview page.
    $this
      ->drupalGet('admin/structure/skinr');
    $this
      ->assertLinkByHref(drupal_encode_path('admin/structure/skinr/edit/' . $skin->module . '/' . $skin->element . '/' . $skin->gid), 0, 'Skin configuration was found on overview page.');

    // Test that revert link doesn't appear for default skin configurations.
    $default_skin = skinr_skin_load_by_uuid('501ff0c3-db03-0944-9910-3a788f38097a');
    $this
      ->verbose(highlight_string(print_r($default_skin, TRUE), TRUE));
    $this
      ->assertNoLinkByHref('admin/structure/skinr/skin/' . $default_skin->sid . '/revert', 0, 'No revert operation is available for default skin configuration.');

    // Test that delete link does not appear for default skin configurations.
    $this
      ->assertNoLinkByHref('admin/structure/skinr/skin/' . $default_skin->sid . '/delete', 0, 'No delete operation is available for default skin configuration.');

    // Test that revert link appears for skin configurations in code that are
    // overridden in databse.
    $default_skin->options = array(
      'options3',
    );
    skinr_skin_save($default_skin);
    $this
      ->drupalGet('admin/structure/skinr');
    $this
      ->assertLinkByHref('admin/structure/skinr/skin/' . $default_skin->sid . '/revert', 0, 'Revert operation is available for overridden skin configuration.');

    // Test that delete link does not appear for overridden skin configurations.
    $this
      ->assertNoLinkByHref('admin/structure/skinr/skin/' . $default_skin->sid . '/delete', 0, 'No delete operation is available for overridden skin configuration.');

    // Test reverting overridden skin.
    $this
      ->clickLink(t('revert'), 0);
    $edit = array(
      'skinr_settings[bartik][groups][_additional][_additional]' => 'additional',
    );
    $this
      ->drupalPost(NULL, array(), t('Revert'));

    // Load an uncached version of the skin configuration object.
    $default_skin = entity_load('skin', $default_skin->sid, TRUE);
    $this
      ->assertTrue(skinr_skin_storage($default_skin) == SKINR_STORAGE_IN_CODE, 'Overridden skin configuration was reverted to default.');

    // @todo Should we check the filtering and update options functionality?
  }

  /**
   * Tests skin configuration and group import and export forms.
   */
  function testGroupSkinImportExport() {
    $this
      ->drupalGet('admin/structure/skinr/import');
    $gid1 = 'node:page:default';
    $gid2 = 'block:user__online:default';
    $uuid1 = '16daa322-5ac0-49e4-cda2-809a13bb965b';
    $uuid2 = '7384adb8-50a8-67d4-2dcd-5acda9b5c76e';
    $edit = array(
      'skinr_groups' => "\$group = new stdClass();\n\$group->status = TRUE; /* Edit this to false to make a default group disabled initially */\n\$group->api_version = " . SKINR_VERSION . ";\n\$group->gid = '" . $gid1 . "';\n\$group->module = 'block';\n\$group->element = 'system__main';\n\$group->title = 'Default';\n\$group->description = '';\n\$group->conditions = array(\n  'sitewide' => array(\n    'values' => array(\n      1 => 1,\n    ),\n  ),\n);\n\$group->condition_mode = 0;\n\$group->weight = 0;\n\$groups['" . $gid1 . "'] = \$group;\n\n\$group = new stdClass();\n\$group->status = TRUE; /* Edit this to false to make a default group disabled initially */\n\$group->api_version = " . SKINR_VERSION . ";\n\$group->gid = '" . $gid2 . "';\n\$group->module = 'block';\n\$group->element = 'system__user-menu';\n\$group->title = 'Default';\n\$group->description = 'Default export description.';\n\$group->conditions = array(\n  'sitewide' => array(\n    'values' => array(\n      1 => 1,\n    ),\n  ),\n);\n\$group->condition_mode = 0;\n\$group->weight = 0;\n\$groups['" . $gid2 . "'] = \$group;\n",
      'skinr_skins' => "\$skin = new stdClass();\n\$skin->status = TRUE; /* Edit this to false to make a default skin disabled initially */\n\$skin->api_version = " . SKINR_VERSION . ";\n\$skin->uuid = '" . $uuid1 . "';\n\$skin->theme = 'bartik';\n\$skin->module = 'block';\n\$skin->element = 'system__main';\n\$skin->skin = 'skinr_test_example';\n\$skin->options = array(\n  'option1' => 'option1',\n);\n\$skin->gid = '" . $gid1 . "';\n\$skins['" . $uuid1 . "'] = \$skin;\n\n\$skin = new stdClass();\n\$skin->status = TRUE; /* Edit this to false to make a default skin disabled initially */\n\$skin->api_version = " . SKINR_VERSION . ";\n\$skin->uuid = '" . $uuid2 . "';\n\$skin->theme = 'bartik';\n\$skin->module = 'block';\n\$skin->element = 'system__user-menu';\n\$skin->skin = 'skinr_test_subtheme';\n\$skin->options = array(\n  'option1' => 'option1',\n  'option2' => 'option2',\n);\n\$skin->gid = '" . $gid2 . "';\n\$skins['" . $uuid2 . "'] = \$skin;\n",
    );
    $this
      ->drupalPost(NULL, $edit, t('Import'));

    // Now check if the imported skin configuration groups exist.
    $group1 = skinr_context_group_load($gid1);
    $group2 = skinr_context_group_load($gid2);
    $this
      ->assertTrue(isset($group1->gid) && $group1->gid == $gid1 && isset($group2->gid) && $group2->gid == $gid2, 'Successfully imported skin configuration groups.');

    // Now check if the imported skin configurations exist.
    $skin1 = skinr_skin_load_by_uuid($uuid1);
    $skin2 = skinr_skin_load_by_uuid($uuid2);
    $this
      ->assertTrue(isset($skin1->uuid) && $skin1->uuid == $uuid1 && $skin1->gid == $gid1 && isset($skin2->uuid) && $skin2->uuid == $uuid2 && $skin2->gid == $gid2, 'Successfully imported skin configurations with linked groups.');

    // Test export.
    $this
      ->drupalGet('admin/structure/skinr/export');
    $this
      ->drupalPost(NULL, array(
      'theme' => 'bartik',
    ), t('Export'));
    $this
      ->assertFieldByName('skinr_groups', $edit['skinr_groups'], 'Skin configuration group export value is correct.');
    $this
      ->assertFieldByName('skinr_skins', $edit['skinr_skins'], 'Skin configuration export value is correct.');
  }

}

Classes

Namesort descending Description
SkinrContextUIAdminTestCase Tests UI functionality.
SkinrContextUIBasicTestCase Tests UI functionality.
SkinrContextUITestCase Base class for Skinr Context UI tests.