Skip to content
Snippets Groups Projects
Commit 62c8b2c0 authored by Nia Kathoni's avatar Nia Kathoni
Browse files

Adding a test which toggle on and off the revision config and check if a...

Adding a test which toggle on and off the revision config and check if a revision was created or not.
parent a9950c7b
No related branches found
Tags 11.1.9
No related merge requests found
<?php
namespace Drupal\Tests\feeds\Kernel;
use Drupal\feeds\Plugin\Type\Processor\ProcessorInterface;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
/**
* Tests the feature of save a new revision.
*
* @group feeds
*/
class RevisionableEntityTest extends FeedsKernelTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->setUpBodyField();
}
/**
* {@inheritdoc}
*/
protected function setUpNodeType() {
// Create a content type.
$this->nodeType = NodeType::create([
'type' => 'article',
'name' => 'Article',
// Ensure that this node type is revisionable.
'new_revision' => TRUE,
]);
$this->nodeType->save();
}
/**
* Tests the revision toggle configuration.
*
* @dataProvider provideToggleRevision
*/
public function testRevisionToggle($is_enabled) {
$feed_type = $this->createFeedType([
'fetcher' => 'directory',
'fetcher_configuration' => [
'allowed_extensions' => 'csv',
],
'parser' => 'csv',
'processor_configuration' => [
'update_existing' => ProcessorInterface::UPDATE_EXISTING,
'authorize' => FALSE,
// Using the data provider, enable or disable the revision accordingly.
'revision' => $is_enabled,
'values' => [
'type' => 'article',
],
],
'custom_sources' => [
'title' => [
'label' => 'title',
'value' => 'title',
'machine_name' => 'title',
],
'body' => [
'label' => 'body',
'value' => 'body',
'machine_name' => 'body',
],
],
'mappings' => [
[
'target' => 'title',
'map' => ['value' => 'title'],
'unique' => ['value' => TRUE],
'settings' => [
'language' => NULL,
],
],
[
'target' => 'body',
'map' => ['value' => 'body', 'summary' => ''],
'settings' => ['format' => 'plain_text'],
],
],
]);
// Import first feed to create the first revision.
$feed = $this->createFeed($feed_type->id(), [
'source' => $this->resourcesPath() . '/csv/content.csv',
]);
$feed->import();
$node = Node::load(1);
$first_revision_id = $node->getRevisionId();
// Now import updated feed to trigger a second revision to be created.
$feed->setSource($this->resourcesPath() . '/csv/content_updated.csv');
$feed->save();
$feed->import();
$node = Node::load(1);
$second_revision_id = $node->getRevisionId();
// When revision is enabled the second revision should be different from
// the first revision and when revision is disabled the second revision
// should be equal to the second one.
$is_true = $is_enabled ? $second_revision_id !== $first_revision_id : $second_revision_id === $first_revision_id;
$this->assertTrue($is_true);
}
/**
* Data provider for ::testRevisionToggle().
*/
public function provideToggleRevision() {
return [
'enable revision' => [TRUE],
'disable revision' => [FALSE],
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment