Commit 86f62c10 authored by alexpott's avatar alexpott

Issue #2372899 by mpdonadio, Berdir: PageCacheTagsTestBase should use Url objects

parent b8378ac5
......@@ -7,6 +7,7 @@
namespace Drupal\menu_ui\Tests;
use Drupal\Core\Url;
use Drupal\system\Tests\Cache\PageCacheTagsTestBase;
/**
......@@ -28,7 +29,7 @@ class MenuCacheTagsTest extends PageCacheTagsTestBase {
* - "menu:<menu ID>"
*/
public function testMenuBlock() {
$path = 'test-page';
$url = Url::fromRoute('test_page_test.test_page');
// Create a Llama menu, add a link to it and place the corresponding block.
$menu = entity_create('menu', array(
......@@ -44,7 +45,7 @@ public function testMenuBlock() {
$block = $this->drupalPlaceBlock('system_menu_block:llama', array('label' => 'Llama', 'provider' => 'system', 'region' => 'footer'));
// Prime the page cache.
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit, but also the presence of the correct cache tags.
$expected_tags = array(
......@@ -55,24 +56,24 @@ public function testMenuBlock() {
'block_plugin:system_menu_block__llama',
'config:system.menu.llama',
);
$this->verifyPageCache($path, 'HIT', $expected_tags);
$this->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after modifying the menu, there is a cache miss.
$this->pass('Test modification of menu.', 'Debug');
$menu->set('label', 'Awesome llama');
$menu->save();
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$this->verifyPageCache($path, 'HIT');
$this->verifyPageCache($url, 'HIT');
// Verify that after modifying the menu link weight, there is a cache miss.
$menu_link_manager->updateDefinition('test_page_test.test_page', array('weight' => -10));
$this->pass('Test modification of menu link.', 'Debug');
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$this->verifyPageCache($path, 'HIT');
$this->verifyPageCache($url, 'HIT');
// Verify that after adding a menu link, there is a cache miss.
$this->pass('Test addition of menu link.', 'Debug');
......@@ -85,27 +86,27 @@ public function testMenuBlock() {
'bundle' => 'menu_name',
));
$menu_link_2->save();
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$this->verifyPageCache($path, 'HIT');
$this->verifyPageCache($url, 'HIT');
// Verify that after resetting the first menu link, there is a cache miss.
$this->pass('Test reset of menu link.', 'Debug');
$this->assertTrue($menu_link->isResettable(), 'First link can be reset');
$menu_link = $menu_link_manager->resetLink($menu_link->getPluginId());
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$this->verifyPageCache($path, 'HIT', $expected_tags);
$this->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after deleting the menu, there is a cache miss.
$this->pass('Test deletion of menu.', 'Debug');
$menu->delete();
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$this->verifyPageCache($path, 'HIT', ['config:block_list', 'rendered']);
$this->verifyPageCache($url, 'HIT', ['config:block_list', 'rendered']);
}
}
......@@ -7,7 +7,7 @@
namespace Drupal\system\Tests\Cache;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
use Drupal\Component\Utility\String;
......@@ -39,8 +39,8 @@ protected function setUp() {
/**
* Verify that when loading a given page, it's a page cache hit or miss.
*
* @param string $path
* The page at this path will be loaded.
* @param \Drupal\Core\Url $url
* The page for this URL will be loaded.
* @param string $hit_or_miss
* 'HIT' if a page cache hit is expected, 'MISS' otherwise.
*
......@@ -48,13 +48,13 @@ protected function setUp() {
* When expecting a page cache hit, you may optionally specify an array of
* expected cache tags. While FALSE, the cache tags will not be verified.
*/
protected function verifyPageCache($path, $hit_or_miss, $tags = FALSE) {
$this->drupalGet($path);
$message = String::format('Page cache @hit_or_miss for %path.', array('@hit_or_miss' => $hit_or_miss, '%path' => $path));
protected function verifyPageCache(Url $url, $hit_or_miss, $tags = FALSE) {
$this->drupalGet($url);
$message = String::format('Page cache @hit_or_miss for %path.', array('@hit_or_miss' => $hit_or_miss, '%path' => $url->toString()));
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), $hit_or_miss, $message);
if ($hit_or_miss === 'HIT' && is_array($tags)) {
$absolute_url = UrlHelper::isExternal($path) ? $path : _url($path, array('absolute' => TRUE));
$absolute_url = $url->setAbsolute()->toString();
$cid_parts = array($absolute_url, 'html');
$cid = implode(':', $cid_parts);
$cache_entry = \Drupal::cache('render')->get($cid);
......
......@@ -24,7 +24,7 @@ abstract class EntityWithUriCacheTagsTestBase extends EntityCacheTagsTestBase {
* - "<entity_type>:<entity ID>"
*/
public function testEntityUri() {
$entity_url = $this->entity->urlInfo()->setAbsolute()->toString();
$entity_url = $this->entity->urlInfo();
$entity_type = $this->entity->getEntityTypeId();
// Selects the view mode that will be used.
......
......@@ -7,6 +7,7 @@
namespace Drupal\tour\Tests;
use Drupal\Core\Url;
use Drupal\system\Tests\Cache\PageCacheTagsTestBase;
use Drupal\tour\Entity\Tour;
use Drupal\user\Entity\Role;
......@@ -42,36 +43,36 @@ protected function setUp() {
* - 'tour:<tour ID>'
*/
public function testRenderedTour() {
$path = 'tour-test-1';
$url = Url::fromRoute('tour_test.1');
// Prime the page cache.
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit, but also the presence of the correct cache tags.
$expected_tags = [
'config:tour.tour.tour-test',
'rendered',
];
$this->verifyPageCache($path, 'HIT', $expected_tags);
$this->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after modifying the tour, there is a cache miss.
$this->pass('Test modification of tour.', 'Debug');
Tour::load('tour-test')->save();
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$this->verifyPageCache($path, 'HIT', $expected_tags);
$this->verifyPageCache($url, 'HIT', $expected_tags);
// Verify that after deleting the tour, there is a cache miss.
$this->pass('Test deletion of tour.', 'Debug');
Tour::load('tour-test')->delete();
$this->verifyPageCache($path, 'MISS');
$this->verifyPageCache($url, 'MISS');
// Verify a cache hit.
$expected_tags = [
'rendered',
];
$this->verifyPageCache($path, 'HIT', $expected_tags);
$this->verifyPageCache($url, 'HIT', $expected_tags);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment