function BuildTestTest::testCopyCodebaseDocRoot

Same name and namespace in other branches
  1. 10 core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php \Drupal\BuildTests\Framework\Tests\BuildTestTest::testCopyCodebaseDocRoot()

Tests copying codebase when Drupal and Composer roots are different.

@covers ::copyCodebase

File

core/tests/Drupal/BuildTests/Framework/Tests/BuildTestTest.php, line 134

Class

BuildTestTest
@coversDefaultClass <a href="/api/drupal/core%21tests%21Drupal%21BuildTests%21Framework%21BuildTestBase.php/class/BuildTestBase/11.x" title="Provides a workspace to test build processes." class="local">\Drupal\BuildTests\Framework\BuildTestBase</a> @group Build

Namespace

Drupal\BuildTests\Framework\Tests

Code

public function testCopyCodebaseDocRoot() : void {
    // Create a virtual file system containing items that should be
    // excluded. Exception being modules directory.
    vfsStream::setup('drupal', NULL, [
        'docroot' => [
            'sites' => [
                'default' => [
                    'files' => [
                        'a_file.txt' => 'some file.',
                    ],
                    'settings.php' => '<?php $settings = "stuff";',
                    'settings.local.php' => '<?php $settings = "override";',
                    'default.settings.php' => '<?php $settings = "default";',
                ],
                'simpletest' => [
                    'simpletest_hash' => [
                        'some_results.xml' => '<xml/>',
                    ],
                ],
            ],
            'modules' => [
                'my_module' => [
                    'vendor' => [
                        'my_vendor' => [
                            'composer.json' => "{\n}",
                        ],
                    ],
                ],
            ],
        ],
        'vendor' => [
            'test.txt' => 'File exists',
        ],
    ]);
    // Mock BuildTestBase so that it thinks our VFS is the Composer and Drupal
    // roots.
    
    /** @var \PHPUnit\Framework\MockObject\MockBuilder|\Drupal\BuildTests\Framework\BuildTestBase $base */
    $base = $this->getMockBuilder(BuildTestBase::class)
        ->onlyMethods([
        'getDrupalRoot',
        'getComposerRoot',
    ])
        ->setConstructorArgs([
        'test',
    ])
        ->getMockForAbstractClass();
    $base->expects($this->exactly(3))
        ->method('getDrupalRoot')
        ->willReturn(vfsStream::url('drupal/docroot'));
    $base->expects($this->exactly(5))
        ->method('getComposerRoot')
        ->willReturn(vfsStream::url('drupal'));
    $base->setUp();
    // Perform the copy.
    $base->copyCodebase();
    $full_path = $base->getWorkspaceDirectory();
    $this->assertDirectoryExists($full_path . '/docroot');
    // Verify expected files exist.
    $this->assertFileExists($full_path . DIRECTORY_SEPARATOR . 'docroot/modules/my_module/vendor/my_vendor/composer.json');
    $this->assertFileExists($full_path . DIRECTORY_SEPARATOR . 'docroot/sites/default/default.settings.php');
    $this->assertFileExists($full_path . DIRECTORY_SEPARATOR . 'vendor');
    // Verify expected files do not exist
    $this->assertFileDoesNotExist($full_path . DIRECTORY_SEPARATOR . 'docroot/sites/default/settings.php');
    $this->assertFileDoesNotExist($full_path . DIRECTORY_SEPARATOR . 'docroot/sites/default/settings.local.php');
    $this->assertFileDoesNotExist($full_path . DIRECTORY_SEPARATOR . 'docroot/sites/default/files');
    // Ensure that the workspace Drupal root is calculated correctly.
    $this->assertSame($full_path . '/docroot/', $base->getWorkspaceDrupalRoot());
    $this->assertSame('docroot/', $base->getWorkingPathDrupalRoot());
    $base->tearDown();
}

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