CacheExampleTest.php in Examples for Developers 3.x
File
modules/cache_example/tests/src/Functional/CacheExampleTest.php
View source
<?php
namespace Drupal\Tests\cache_example\Functional;
use Drupal\Tests\BrowserTestBase;
class CacheExampleTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'cache_example',
];
protected $profile = 'minimal';
public function testCacheExampleMenu() {
$assert = $this
->assertSession();
$this
->drupalGet('');
$assert
->statusCodeEquals(200);
$assert
->linkByHrefExists('examples/cache-example');
$this
->drupalGet('examples/cache-example');
$assert
->statusCodeEquals(200);
}
public function testCacheExampleBasic() {
$assert = $this
->assertSession();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('examples/cache-example');
$assert
->pageTextContains('Source: actual file search');
$this
->drupalGet('examples/cache-example');
$assert
->pageTextContains('Source: cached');
$this
->drupalPostForm('examples/cache-example', [], 'Explicitly remove cached file count');
$assert
->pageTextContains('Source: actual file search');
$assert
->pageTextContains('Cache item does not exist');
$this
->drupalPostForm('examples/cache-example', [
'expiration' => -10,
], 'Create a cache item with this expiration');
$assert
->pageTextContains('Cache_item is invalid');
$this
->drupalPostForm('examples/cache-example', [
'cache_clear_type' => 'expire',
], 'Clear or expire cache');
$assert
->pageTextContains('Cache item does not exist');
$this
->drupalPostForm('examples/cache-example', [
'expiration' => 'never_remove',
], 'Create a cache item with this expiration');
$assert
->pageTextContains('Cache item exists and is set to expire at Never expires');
$this
->drupalPostForm('examples/cache-example', [
'cache_clear_type' => 'expire',
], 'Clear or expire cache');
$assert
->pageTextContains('Cache item exists and is set to expire at Never expires');
$this
->drupalPostForm('examples/cache-example', [
'cache_clear_type' => 'remove_tag',
], 'Clear or expire cache');
$assert
->pageTextContains('Cache_item is invalid');
$this
->drupalPostForm('examples/cache-example', [
'cache_clear_type' => 'remove_all',
], 'Clear or expire cache');
$assert
->pageTextContains('Cache item does not exist');
}
}