3 namespace Drupal\Tests\taxonomy\Functional;
5 use Drupal\Core\Datetime\DrupalDateTime;
6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
7 use \Drupal\taxonomy\Entity\Vocabulary;
10 * Posts an article with a taxonomy term and a date prior to 1970.
14 class LegacyTest extends TaxonomyTestBase {
21 public static $modules = ['node', 'datetime'];
23 protected function setUp() {
26 // Create a tags vocabulary for the 'article' content type.
27 $vocabulary = Vocabulary::create([
32 $field_name = 'field_' . $vocabulary->id();
36 $vocabulary->id() => $vocabulary->id(),
38 'auto_create' => TRUE,
40 $this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
42 entity_get_form_display('node', 'article', 'default')
43 ->setComponent($field_name, [
44 'type' => 'entity_reference_autocomplete_tags',
48 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'bypass node access']));
52 * Test taxonomy functionality with nodes prior to 1970.
54 public function testTaxonomyLegacyNode() {
55 // Posts an article with a taxonomy term and a date prior to 1970.
56 $date = new DrupalDateTime('1969-01-01 00:00:00');
58 $edit['title[0][value]'] = $this->randomMachineName();
59 $edit['created[0][value][date]'] = $date->format('Y-m-d');
60 $edit['created[0][value][time]'] = $date->format('H:i:s');
61 $edit['body[0][value]'] = $this->randomMachineName();
62 $edit['field_tags[target_id]'] = $this->randomMachineName();
63 $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
64 // Checks that the node has been saved.
65 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
66 $this->assertEqual($node->getCreatedTime(), $date->getTimestamp(), 'Legacy node was saved with the right date.');