Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Tests\node\Functional; | 3 namespace Drupal\Tests\node\Functional; |
4 | 4 |
5 use Drupal\block\Entity\Block; | 5 use Drupal\block\Entity\Block; |
6 use Drupal\Core\Database\Database; | |
6 use Drupal\Core\EventSubscriber\MainContentViewSubscriber; | 7 use Drupal\Core\EventSubscriber\MainContentViewSubscriber; |
7 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait; | 8 use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait; |
8 use Drupal\user\RoleInterface; | 9 use Drupal\user\RoleInterface; |
9 | 10 |
10 /** | 11 /** |
67 $default_settings = ['uid' => $this->webUser->id(), 'type' => 'article']; | 68 $default_settings = ['uid' => $this->webUser->id(), 'type' => 'article']; |
68 $node1 = $this->drupalCreateNode($default_settings); | 69 $node1 = $this->drupalCreateNode($default_settings); |
69 $node2 = $this->drupalCreateNode($default_settings); | 70 $node2 = $this->drupalCreateNode($default_settings); |
70 $node3 = $this->drupalCreateNode($default_settings); | 71 $node3 = $this->drupalCreateNode($default_settings); |
71 | 72 |
73 $connection = Database::getConnection(); | |
72 // Change the changed time for node so that we can test ordering. | 74 // Change the changed time for node so that we can test ordering. |
73 db_update('node_field_data') | 75 $connection->update('node_field_data') |
74 ->fields([ | 76 ->fields([ |
75 'changed' => $node1->getChangedTime() + 100, | 77 'changed' => $node1->getChangedTime() + 100, |
76 ]) | 78 ]) |
77 ->condition('nid', $node2->id()) | 79 ->condition('nid', $node2->id()) |
78 ->execute(); | 80 ->execute(); |
79 db_update('node_field_data') | 81 $connection->update('node_field_data') |
80 ->fields([ | 82 ->fields([ |
81 'changed' => $node1->getChangedTime() + 200, | 83 'changed' => $node1->getChangedTime() + 200, |
82 ]) | 84 ]) |
83 ->condition('nid', $node3->id()) | 85 ->condition('nid', $node3->id()) |
84 ->execute(); | 86 ->execute(); |
154 // The node/add/article page is an admin path and currently uncacheable. | 156 // The node/add/article page is an admin path and currently uncacheable. |
155 $this->assertSame('UNCACHEABLE', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); | 157 $this->assertSame('UNCACHEABLE', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); |
156 | 158 |
157 $this->drupalGet('node/' . $node1->id()); | 159 $this->drupalGet('node/' . $node1->id()); |
158 $this->assertText($label, 'Block was displayed on the node/N when node is of type article.'); | 160 $this->assertText($label, 'Block was displayed on the node/N when node is of type article.'); |
159 $this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user', 'route', 'timezone']); | 161 $this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'url.site', 'user', 'route', 'timezone']); |
160 $this->assertSame('MISS', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); | 162 $this->assertSame('MISS', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); |
161 $this->drupalGet('node/' . $node1->id()); | 163 $this->drupalGet('node/' . $node1->id()); |
162 $this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); | 164 $this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); |
163 | 165 |
164 $this->drupalGet('node/' . $node5->id()); | 166 $this->drupalGet('node/' . $node5->id()); |
165 $this->assertNoText($label, 'Block was not displayed on nodes of type page.'); | 167 $this->assertNoText($label, 'Block was not displayed on nodes of type page.'); |
166 $this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'user', 'route', 'timezone']); | 168 $this->assertCacheContexts(['languages:language_content', 'languages:language_interface', 'theme', 'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT, 'url.site', 'user', 'route', 'timezone']); |
167 $this->assertSame('MISS', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); | 169 $this->assertSame('MISS', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); |
168 $this->drupalGet('node/' . $node5->id()); | 170 $this->drupalGet('node/' . $node5->id()); |
169 $this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); | 171 $this->assertSame('HIT', $this->getSession()->getResponseHeader('X-Drupal-Dynamic-Cache')); |
170 | 172 |
171 $this->drupalLogin($this->adminUser); | 173 $this->drupalLogin($this->adminUser); |
172 $this->drupalGet('admin/structure/block'); | 174 $this->drupalGet('admin/structure/block'); |
173 $this->assertText($label, 'Block was displayed on the admin/structure/block page.'); | 175 $this->assertText($label, 'Block was displayed on the admin/structure/block page.'); |
174 $this->assertLinkByHref($block->url()); | 176 $this->assertLinkByHref($block->toUrl()->toString()); |
175 } | 177 } |
176 | 178 |
177 } | 179 } |