This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/web/vendor/drupal-composer/drupal-scaffold/tests/FetcherTest.php

100 lines
2.9 KiB
PHP
Raw Normal View History

2017-03-16 15:11:34 +00:00
<?php
/**
* @file
* Contains \DrupalComposer\DrupalScaffold\Tests\FetcherTest.
*/
namespace DrupalComposer\DrupalScaffold\Tests;
use Composer\Downloader\TransportException;
use Composer\IO\NullIO;
use Composer\Util\Filesystem;
use Composer\Util\RemoteFilesystem;
use DrupalComposer\DrupalScaffold\FileFetcher;
use DrupalComposer\DrupalScaffold\InitialFileFetcher;
class FetcherTest extends \PHPUnit_Framework_TestCase {
/**
* @var \Composer\Util\Filesystem
*/
protected $fs;
/**
* @var string
*/
protected $tmpDir;
/**
* @var string
*/
protected $rootDir;
/**
* @var string
*/
protected $tmpReleaseTag;
/**
* SetUp test
*/
public function setUp() {
$this->rootDir = realpath(realpath(__DIR__ . '/..'));
// Prepare temp directory.
$this->fs = new Filesystem();
$this->tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'drupal-scaffold';
$this->ensureDirectoryExistsAndClear($this->tmpDir);
chdir($this->tmpDir);
}
/**
* Makes sure the given directory exists and has no content.
*
* @param string $directory
*/
protected function ensureDirectoryExistsAndClear($directory) {
if (is_dir($directory)) {
$this->fs->removeDirectory($directory);
}
mkdir($directory, 0777, true);
}
public function testFetch() {
$fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', ['.htaccess', 'sites/default/default.settings.php']);
$fetcher->fetch('8.1.1', $this->tmpDir);
$this->assertFileExists($this->tmpDir . '/.htaccess');
$this->assertFileExists($this->tmpDir . '/sites/default/default.settings.php');
}
/**
* Tests version specific files.
*/
public function testFetchVersionSpecific() {
$fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', ['.eslintrc', '.eslintrc.json']);
$this->setExpectedException(TransportException::class);
$fetcher->fetch('8.2.x', $this->tmpDir);
$this->assertFileExists($this->tmpDir . '/.eslintrc');
$this->assertFileNotExists($this->tmpDir . '/.eslintrc.json');
// Remove downloaded files to retest with 8.3.x.
@unlink($this->tmpDir . '/.eslintrc');
$this->setExpectedException(TransportException::class);
$fetcher->fetch('8.3.x', $this->tmpDir);
$this->assertFileExists($this->tmpDir . '/.eslintrc.json');
$this->assertFileNotExists($this->tmpDir . '/.eslintrc');
}
public function testInitialFetch() {
$fetcher = new InitialFileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', ['sites/default/default.settings.php' => 'sites/default/settings.php']);
$fetcher->fetch('8.1.1', $this->tmpDir);
$this->assertFileExists($this->tmpDir . '/sites/default/settings.php');
}
}