Version 1
[yaffs-website] / web / core / modules / node / tests / src / Functional / NodeFormSaveChangedTimeTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests updating the changed time after API and FORM entity save.
9  *
10  * @group node
11  */
12 class NodeFormSaveChangedTimeTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = [
20     'node',
21   ];
22
23   /**
24    * An user with permissions to create and edit articles.
25    *
26    * @var \Drupal\user\UserInterface
27    */
28   protected $authorUser;
29
30   /**
31    * {@inheritdoc}
32    */
33   protected function setUp() {
34     parent::setUp();
35
36     // Create a node type.
37     $this->drupalCreateContentType([
38       'type' => 'article',
39       'name' => 'Article',
40     ]);
41
42     $this->authorUser = $this->drupalCreateUser(['access content', 'create article content', 'edit any article content'], 'author');
43     $this->drupalLogin($this->authorUser);
44
45     // Create one node of the above node type .
46     $this->drupalCreateNode([
47       'type' => 'article',
48     ]);
49   }
50
51   /**
52    * Test the changed time after API and FORM save without changes.
53    */
54   public function testChangedTimeAfterSaveWithoutChanges() {
55     $storage = $this->container->get('entity_type.manager')->getStorage('node');
56     $storage->resetCache([1]);
57     $node = $storage->load(1);
58     $changed_timestamp = $node->getChangedTime();
59     $node->save();
60     $storage->resetCache([1]);
61     $node = $storage->load(1);
62     $this->assertEqual($changed_timestamp, $node->getChangedTime(), "The entity's changed time wasn't updated after API save without changes.");
63
64     // Ensure different save timestamps.
65     sleep(1);
66
67     // Save the node on the regular node edit form.
68     $this->drupalPostForm('node/1/edit', [], t('Save'));
69
70     $storage->resetCache([1]);
71     $node = $storage->load(1);
72     $this->assertNotEqual($changed_timestamp, $node->getChangedTime(), "The entity's changed time was updated after form save without changes.");
73   }
74
75 }