annotate core/modules/taxonomy/tests/src/Functional/EarlyDateTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 1fec387a4317
children
rev   line source
Chris@14 1 <?php
Chris@14 2
Chris@14 3 namespace Drupal\Tests\taxonomy\Functional;
Chris@14 4
Chris@14 5 use Drupal\Core\Datetime\DrupalDateTime;
Chris@14 6 use Drupal\Core\Field\FieldStorageDefinitionInterface;
Chris@14 7 use Drupal\taxonomy\Entity\Vocabulary;
Chris@14 8
Chris@14 9 /**
Chris@14 10 * Posts an article with a taxonomy term and a date prior to 1970.
Chris@14 11 *
Chris@14 12 * @group taxonomy
Chris@14 13 */
Chris@14 14 class EarlyDateTest extends TaxonomyTestBase {
Chris@14 15
Chris@14 16 /**
Chris@14 17 * Modules to enable.
Chris@14 18 *
Chris@14 19 * @var array
Chris@14 20 */
Chris@14 21 public static $modules = ['node', 'datetime'];
Chris@14 22
Chris@14 23 protected function setUp() {
Chris@14 24 parent::setUp();
Chris@14 25
Chris@14 26 // Create a tags vocabulary for the 'article' content type.
Chris@14 27 $vocabulary = Vocabulary::create([
Chris@14 28 'name' => 'Tags',
Chris@14 29 'vid' => 'tags',
Chris@14 30 ]);
Chris@14 31 $vocabulary->save();
Chris@14 32 $field_name = 'field_' . $vocabulary->id();
Chris@14 33
Chris@14 34 $handler_settings = [
Chris@14 35 'target_bundles' => [
Chris@14 36 $vocabulary->id() => $vocabulary->id(),
Chris@14 37 ],
Chris@14 38 'auto_create' => TRUE,
Chris@14 39 ];
Chris@14 40 $this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
Chris@14 41
Chris@14 42 entity_get_form_display('node', 'article', 'default')
Chris@14 43 ->setComponent($field_name, [
Chris@14 44 'type' => 'entity_reference_autocomplete_tags',
Chris@14 45 ])
Chris@14 46 ->save();
Chris@14 47
Chris@14 48 $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'bypass node access']));
Chris@14 49 }
Chris@14 50
Chris@14 51 /**
Chris@14 52 * Test taxonomy functionality with nodes prior to 1970.
Chris@14 53 */
Chris@14 54 public function testTaxonomyEarlyDateNode() {
Chris@14 55 // Posts an article with a taxonomy term and a date prior to 1970.
Chris@14 56 $date = new DrupalDateTime('1969-01-01 00:00:00');
Chris@14 57 $edit = [];
Chris@14 58 $edit['title[0][value]'] = $this->randomMachineName();
Chris@14 59 $edit['created[0][value][date]'] = $date->format('Y-m-d');
Chris@14 60 $edit['created[0][value][time]'] = $date->format('H:i:s');
Chris@14 61 $edit['body[0][value]'] = $this->randomMachineName();
Chris@14 62 $edit['field_tags[target_id]'] = $this->randomMachineName();
Chris@14 63 $this->drupalPostForm('node/add/article', $edit, t('Save'));
Chris@14 64 // Checks that the node has been saved.
Chris@14 65 $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
Chris@14 66 $this->assertEqual($node->getCreatedTime(), $date->getTimestamp(), 'Legacy node was saved with the right date.');
Chris@14 67 }
Chris@14 68
Chris@14 69 }