View source
<?php
namespace Drupal\Tests\feeds\Functional;
use Drupal\feeds\Plugin\Type\Processor\ProcessorInterface;
use Drupal\node\Entity\Node;
class UpdateExistingTest extends FeedsBrowserTestBase {
protected $feedType;
protected function setUp() {
parent::setUp();
$this->feedType = $this
->createFeedTypeForCsv([
'title' => 'title',
], [
'processor_configuration' => [
'update_existing' => ProcessorInterface::UPDATE_EXISTING,
'values' => [
'type' => 'article',
],
],
'mappings' => [
[
'target' => 'title',
'map' => [
'value' => 'title',
],
'unique' => [
'value' => TRUE,
],
],
],
]);
}
public function testUpdateUnpublishedNodeWithNodeAccess() {
\Drupal::state()
->get('node_access_test.no_access_uid', 1);
$this->container
->get('module_installer')
->install([
'node_access_test',
]);
node_access_rebuild();
$account = $this
->drupalCreateUser([
'access content',
'create article content',
'edit any article content',
]);
$processor = $this->feedType
->getProcessor();
$config = $processor
->getConfiguration();
$config['owner_id'] = $account
->id();
$processor
->setConfiguration($config);
$this->feedType
->save();
$node = Node::create([
'title' => 'Lorem ipsum',
'type' => 'article',
'uid' => $this->adminUser
->id(),
'status' => 0,
]);
$node
->save();
$feed = $this
->createFeed($this->feedType
->id(), [
'source' => $this
->resourcesPath() . '/csv/content.csv',
'uid' => $account
->id(),
]);
$feed
->startCronImport();
$this
->cronRun();
$this
->assertNodeCount(2);
$feed = $this
->reloadFeed($feed);
$this
->drupalGet('feed/1');
$assert_session = $this
->assertSession();
$assert_session
->pageTextContains('Created 1 article');
$assert_session
->pageTextContains('Updated 1 article');
}
}