You are here

public function JmesPathParserTest::testInvalidMappingSource in Feeds extensible parsers 8

Tests mapping validation.

File

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

Class

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

Namespace

Drupal\Tests\feeds_ex\Functional\Feeds\Parser

Code

public function testInvalidMappingSource() {
  $this
    ->drupalGet('/admin/structure/feeds/manage/' . $this->feedType
    ->id() . '/mapping');

  // First, set context.
  $edit = [
    'context' => '@',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  // Now try to configure an invalid mapping source.
  $edit = [
    'mappings[1][map][value][select]' => '__new',
    // Invalid source expression. Closing bracket is missing.
    'mappings[1][map][value][__new][value]' => 'items[].join(`__`,[title,description)',
    'mappings[1][map][value][__new][machine_name]' => 'title_desc',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  // Assert that a warning is displayed.
  $this
    ->assertSession()
    ->pageTextContains('Syntax error at character');

  // Now check the parser configuration.
  $this->feedType = $this
    ->reloadEntity($this->feedType);
  $this
    ->assertEquals([], $this->feedType
    ->getParser()
    ->getConfiguration('sources'));
}