You are here

function EntityReferenceProvidersTestCase::testProvidres in Entityreference prepopulate 7

Test the providers functionality.

File

./entityreference_prepopulate.test, line 293

Class

EntityReferenceProvidersTestCase

Code

function testProvidres() {
  $nid1 = $this->group1->nid;
  $nid2 = $this->group2->nid;
  $path = 'node/add/' . str_replace('_', '-', $this->group_content_type);
  $options = array(
    'query' => array(
      OG_AUDIENCE_FIELD => $nid1,
      // Set the OG context. See entityreference_prepopulate_init().
      'gid' => $nid2,
    ),
  );
  $instance = field_info_instance('node', OG_AUDIENCE_FIELD, $this->group_content_type);
  $scenarios = array(
    array(
      'message' => 'No providers set - defaults to URL.',
      'providers' => array(),
      'result' => $nid1,
    ),
    array(
      'message' => 'URL provider only.',
      'providers' => array(
        'url' => TRUE,
      ),
      'result' => $nid1,
    ),
    array(
      'message' => 'OG Context provider only.',
      'providers' => array(
        'og_context' => TRUE,
      ),
      'result' => $nid2,
    ),
    array(
      'message' => 'URL provider, and then OG Context provider.',
      'providers' => array(
        'url' => TRUE,
        'og_context' => TRUE,
      ),
      'result' => $nid1,
    ),
    array(
      'message' => 'OG Context provider, and then URL provider.',
      'providers' => array(
        'og_context' => TRUE,
        'url' => TRUE,
      ),
      'result' => $nid2,
    ),
    array(
      'message' => 'Invalid provider.',
      'providers' => array(
        'invalid' => TRUE,
      ),
      'result' => FALSE,
    ),
  );
  foreach ($scenarios as $scenario) {
    $instance['settings']['behaviors']['prepopulate']['providers'] = $scenario['providers'];
    field_update_instance($instance);
    $this
      ->drupalGet($path, $options);
    if ($scenario['result']) {
      $this
        ->assertOptionSelected('edit-og-group-ref-und-0-default', $scenario['result'], $scenario['message']);
    }
    else {
      $this
        ->assertNoOptionSelected('edit-og-group-ref-und-0-default', $nid1, $scenario['message']);
      $this
        ->assertNoOptionSelected('edit-og-group-ref-und-0-default', $nid2, $scenario['message']);
    }
  }
}