View source
<?php
namespace Drupal\Tests\search\Functional\Rest;
use Drupal\search\Entity\SearchPage;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
abstract class SearchPageResourceTestBase extends EntityResourceTestBase {
public static $modules = [
'node',
'search',
];
protected static $entityTypeId = 'search_page';
protected $entity;
protected function setUpAuthorization($method) {
switch ($method) {
case 'GET':
$this
->grantPermissionsToTestedRole([
'access content',
]);
break;
case 'POST':
case 'PATCH':
case 'DELETE':
$this
->grantPermissionsToTestedRole([
'administer search',
]);
break;
}
}
protected function createEntity() {
$search_page = SearchPage::create([
'id' => 'hinode_search',
'plugin' => 'node_search',
'label' => 'Search of magnetic activity of the Sun',
'path' => 'sun',
]);
$search_page
->save();
return $search_page;
}
protected function getExpectedNormalizedEntity() {
return [
'configuration' => [
'rankings' => [],
],
'dependencies' => [
'module' => [
'node',
],
],
'id' => 'hinode_search',
'label' => 'Search of magnetic activity of the Sun',
'langcode' => 'en',
'path' => 'sun',
'plugin' => 'node_search',
'status' => TRUE,
'uuid' => $this->entity
->uuid(),
'weight' => 0,
];
}
protected function getNormalizedPostEntity() {
}
protected function getExpectedUnauthorizedAccessMessage($method) {
if ($this
->config('rest.settings')
->get('bc_entity_resource_permissions')) {
return parent::getExpectedUnauthorizedAccessMessage($method);
}
switch ($method) {
case 'GET':
return "The 'access content' permission is required.";
default:
return parent::getExpectedUnauthorizedAccessMessage($method);
}
}
protected function getExpectedUnauthorizedEntityAccessCacheability($is_authenticated) {
return parent::getExpectedUnauthorizedEntityAccessCacheability($is_authenticated)
->addCacheTags([
'config:search.page.hinode_search',
]);
}
}