filecache-8.x-1.0-alpha3/tests/src/Kernel/FileSystemBackendTest.php

tests/src/Kernel/FileSystemBackendTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\filecache\Kernel;

use Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase;

/**
 * Tests the FileSystemBackend cache backend.
 *
 * @group filecache
 */
class FileSystemBackendTest extends GenericCacheBackendUnitTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'file',
    'filecache',
    'system',
    'user',
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    $this->installConfig(['system']);
    $this->installEntitySchema('file');
    $this->installEntitySchema('user');
    $this->installSchema('file', ['file_usage']);
  }

  /**
   * {@inheritdoc}
   */
  protected function createCacheBackend($bin) {
    // Set the FileSystemBackend as the default cache backend.
    $this->setSetting('cache', ['default' => 'cache.backend.file_system']);

    $base_path = $this->config('system.file')->get('default_scheme') . '://filecache';

    $cache_path_settings = [
      'directory' => [
        'default' => $base_path,
        'bins' => [
          'foo' => $base_path . '/foo',
          'bar' => $base_path . '/bar',
        ],
      ],
    ];
    $this->setSetting('filecache', $cache_path_settings);

    return $this->container->get('cache.backend.file_system')->get($bin);
  }

  /**
   * {@inheritdoc}
   */
  protected function tearDown(): void {
    // The parent method will loop over all cache backends used in the test and
    // call ::deleteAll() on them to get rid of persistent cache data. This
    // doesn't work for us since we are using the virtual file system which is
    // no longer available after the test completes. We don't need to worry
    // about cache data persisting after the test since the virtual file system
    // is cleaned up in KernelTestBase::tearDown().
    // @deprecated The ::cachebackends property has been deprecated in
    // drupal:10.0.0 and is renamed to ::cacheBackends in drupal:11.0.0.
    if (property_exists($this, 'cachebackends')) {
      $this->cachebackends = [];
    }
    if (property_exists($this, 'cacheBackends')) {
      $this->cacheBackends = [];
    }
    parent::tearDown();
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc