public function AfterParseBaseTest::testAfterParse in Feeds 8.3
Tests that a list of items can get manipulated.
@covers ::afterParse
File
- tests/
src/ Unit/ EventSubscriber/ AfterParseBaseTest.php, line 71
Class
- AfterParseBaseTest
- @coversDefaultClass \Drupal\feeds\EventSubscriber\AfterParseBase @group feeds
Namespace
Drupal\Tests\feeds\Unit\EventSubscriberCode
public function testAfterParse() {
// Create two items and add these to the parser result.
$item1 = new DynamicItem();
$item1
->set('title', 'Foo');
$item2 = new DynamicItem();
$item2
->set('title', 'Bar');
$this->parserResult
->addItems([
$item1,
$item2,
]);
// Implement AfterParseBase::alterItem() by adding a '1' to each item's
// title.
$this->subscriber
->expects($this
->exactly(2))
->method('alterItem')
->will($this
->returnCallback(function (ItemInterface $item, ParseEvent $event) {
$item
->set('title', $item
->get('title') . '1');
}));
// Run subscriber.
$this->subscriber
->afterParse($this->event);
// Assert that each item got a '1' added.
$this
->assertEquals('Foo1', $item1
->get('title'));
$this
->assertEquals('Bar1', $item2
->get('title'));
}