You are here

TestRoleConfiguration.test in Configuration Management 7.2

File

tests/handlers/TestRoleConfiguration.test
View source
<?php

class TestRoleConfiguration extends ConfigurationHandlerBaseTestCase {

  /**
   * Implementation of DrupalWebTestCase::setUp().
   */
  public function setUp($modules = array()) {
    global $base_url;
    if (empty($modules)) {
      parent::setUp(array(
        'configuration',
        'role_export',
      ));
    }
    else {
      parent::setUp($modules);
    }
  }

  /**
   * Test info.
   */
  public static function getInfo() {
    return array(
      'name' => t('Handler: RoleConfiguration'),
      'description' => t('Test the configuration API for role configurations'),
      'group' => t('Configuration'),
    );
  }

  /**
   * Returns an array of configurations to import.
   */
  protected function configToImport() {
    return array(
      'role.developer',
    );
  }

  /**
   * Returns an array of configurations to export.
   */
  protected function configToExport() {
    return array(
      'role.my_custom_role',
    );
  }

  /**
   * Returns an array of configurations to modify and check for modifications.
   */
  protected function configToModify() {
    return array(
      'role.developer',
    );
  }

  /**
   * Return TRUE if the configuration is modified in the active store.
   */
  protected function isModified($config) {
    $modified = FALSE;
    foreach (role_export_roles() as $role) {
      if ($role->machine_name == 'developer') {
        $modified = $role->name == 'Modified';
        break;
      }
    }
    return $modified;
  }

  /**
   * Return TRUE if all the configurations defined in configToImport were saved
   * into the active store.
   */
  protected function savedInActiveStore() {
    return 'developer' == role_export_role_name_exists('developer');
  }

  /**
   * This function creates the configurations that will be exported by
   * configuration management.
   */
  protected function createConfigToExport() {
    $data = (object) array(
      'name' => 'My Custom Role',
      'weight' => '3',
    );
    user_role_save($data);
  }

  /**
   * Perform changes in the configuration and save those changes into the active
   * store.
   */
  protected function modifyConfiguration() {
    $role = user_role_load_by_name('Developer');
    $role->name = 'Modified';
    $role->machine_name = 'developer';
    user_role_save($role);
  }

}

Classes