PublicationDatePreExistingContentTest.php in Publication Date 8.2
File
tests/src/Functional/PublicationDatePreExistingContentTest.php
View source
<?php
namespace Drupal\Tests\publication_date\Functional;
use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
class PublicationDatePreExistingContentTest extends BrowserTestBase {
use \Drupal\Tests\node\Traits\ContentTypeCreationTrait;
protected static $modules = [
'node',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$nodeType = NodeType::create([
'type' => 'test1',
'name' => 'Test Unpublished',
]);
$nodeType
->save();
$entity = BaseFieldOverride::create([
'field_name' => 'status',
'entity_type' => 'node',
'bundle' => 'test1',
]);
$entity
->setDefaultValue(FALSE)
->save();
$account = $this
->drupalCreateUser([
'create test1 content',
'edit own test1 content',
'administer nodes',
]);
$this
->drupalLogin($account);
}
public function testWithExistingContent() {
$node = Node::create([
'type' => 'test1',
'title' => $this
->randomString(),
]);
$node
->save();
\Drupal::service('module_installer')
->install([
'publication_date',
]);
$node = Node::load($node
->id());
$node
->save();
$this
->assertEqual($node->published_at->value, PUBLICATION_DATE_DEFAULT);
$node
->setPublished()
->save();
$this
->assertNotNull($node->published_at->value);
$this
->assertNotEqual($node->published_at->value, PUBLICATION_DATE_DEFAULT);
}
}