View source
<?php
namespace Drupal\Tests\feeds\Kernel;
use Drupal\feeds\Plugin\Type\Processor\ProcessorInterface;
use Drupal\node\Entity\Node;
class HashTest extends FeedsKernelTestBase {
public function testIrrelevantUpdate() {
$feed_type = $this
->createFeedType([
'fetcher' => 'directory',
'fetcher_configuration' => [
'allowed_extensions' => 'csv',
],
'parser' => 'csv',
'processor_configuration' => [
'update_existing' => ProcessorInterface::UPDATE_EXISTING,
'authorize' => FALSE,
'values' => [
'type' => 'article',
],
],
'processor_configuration' => [
'authorize' => FALSE,
'update_existing' => ProcessorInterface::UPDATE_EXISTING,
'values' => [
'type' => 'article',
],
],
'custom_sources' => [
'guid' => [
'label' => 'guid',
'value' => 'guid',
'machine_name' => 'guid',
],
'title' => [
'label' => 'title',
'value' => 'title',
'machine_name' => 'title',
],
],
]);
$feed = $this
->createFeed($feed_type
->id(), [
'source' => $this
->resourcesPath() . '/csv/content.csv',
]);
$feed
->import();
$this
->assertNodeCount(2);
$nodes = Node::loadMultiple();
$expected_titles = [
1 => 'Lorem ipsum',
2 => 'Ut wisi enim ad minim veniam',
];
foreach ($expected_titles as $node_id => $expected_title) {
$this
->assertEquals($expected_title, $nodes[$node_id]->title->value);
}
for ($i = 1; $i <= 2; $i++) {
$nodes[$i]->title->value = 'Node ' . $i;
$nodes[$i]
->save();
}
$feed
->setSource($this
->resourcesPath() . '/csv/content_updated.csv');
$feed
->save();
$feed
->import();
for ($i = 1; $i <= 2; $i++) {
$node = $this
->reloadEntity($nodes[$i]);
$this
->assertEquals('Node ' . $i, $node->title->value);
}
}
}