You are here

public function FieldValidationTest::testImportFieldWithAdminFilterFormatOnCron in Feeds 8.3

Tests if a field with admin filter format can be imported on cron.

When importing the body field using a filter format that anonymous users are not allowed to use, import should not fail because of permission issues.

File

tests/src/Functional/FieldValidationTest.php, line 149

Class

FieldValidationTest
Tests fields validation.

Namespace

Drupal\Tests\feeds\Functional

Code

public function testImportFieldWithAdminFilterFormatOnCron() {

  // Create a body field for the article content type.
  node_add_body_field($this->nodeType);

  // Create a filter not available to anonymous users.
  $format = FilterFormat::create([
    'format' => 'empty_format',
    'name' => 'Empty format',
  ]);
  $format
    ->save();

  // Create an user that may use this format.
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer feeds',
    'administer filters',
    'access site reports',
    $format
      ->getPermissionName(),
  ]);
  $this
    ->drupalLogin($this->adminUser);

  // Create a feed type, map to body field. Set the filter format that has
  // restricted access.
  $feed_type = $this
    ->createFeedTypeForCsv([
    'guid' => 'guid',
    'title' => 'title',
    'body' => 'body',
  ], [
    'mappings' => array_merge($this
      ->getDefaultMappings(), [
      [
        'target' => 'body',
        'map' => [
          'value' => 'body',
        ],
        'settings' => [
          'format' => $format
            ->id(),
        ],
      ],
    ]),
  ]);

  // Create a feed and import on cron.
  $feed = $this
    ->createFeed($feed_type
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/csv/content.csv',
    'uid' => $this->adminUser
      ->id(),
  ]);
  $feed
    ->startCronImport();

  // Run cron to import.
  $this
    ->cronRun();

  // Assert that 2 nodes have been created.
  $this
    ->assertNodeCount(2);
}