You are here

class SkinrUIAdminTestCase in Skinr 8.2

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

Tests administrative pages functionality.

Hierarchy

Expanded class hierarchy of SkinrUIAdminTestCase

File

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

View source
class SkinrUIAdminTestCase extends SkinrUITestCase {
  public static function getInfo() {
    return array(
      'name' => 'UI - Administration',
      'description' => 'Tests administrative Skinr UI functionality.',
      'group' => 'Skinr',
    );
  }
  function setUp() {
    parent::setUp(array(
      'skinr_test',
      'skinr_test_default',
    ));
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer skinr',
      'edit skin settings',
      'edit advanced skin settings',
    ));
    $this
      ->drupalLogin($this->admin_user);

    // Enable Garland and skinr_test_subtheme without enabling its base theme in
    // order to test subtheme inheritance functionality.
    theme_enable(array(
      'garland',
      'skinr_test_subtheme',
    ));
  }

  /**
   * Tests default status of skins.
   *
   * The skinr_test_basetheme skin defined by the skinr_test_basetheme theme
   * specifies a default status for itself. Its subtheme should inherit the
   * status of the basetheme.
   *
   * @todo Add assertions for 'default status' itself.
   */
  function testSkinDefaultStatus() {

    // Verify that it is enabled for the skinr_test_subtheme.
    $this
      ->drupalGet('admin/structure/skinr/library/list/skinr_test_subtheme');
    $this
      ->assertFieldChecked('edit-skins-general-skinr-test-basetheme-enable', 'skinr_test_basetheme skin is enabled for skinr_test_subtheme.');

    // Verify that it is disabled for Bartik by default.
    $this
      ->drupalGet('admin/structure/skinr/library/list/bartik');
    $this
      ->assertNoFieldChecked('edit-skins-general-skinr-test-basetheme-enable', 'skinr_test_basetheme skin is disabled for Bartik.');

    // Verify that it is disabled for Garland by default.
    $this
      ->drupalGet('admin/structure/skinr/library/list/garland');
    $this
      ->assertNoFieldChecked('edit-skins-general-skinr-test-basetheme-enable', 'skinr_test_basetheme skin is disabled for Garland.');

    // Override the status for skinr_test_subtheme and Bartik, then verify them.
    $skin = (object) array(
      'theme' => 'skinr_test_subtheme',
      'module' => 'block',
      'element' => 'system__user-menu',
      'skin' => 'skinr_test_subtheme',
      'options' => array(
        'option1',
        'option2',
      ),
      'status' => 1,
    );
    skinr_skin_save($skin);
    $skin = entity_load('skin', $skin->sid);

    // Override the default skin.
    $skin->element = 'system-main';
    $this
      ->drupalGet('admin/structure/skinr');
    $this
      ->clickLink(t('disable'), 1);

    // Unaltered skin configuration object should have been saved with only the status updated.
    // Load an uncached version of the skin configuration object.
    $skin = entity_load('skin', $skin->sid, TRUE);
    $this
      ->assertFalse($skin->status, 'Status was disabled successfully.');
    $this
      ->assertEqual($skin->element, 'system__user-menu', 'Only status was updated, even though the object was modified before updating status.');

    // Enable the skin configuration.
    $this
      ->drupalGet('admin/structure/skinr');
    $this
      ->clickLink(t('enable'), 0);

    // Load an uncached version of the skin configuration object.
    $skin = entity_load('skin', $skin->sid, TRUE);
    $this
      ->assertTrue($skin->status, 'Status was enabled successfully.');
  }

  /**
   * Tests skin group functionality.
   */
  function testSkinGroups() {
    $this
      ->drupalGet('admin/structure/skinr/library');

    // Verify that the 'General' (default) group appears.
    $this
      ->assertText(t('General'));

    // Verify that the 'Box styles' group appears, since skinr_ui_test module
    // registers a skin in that group.
    $this
      ->assertText(t('Box styles'));
  }

  /**
   * Tests skin configuration listing functionality.
   */
  function testSkinListing() {
    $skin = (object) array(
      'theme' => 'skinr_test_subtheme',
      'module' => 'block',
      'element' => 'system__user-menu',
      '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('admin/structure/skinr/skin/' . $skin->sid . '/delete', 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
      ->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);
    $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 import and export forms.
   */
  function testSkinImportExport() {
    $this
      ->drupalGet('admin/structure/skinr/import');
    $uuid1 = '16daa322-5ac0-49e4-cda2-809a13bb965b';
    $uuid2 = '7384adb8-50a8-67d4-2dcd-5acda9b5c76e';
    $edit = array(
      '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\$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\$skins['" . $uuid2 . "'] = \$skin;\n",
    );
    $this
      ->drupalPost(NULL, $edit, t('Import'));

    // 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 && isset($skin2->uuid) && $skin2->uuid == $uuid2, 'Successfully imported skin configurations.');

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

}

Members

Namesort descending Modifiers Type Description Overrides
SkinrUIAdminTestCase::getInfo public static function
SkinrUIAdminTestCase::setUp function Overrides SkinrUITestCase::setUp
SkinrUIAdminTestCase::testSkinDefaultStatus function Tests default status of skins.
SkinrUIAdminTestCase::testSkinGroups function Tests skin group functionality.
SkinrUIAdminTestCase::testSkinImportExport function Tests skin configuration import and export forms.
SkinrUIAdminTestCase::testSkinListing function Tests skin configuration listing functionality.
SkinrUITestCase::$profile protected property 1
SkinrUITestCase::assertNoSkinrClass function Asserts that a class is not set for the given element id.
SkinrUITestCase::assertSkinrClass function Asserts that a class is set for the given element id.