ea822f928e7d8e01f209d51f998cbdea9ba3c823
[yaffs-website] / vendor / drupal-composer / drupal-scaffold / tests / FetcherTest.php
1 <?php
2
3 namespace DrupalComposer\DrupalScaffold\Tests;
4
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;
10
11 class FetcherTest extends TestCase {
12
13   /**
14    * @var \Composer\Util\Filesystem
15    */
16   protected $fs;
17
18   /**
19    * @var string
20    */
21   protected $tmpDir;
22
23   /**
24    * @var string
25    */
26   protected $rootDir;
27
28   /**
29    * @var string
30    */
31   protected $tmpReleaseTag;
32
33   /**
34    * SetUp test.
35    */
36   public function setUp() {
37     $this->rootDir = realpath(realpath(__DIR__ . '/..'));
38
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);
43
44     chdir($this->tmpDir);
45   }
46
47   /**
48    * Makes sure the given directory exists and has no content.
49    *
50    * @param string $directory
51    */
52   protected function ensureDirectoryExistsAndClear($directory) {
53     if (is_dir($directory)) {
54       $this->fs->removeDirectory($directory);
55     }
56     mkdir($directory, 0777, TRUE);
57   }
58
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',
64     ]);
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');
68   }
69
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',
74     ]);
75     $fetcher->fetch('8.1.1', $this->tmpDir, FALSE);
76     $this->assertFileExists($this->tmpDir . '/sites/default/settings.php');
77   }
78
79 }