You are here

public function FeedsOgTest::testImportOgReferenceWithAuthorizing in Feeds 7.2

Tests authorizing users importing content for a group.

With the "authorize" option turned on, an user *must* be a member of the group in order to import content for that group.

File

tests/feeds_og.test, line 181
Contains FeedsOgTest.

Class

FeedsOgTest
Tests for Organic Groups integration.

Code

public function testImportOgReferenceWithAuthorizing() {

  // Enable "authorize" option.
  $this
    ->setSettings('syndication', 'FeedsNodeProcessor', array(
    'authorize' => TRUE,
  ));

  // Use source 'alpha' as group name.
  $this
    ->addMappings('syndication', array(
    1 => array(
      'source' => 'author',
      'target' => 'user_name',
    ),
    2 => array(
      'source' => 'alpha',
      'target' => 'og_group_ref:label',
    ),
  ));

  // Create a role with permission to create content.
  $rid = $this
    ->drupalCreateRole(array(
    'access content',
    'create article content',
  ));

  // Create two accounts.
  $morticia = user_save(drupal_anonymous_user(), array(
    'name' => 'Morticia',
    'mail' => 'morticia@example.com',
    'pass' => 'mort',
    'status' => 1,
    'roles' => array(
      $rid => $rid,
    ),
  ));
  $fester = user_save(drupal_anonymous_user(), array(
    'name' => 'Fester',
    'mail' => 'fester@example.com',
    'pass' => 'fester',
    'status' => 1,
    'roles' => array(
      $rid => $rid,
    ),
  ));

  // Create two groups and make Fester the owner of both.
  $group1 = $this
    ->createGroup('Lorem', $fester->uid);
  $group2 = $this
    ->createGroup('Ut wisi', $fester->uid);

  // Create a feed node and change the author of the node.
  $nid = $this
    ->createFeedNode('syndication', $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/content_author.csv', 'Node 1');
  $account = $this
    ->drupalCreateUser(array(
    'access content',
    'create article content',
  ));
  $this
    ->changeNodeAuthor($nid, $account);

  // And perform import.
  $this
    ->drupalPost('node/3/import', NULL, 'Import');

  // Assert that only one node was imported. Only the author of the second
  // item is expected to be allowed to reference the group.
  $this
    ->assertText('Created 1 node');
  $this
    ->assertText('Failed importing 1 node');
  $this
    ->assertText("Field validation errors in item 'Lorem ipsum'");
  $this
    ->assertText('The referenced group (node: 1) is invalid.');
}