CacheabilityTest.php in Search API 8
File
tests/src/Functional/CacheabilityTest.php
View source
<?php
namespace Drupal\Tests\search_api\Functional;
use Drupal\block\Entity\Block;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\search_api\Entity\Index;
use Drupal\search_api\Entity\Task;
class CacheabilityTest extends SearchApiBrowserTestBase {
use ExampleContentTrait;
public static $modules = [
'rest',
'search_api',
'search_api_test',
'search_api_test_views',
];
public function setUp() {
parent::setUp();
$this
->setUpExampleStructure();
$this
->insertExampleContent();
\Drupal::getContainer()
->get('search_api.index_task_manager')
->addItemsAll(Index::load($this->indexId));
$this
->indexItems($this->indexId);
}
public function testFramework() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('search-api-test');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseHeaderEquals('x-drupal-dynamic-cache', 'UNCACHEABLE');
$this
->assertStringContainsString('no-cache', $this
->drupalGetHeader('cache-control'));
$this
->assertSession()
->pageTextContains('foo test');
$this
->assertSession()
->pageTextContains('foo baz');
}
public function testExecuteTasksAction() {
$success = \Drupal::getContainer()
->get('module_installer')
->install([
'block',
], TRUE);
$this
->assertTrue($success, new FormattableMarkup('Enabled modules: %modules', [
'%modules' => 'block',
]));
Block::create([
'id' => 'stark_local_actions',
'theme' => 'stark',
'weight' => -20,
'plugin' => 'local_actions_block',
'region' => 'content',
])
->save();
$assert_session = $this
->assertSession();
$admin_path = 'admin/config/search/search-api';
$this
->drupalLogin($this->adminUser);
$this
->drupalGet($admin_path);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Execute pending tasks');
$this
->drupalGet($admin_path);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Execute pending tasks');
$task = Task::create([]);
$task
->save();
$this
->drupalGet($admin_path);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('Execute pending tasks');
$this
->drupalGet($admin_path);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('Execute pending tasks');
$task
->delete();
$this
->drupalGet($admin_path);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Execute pending tasks');
$this
->drupalGet($admin_path);
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextNotContains('Execute pending tasks');
}
public function testViewsCacheAddRemoveContent() {
$entity = $this
->addTestEntity(6, [
'name' => 'Fresh node',
'body' => 'test foobar Case',
'type' => 'item',
]);
$this
->drupalGet('search-api-test-search-view-caching-tag');
$this
->assertSession()
->pageTextContains('Displaying 5 search results');
$this
->indexItems($this->indexId);
$this
->drupalGet('search-api-test-search-view-caching-tag');
$this
->assertSession()
->pageTextContains('Displaying 6 search results');
$entity
->delete();
$this
->drupalGet('search-api-test-search-view-caching-tag');
$this
->assertSession()
->pageTextContains('Displaying 5 search results');
}
}