5 * Contains \DrupalComposer\DrupalScaffold\Tests\FetcherTest.
8 namespace DrupalComposer\DrupalScaffold\Tests;
10 use Composer\Downloader\TransportException;
11 use Composer\IO\NullIO;
12 use Composer\Util\Filesystem;
13 use Composer\Util\RemoteFilesystem;
14 use DrupalComposer\DrupalScaffold\FileFetcher;
15 use DrupalComposer\DrupalScaffold\InitialFileFetcher;
17 class FetcherTest extends \PHPUnit_Framework_TestCase {
20 * @var \Composer\Util\Filesystem
37 protected $tmpReleaseTag;
42 public function setUp() {
43 $this->rootDir = realpath(realpath(__DIR__ . '/..'));
45 // Prepare temp directory.
46 $this->fs = new Filesystem();
47 $this->tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'drupal-scaffold';
48 $this->ensureDirectoryExistsAndClear($this->tmpDir);
54 * Makes sure the given directory exists and has no content.
56 * @param string $directory
58 protected function ensureDirectoryExistsAndClear($directory) {
59 if (is_dir($directory)) {
60 $this->fs->removeDirectory($directory);
62 mkdir($directory, 0777, true);
65 public function testFetch() {
66 $fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', ['.htaccess', 'sites/default/default.settings.php']);
67 $fetcher->fetch('8.1.1', $this->tmpDir);
68 $this->assertFileExists($this->tmpDir . '/.htaccess');
69 $this->assertFileExists($this->tmpDir . '/sites/default/default.settings.php');
73 * Tests version specific files.
75 public function testFetchVersionSpecific() {
76 $fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', ['.eslintrc', '.eslintrc.json']);
78 $this->setExpectedException(TransportException::class);
79 $fetcher->fetch('8.2.x', $this->tmpDir);
81 $this->assertFileExists($this->tmpDir . '/.eslintrc');
82 $this->assertFileNotExists($this->tmpDir . '/.eslintrc.json');
84 // Remove downloaded files to retest with 8.3.x.
85 @unlink($this->tmpDir . '/.eslintrc');
87 $this->setExpectedException(TransportException::class);
88 $fetcher->fetch('8.3.x', $this->tmpDir);
90 $this->assertFileExists($this->tmpDir . '/.eslintrc.json');
91 $this->assertFileNotExists($this->tmpDir . '/.eslintrc');
94 public function testInitialFetch() {
95 $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']);
96 $fetcher->fetch('8.1.1', $this->tmpDir);
97 $this->assertFileExists($this->tmpDir . '/sites/default/settings.php');