EntityCloneContentCreatedDate.php in Entity Clone 8
File
tests/src/Functional/EntityCloneContentCreatedDate.php
View source
<?php
namespace Drupal\Tests\entity_clone\Functional;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\Tests\node\Functional\NodeTestBase;
class EntityCloneContentCreatedDate extends NodeTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'entity_clone',
'node',
];
protected $sutUser;
protected function setUp() {
parent::setUp();
$this->sutUser = $this
->drupalCreateUser([
'bypass node access',
'administer nodes',
'clone node entity',
]);
}
public function testCreatedDateIsNotCloned() {
$this
->drupalLogin($this->sutUser);
$originalNodeCreatedDate = new \DateTimeImmutable('1 year 1 month 1 day ago');
$originalNode = $this
->drupalCreateNode([
'created' => $originalNodeCreatedDate
->getTimestamp(),
]);
$this
->assertEquals($originalNodeCreatedDate
->getTimestamp(), $originalNode
->getCreatedTime());
$this
->drupalGet(Url::fromRoute('entity.node.clone_form', [
'node' => $originalNode
->id(),
])
->toString());
$this
->getSession()
->getPage()
->pressButton('Clone');
$originalNodeClones = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'title' => sprintf('%s - Cloned', $originalNode
->label()),
]);
$this
->assertGreaterThanOrEqual(1, count($originalNodeClones));
$clonedNode = reset($originalNodeClones);
$this
->assertNotEquals($originalNode
->getCreatedTime(), $clonedNode
->getCreatedTime());
$this
->assertGreaterThanOrEqual($originalNode
->getCreatedTime(), $clonedNode
->getCreatedTime());
}
}