You are here

public function VendorHardeningPluginTest::testWriteAccessRestrictionFiles in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php \Drupal\Tests\Composer\Plugin\VendorHardening\VendorHardeningPluginTest::testWriteAccessRestrictionFiles()

@covers ::writeAccessRestrictionFiles

File

core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php, line 125

Class

VendorHardeningPluginTest
@coversDefaultClass \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin @group VendorHardening

Namespace

Drupal\Tests\Composer\Plugin\VendorHardening

Code

public function testWriteAccessRestrictionFiles() {
  $dir = vfsStream::url('vendor');

  // Set up mocks so that writeAccessRestrictionFiles() can eventually use
  // the IOInterface object.
  $composer = $this
    ->getMockBuilder(Composer::class)
    ->setMethods([
    'getPackage',
  ])
    ->getMock();
  $composer
    ->expects($this
    ->once())
    ->method('getPackage')
    ->willReturn($this
    ->prophesize(RootPackageInterface::class)
    ->reveal());
  $plugin = new VendorHardeningPlugin();
  $plugin
    ->activate($composer, $this
    ->prophesize(IOInterface::class)
    ->reveal());
  $this
    ->assertDirectoryExists($dir);
  $this
    ->assertFileNotExists($dir . '/.htaccess');
  $this
    ->assertFileNotExists($dir . '/web.config');
  $plugin
    ->writeAccessRestrictionFiles($dir);
  $this
    ->assertFileExists($dir . '/.htaccess');
  $this
    ->assertFileExists($dir . '/web.config');
}