3 namespace DrupalComposer\DrupalScaffold\Tests;
5 use Composer\IO\NullIO;
6 use Composer\Util\Filesystem;
7 use Composer\Util\RemoteFilesystem;
8 use DrupalComposer\DrupalScaffold\FileFetcher;
9 use PHPUnit\Framework\TestCase;
11 class FetcherTest extends TestCase {
14 * @var \Composer\Util\Filesystem
31 protected $tmpReleaseTag;
36 public function setUp() {
37 $this->rootDir = realpath(realpath(__DIR__ . '/..'));
39 // Prepare temp directory.
40 $this->fs = new Filesystem();
41 $this->tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'drupal-scaffold';
42 $this->ensureDirectoryExistsAndClear($this->tmpDir);
48 * Makes sure the given directory exists and has no content.
50 * @param string $directory
52 protected function ensureDirectoryExistsAndClear($directory) {
53 if (is_dir($directory)) {
54 $this->fs->removeDirectory($directory);
56 mkdir($directory, 0777, TRUE);
59 public function testFetch() {
60 $fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'https://cgit.drupalcode.org/drupal/plain/{path}?h={version}', new NullIO());
61 $fetcher->setFilenames([
62 '.htaccess' => '.htaccess',
63 'sites/default/default.settings.php' => 'sites/default/default.settings.php',
65 $fetcher->fetch('8.1.1', $this->tmpDir, TRUE);
66 $this->assertFileExists($this->tmpDir . '/.htaccess');
67 $this->assertFileExists($this->tmpDir . '/sites/default/default.settings.php');
70 public function testInitialFetch() {
71 $fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'https://cgit.drupalcode.org/drupal/plain/{path}?h={version}', new NullIO());
72 $fetcher->setFilenames([
73 'sites/default/default.settings.php' => 'sites/default/settings.php',
75 $fetcher->fetch('8.1.1', $this->tmpDir, FALSE);
76 $this->assertFileExists($this->tmpDir . '/sites/default/settings.php');