You are here

public function RoleExportTestCase::testExport in Role Export 6

File

./role_export.test, line 29
Test Role Export.

Class

RoleExportTestCase
@file Test Role Export.

Code

public function testExport() {

  // Create a user with permission to create Roles
  $u = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'administer permissions',
  ));
  $this
    ->drupalLogin($u);

  // Create a Role
  $edit = array(
    'name' => 'Test Role',
    'machine_name' => 'test_role_with_different_machine_name',
  );
  $this
    ->drupalPost('admin/user/roles', $edit, 'Add role');
  $this
    ->assertRaw("The role has been added.", "Unable to add test role.");

  // Make sure the machine_name was correctly hashed into an rid
  $roles = user_roles();
  $this
    ->assertTrue(isset($roles[924007658]), "Test Role wasn't added, or has incorrect hashed machine_name.");

  // Export a Feature
  $this
    ->assertFalse(module_exists('test_role_feature'), "The test Feature export module is already enabled.");
  drush_set_context('DRUSH_AFFIRMATIVE', TRUE);
  drush_features_export('test_role_feature', 'role_export:test_role_with_different_machine_name');
  $this
    ->assertTrue(is_dir('sites/all/modules/test_role_feature'), "Failed to export Feature.");

  // Check contents of exported Feature
  module_load_include('inc', 'test_role_feature', 'test_role_feature.features.role_export');
  $this
    ->assertTrue(function_exists('test_role_feature_role_export_defaults'), "Function test_role_feature_role_export_defaults doesn't appear in exported Feature.");
  $defaults = test_role_feature_role_export_defaults();
  $this
    ->assertTrue(isset($defaults['test_role_with_different_machine_name']), "No default defined for test_role_with_different_machine_name.");
  $this
    ->assertEqual($defaults['test_role_with_different_machine_name']['rid'], 924007658, "Incorrect exported rid.");
  $this
    ->assertEqual($defaults['test_role_with_different_machine_name']['name'], 'Test Role', "Incorrect exported name.");
  $this
    ->assertEqual($defaults['test_role_with_different_machine_name']['machine_name'], 'test_role_with_different_machine_name', "Incorrect exported machine_name.");
}