You are here

public function JmesPathParserTest::testImportWithInvalidExpression in Feeds extensible parsers 8

Tests an import with an invalid source expression.

File

tests/src/Functional/Feeds/Parser/JmesPathParserTest.php, line 72

Class

JmesPathParserTest
@coversDefaultClass \Drupal\feeds_ex\Feeds\Parser\JmesPathParser @group feeds_ex

Namespace

Drupal\Tests\feeds_ex\Functional\Feeds\Parser

Code

public function testImportWithInvalidExpression() {

  // Add body field.
  node_add_body_field($this->nodeType);

  // Create a feed type with an invalid jmespath source value.
  $feed_type = $this
    ->createFeedType([
    'parser' => 'jmespath',
    'parser_configuration' => [
      'context' => [
        'value' => '@',
      ],
      'sources' => [
        'title' => [
          'label' => 'Title',
          'value' => 'items[].title',
        ],
        'title_desc' => [
          'label' => 'Title and description',
          // Invalid source expression. Closing bracket is missing.
          'value' => 'items[].join(`__`,[title,description)',
        ],
      ],
    ],
    'custom_sources' => [
      'title' => [
        'label' => 'Title',
        'value' => 'items[].title',
        'machine_name' => 'title',
      ],
      'title_desc' => [
        'label' => 'Title and description',
        // Invalid source expression. Closing bracket is missing.
        'value' => 'items[].join(`__`,[title,description)',
        'machine_name' => 'title_desc',
      ],
    ],
    'mappings' => [
      [
        'target' => 'title',
        'map' => [
          'value' => 'title',
        ],
        'unique' => [
          'value' => TRUE,
        ],
      ],
      [
        'target' => 'body',
        'map' => [
          'value' => 'title_desc',
        ],
        'settings' => [
          'format' => 'plain_text',
        ],
      ],
    ],
  ]);

  // And try to do a batch import.
  $feed = $this
    ->createFeed($feed_type
    ->id(), [
    'source' => $this
      ->resourcesUrl() . '/test.json',
  ]);
  $this
    ->batchImport($feed);

  // And assert that it failed gracefully.
  $this
    ->assertSession()
    ->pageTextContains('There are no new Article items.');
  $this
    ->assertSession()
    ->pageTextContains('Syntax error at character');
}