You are here

public function FeedsSubscriberTest::testAfterParseWithTamperItem in Feeds Tamper 8.2

@covers ::afterParse @covers ::alterItem

File

tests/src/Unit/EventSubscriber/FeedsSubscriberTest.php, line 230

Class

FeedsSubscriberTest
@coversDefaultClass \Drupal\feeds_tamper\EventSubscriber\FeedsSubscriber @group feeds_tamper

Namespace

Drupal\Tests\feeds_tamper\Unit\EventSubscriber

Code

public function testAfterParseWithTamperItem() {

  // Create a tamper plugin that manipulates the whole item.
  $tamper = $this
    ->createMock(TamperInterface::class);
  $tamper
    ->expects($this
    ->once())
    ->method('tamper')
    ->will($this
    ->returnCallback([
    $this,
    'callbackWithTamperItem',
  ]));
  $this->tamperMeta
    ->expects($this
    ->once())
    ->method('getTampersGroupedBySource')
    ->will($this
    ->returnValue([
    'alpha' => [
      $tamper,
    ],
  ]));

  // Add an item to the parser result.
  $item = new DynamicItem();
  $item
    ->set('alpha', 'Foo');
  $item
    ->set('beta', 'Bar');
  $item
    ->set('gamma', 'Qux');
  $this->event
    ->getParserResult()
    ->addItem($item);

  // Run event callback.
  $this->subscriber
    ->afterParse($this->event);
  $this
    ->assertEquals('Fooing', $item
    ->get('alpha'));
  $this
    ->assertEquals('Baring', $item
    ->get('beta'));
  $this
    ->assertEquals('Quxing', $item
    ->get('gamma'));
}