You are here

function OgFieldWidgetTestCase::testFieldModes in Organic groups 7.2

Test "field modes" of the OG reference widget.

File

./og.test, line 1112

Class

OgFieldWidgetTestCase
Test the complex widget.

Code

function testFieldModes() {
  $user1 = $this
    ->drupalCreateUser(array(
    'administer group',
    'access content',
    'create post content',
  ));
  $user2 = $this
    ->drupalCreateUser(array(
    'access content',
    'create post content',
  ));

  // Create group nodes.
  $settings = array(
    'type' => 'group',
    OG_GROUP_FIELD . '[und][0][value]' => 1,
  );
  $settings['uid'] = $user1->uid;
  $group1 = $this
    ->drupalCreateNode($settings);
  $settings['uid'] = $user2->uid;
  $group2 = $this
    ->drupalCreateNode($settings);
  $settings = array(
    'type' => 'post',
  );
  $settings['uid'] = $user1->uid;
  $post1 = $this
    ->drupalCreateNode($settings);
  og_group('node', $group1->nid, array(
    'entity_type' => 'node',
    'entity' => $post1,
  ));
  $settings['uid'] = $user2->uid;
  $post2 = $this
    ->drupalCreateNode($settings);
  og_group('node', $group2->nid, array(
    'entity_type' => 'node',
    'entity' => $post2,
  ));
  $this
    ->drupalLogin($user1);
  $this
    ->drupalGet("node/{$post1->nid}/edit");
  $fields = $this
    ->xpath('//*[@id="edit-og-group-ref-und-0-default"]');
  $this
    ->assertEqual($fields[0]->option['value'], '_none', '"Default" field mode is not required for administrator.');
  $fields = $this
    ->xpath('//*[@id="edit-og-group-ref-und-0-admin-0-target-id"]');
  $this
    ->assertTrue(strpos($fields[0]
    ->attributes()->class[0], 'form-autocomplete'), '"Administrator field more is an autocomplete widget type."');
  $this
    ->drupalLogin($user2);
  $this
    ->drupalGet("node/{$post2->nid}/edit");
  $fields = $this
    ->xpath('//*[@id="edit-og-group-ref-und-0-default"]');
  $this
    ->assertEqual($fields[0]->option['value'], $group2->nid, '"Default" field mode is required.');
}