You are here

function _oauth2_client_test_delete in OAuth2 Client 7

Same name and namespace in other branches
  1. 7.2 tests/oauth2_client_test.install \_oauth2_client_test_delete()

Delete test servers, clients and scopes.

1 call to _oauth2_client_test_delete()
oauth2_client_test_disable in tests/oauth2_client_test.install
Implements hook_disable().

File

tests/oauth2_client_test.install, line 95
Enable and disable hook functions.

Code

function _oauth2_client_test_delete() {
  $server_name = 'test_oauth2_server';

  // Delete the test clients.
  $clients = array(
    'client1',
    'client2',
  );
  foreach ($clients as $client_key) {
    $query = new EntityFieldQuery();
    $clients = $query
      ->entityCondition('entity_type', 'oauth2_server_client')
      ->propertyCondition('client_key', $client_key)
      ->execute();
    if (isset($clients['oauth2_server_client'])) {
      $ids = array_keys($clients['oauth2_server_client']);
      foreach ($ids as $id) {
        entity_delete('oauth2_server_client', $id);
      }
    }
  }

  // Delete the test scopes.
  $scopes = array(
    'scope1',
    'scope2',
  );
  foreach ($scopes as $scope_name) {
    $query = new EntityFieldQuery();
    $scopes = $query
      ->entityCondition('entity_type', 'oauth2_server_scope')
      ->propertyCondition('name', $scope_name)
      ->execute();
    if (isset($scopes['oauth2_server_scope'])) {
      $ids = array_keys($scopes['oauth2_server_scope']);
      foreach ($ids as $id) {
        entity_delete('oauth2_server_scope', $id);
      }
    }
  }

  // Delete the test oauth2 server.
  $query = new EntityFieldQuery();
  $servers = $query
    ->entityCondition('entity_type', 'oauth2_server')
    ->propertyCondition('name', $server_name)
    ->execute();
  if (isset($servers['oauth2_server'])) {
    $ids = array_keys($servers['oauth2_server']);
    foreach ($ids as $id) {
      entity_delete('oauth2_server', $id);
    }
  }

  // Delete the test user.
  if ($user = user_load_by_name('user1')) {
    user_delete($user->uid);
  }
}