You are here

function SpacesOGTestCRUD::testCRUD in Spaces 7.3

Same name and namespace in other branches
  1. 6.3 spaces_og/tests/spaces_og.test \SpacesOGTestCRUD::testCRUD()
  2. 7 spaces_og/tests/spaces_og.test \SpacesOGTestCRUD::testCRUD()

OG CRUD and configure tests.

File

spaces_og/tests/spaces_og.test, line 184

Class

SpacesOGTestCRUD

Code

function testCRUD() {

  // Test if presets save properly to DB.
  $realms = array(
    'og_admin' => array(
      'gid' => 1,
      'grant_view' => 1,
      'grant_update' => 1,
      'grant_delete' => 0,
    ),
    'og_public' => array(
      'gid' => 0,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
    ),
    'og_subscriber' => array(
      'gid' => 1,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
    ),
  );
  $presets = array(
    'og_controlled' => array(
      'og' => array(
        'og_selective' => 1,
        'og_register' => 1,
        'og_directory' => 1,
        'og_private' => 0,
      ),
      'node_access' => array(
        'og_public',
        'og_admin',
      ),
    ),
    'og_private' => array(
      'og' => array(
        'og_selective' => 3,
        'og_register' => 0,
        'og_directory' => 0,
        'og_private' => 1,
      ),
      'node_access' => array(
        'og_admin',
        'og_subscriber',
      ),
    ),
    'og_public' => array(
      'og' => array(
        'og_selective' => 0,
        'og_register' => 1,
        'og_directory' => 1,
        'og_private' => 0,
      ),
      'node_access' => array(
        'og_public',
        'og_admin',
      ),
    ),
  );
  foreach ($presets as $preset => $config) {
    $edit = array(
      'spaces_preset_og' => $preset,
    );
    $this
      ->drupalPost('node/1/edit', $edit, 'Save');

    // Assert spaces override status.
    $value = unserialize(db_query('SELECT value from {spaces_overrides} WHERE id = :id', array(
      ':id' => 1,
    ))
      ->fetchField());
    $this
      ->assertEqual($value, $preset);

    // Assert OG configuration.
    $result = db_query('SELECT og_selective, og_register, og_directory, og_private FROM {og} WHERE nid = :nid', array(
      ':nid' => 1,
    ));
    $og = $result
      ->fetchAssoc();
    foreach ($config['og'] as $k => $v) {
      $this
        ->assertEqual($og[$k], $v);
    }

    // Review node_access table, this is essentially testing OG behavior, but
    // a change in this behavior would break our assumptions.
    foreach ($config['node_access'] as $realm) {
      $this
        ->assertEqual(2, db_query('SELECT COUNT(*) FROM {node_access} WHERE nid = :nid', array(
        ':nid' => 1,
      ))
        ->fetchField());
      $result = db_query('SELECT * FROM {node_access} WHERE nid = :nid AND realm = :realm', array(
        ':nid' => 1,
        ':realm' => $realm,
      ));
      $access = $result
        ->fetchAssoc();
      foreach ($realms[$realm] as $k => $v) {
        $this
          ->assertEqual($access[$k], $v);
      }
    }
  }

  // Delete the node and verify that there are no remnants.
  $this
    ->drupalPost('node/1/delete', array(), 'Delete group');
  $this
    ->assertText('Group Group A has been deleted.');
  $this
    ->assertEqual(0, db_query('SELECT count(*) FROM {spaces_overrides} WHERE id = :id', array(
    ':id' => 1,
  ))
    ->fetchField());
  $this
    ->assertEqual(0, db_query('SELECT count(*) FROM {purl} WHERE id = :id', array(
    ':id' => 1,
  ))
    ->fetchField());
}