SearchPageResourceTestBase.php

Same filename and directory in other branches
  1. 9 core/modules/search/tests/src/Functional/Rest/SearchPageResourceTestBase.php
  2. 8.9.x core/modules/search/tests/src/Functional/Rest/SearchPageResourceTestBase.php
  3. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/SearchPage/SearchPageResourceTestBase.php
  4. 10 core/modules/search/tests/src/Functional/Rest/SearchPageResourceTestBase.php

Namespace

Drupal\Tests\search\Functional\Rest

File

core/modules/search/tests/src/Functional/Rest/SearchPageResourceTestBase.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\search\Functional\Rest;

use Drupal\search\Entity\SearchPage;
use Drupal\Tests\rest\Functional\EntityResource\ConfigEntityResourceTestBase;
// cspell:ignore hinode

/**
 * Base class for Search page tests.
 */
abstract class SearchPageResourceTestBase extends ConfigEntityResourceTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'node',
        'search',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected static $entityTypeId = 'search_page';
    
    /**
     * @var \Drupal\search\SearchPageInterface
     */
    protected $entity;
    
    /**
     * {@inheritdoc}
     */
    protected function setUpAuthorization($method) {
        switch ($method) {
            case 'GET':
                $this->grantPermissionsToTestedRole([
                    'access content',
                ]);
                break;
            case 'POST':
            case 'PATCH':
            case 'DELETE':
                $this->grantPermissionsToTestedRole([
                    'administer search',
                ]);
                break;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    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;
    }
    
    /**
     * {@inheritdoc}
     */
    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,
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getNormalizedPostEntity() {
        // @todo Update in https://www.drupal.org/node/2300677.
        return [];
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedUnauthorizedAccessMessage($method) {
        switch ($method) {
            case 'GET':
                return "The 'access content' permission is required.";
            default:
                return parent::getExpectedUnauthorizedAccessMessage($method);
        }
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getExpectedUnauthorizedEntityAccessCacheability($is_authenticated) {
        // @see \Drupal\search\SearchPageAccessControlHandler::checkAccess()
        return parent::getExpectedUnauthorizedEntityAccessCacheability($is_authenticated)->addCacheTags([
            'config:search.page.hinode_search',
        ]);
    }

}

Classes

Title Deprecated Summary
SearchPageResourceTestBase Base class for Search page tests.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.