Commit 3c0a42d2 authored by catch's avatar catch
Browse files

Issue #3414589 by Spokje: Convert SearchSetLocaleTest into a Kernel test

parent edf50e18
Loading
Loading
Loading
Loading
Loading
+102 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\search\Functional;
namespace Drupal\Tests\search\Kernel;

use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Plugin\Search\NodeSearch;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;

/**
 * Tests that search works with numeric locale settings.
 *
 * @group search
 */
class SearchSetLocaleTest extends BrowserTestBase {
class SearchSetLocaleTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['comment', 'node', 'search'];
  use ContentTypeCreationTrait;
  use NodeCreationTrait;
  use UserCreationTrait;

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  protected static $modules = [
    'field',
    'filter',
    'node',
    'search',
    'system',
    'text',
    'user',
  ];

  /**
   * A node search plugin instance.
   *
   * @var \Drupal\search\Plugin\SearchInterface
   */
  protected $nodeSearchPlugin;
  protected NodeSearch $nodeSearchPlugin;

  /**
   * {@inheritdoc}
@@ -34,12 +44,44 @@ class SearchSetLocaleTest extends BrowserTestBase {
  protected function setUp(): void {
    parent::setUp();

    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
    $this->installSchema('node', ['node_access']);
    $this->installSchema('search', ['search_index', 'search_dataset', 'search_total']);
    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installConfig(['filter', 'node', 'search']);

    // Create the anonymous user account and set it as current user.
    $this->setUpCurrentUser(['uid' => 0]);

    // Create a node type.
    $this->createContentType([
      'type' => 'page',
      'name' => 'Basic page',
    ]);

    // Create a plugin instance.
    $this->nodeSearchPlugin = $this->container->get('plugin.manager.search')->createInstance('node_search');

    // Create a node with a very simple body.
    $this->drupalCreateNode(['body' => [['value' => 'tapir']]]);
    $this->createNode(
      [
        'body' => [
          [
            'value' => 'tapir',
          ],
        ],
        'uid' => 0,
      ]
    );

    // Create the fallback date format.
    DateFormat::create([
      'id' => 'fallback',
      'label' => 'Fallback date format',
      'pattern' => 'D, m/d/Y - H:i',
      'locked' => TRUE,
    ])->save();

    // Update the search index.
    $this->nodeSearchPlugin->updateIndex();
  }
@@ -47,7 +89,7 @@ protected function setUp(): void {
  /**
   * Verify that search works with a numeric locale set.
   */
  public function testSearchWithNumericLocale() {
  public function testSearchWithNumericLocale(): void {
    // French decimal point is comma.
    setlocale(LC_NUMERIC, 'fr_FR');
    $this->nodeSearchPlugin->setSearch('tapir', [], []);