You are here

public function SplitFilterTest::testSplitFilterCreate in Configuration Split 8

Test that the static create method works and folders contain the htaccess.

File

src/Tests/SplitFilterTest.php, line 510

Class

SplitFilterTest
Test filter plugin.

Namespace

Drupal\config_split\Tests

Code

public function testSplitFilterCreate() {
  $name = 'config_split.' . $this
    ->getRandomGenerator()
    ->name();

  // Set the split stream up.
  $folder = vfsStream::setup($name);
  $container = $this
    ->prophesize('Symfony\\Component\\DependencyInjection\\ContainerInterface');
  $container
    ->get('config.manager')
    ->willReturn($this
    ->getConfigManagerMock());
  $container
    ->get('config.factory')
    ->willReturn($this
    ->getConfigFactoryStub([
    $name => [
      'folder' => $folder
        ->url(),
      'module' => [],
      'theme' => [],
      'blacklist' => [],
      'graylist' => [],
    ],
  ]));
  $database = $this
    ->prophesize('Drupal\\Core\\Database\\Connection');
  $container
    ->get('database')
    ->willReturn($database
    ->reveal());
  $configuration = [
    'config_name' => $name,
  ];
  $filter = SplitFilter::create($container
    ->reveal(), $configuration, $this
    ->getRandomGenerator()
    ->name(), []);
  $this
    ->assertTrue($folder
    ->hasChild('.htaccess'), 'htaccess written to split folder.');
  $folder
    ->addChild(new vfsStreamFile($name . '.' . FileStorage::getFileExtension()));
  $this
    ->assertTrue($filter
    ->filterExists($name, FALSE), 'Assert filename');

  // Test split with db storage.
  $name = 'config_split.' . $this
    ->getRandomGenerator()
    ->name();
  $container = $this
    ->prophesize('Symfony\\Component\\DependencyInjection\\ContainerInterface');
  $container
    ->get('config.manager')
    ->willReturn($this
    ->getConfigManagerMock());
  $container
    ->get('config.factory')
    ->willReturn($this
    ->getConfigFactoryStub([
    $name => [
      'folder' => '',
      'module' => [],
      'theme' => [],
      'blacklist' => [],
      'graylist' => [],
    ],
  ]));
  $database = $this
    ->prophesize('Drupal\\Core\\Database\\Connection')
    ->reveal();
  $container
    ->get('database')
    ->willReturn($database);
  $configuration = [
    'config_name' => $name,
  ];
  $filter = SplitFilter::create($container
    ->reveal(), $configuration, $this
    ->getRandomGenerator()
    ->name(), []);

  // Get the protected secondaryStorage property.
  $storage = new \ReflectionProperty(SplitFilter::class, 'secondaryStorage');
  $storage
    ->setAccessible(TRUE);
  $secondary = $storage
    ->getValue($filter);
  $this
    ->assertInstanceOf(DatabaseStorage::class, $secondary);
}