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');
72 public function testInitialFetch() {
73 $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']);
74 $fetcher->fetch('8.1.1', $this->tmpDir);
75 $this->assertFileExists($this->tmpDir . '/sites/default/settings.php');