Yaffs site version 1.1
[yaffs-website] / vendor / drupal-composer / drupal-scaffold / tests / FetcherTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \DrupalComposer\DrupalScaffold\Tests\FetcherTest.
6  */
7
8 namespace DrupalComposer\DrupalScaffold\Tests;
9
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;
16
17 class FetcherTest extends \PHPUnit_Framework_TestCase {
18
19   /**
20    * @var \Composer\Util\Filesystem
21    */
22   protected $fs;
23
24   /**
25    * @var string
26    */
27   protected $tmpDir;
28
29   /**
30    * @var string
31    */
32   protected $rootDir;
33
34   /**
35    * @var string
36    */
37   protected $tmpReleaseTag;
38
39   /**
40    * SetUp test
41    */
42   public function setUp() {
43     $this->rootDir = realpath(realpath(__DIR__ . '/..'));
44
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);
49
50     chdir($this->tmpDir);
51   }
52
53   /**
54    * Makes sure the given directory exists and has no content.
55    *
56    * @param string $directory
57    */
58   protected function ensureDirectoryExistsAndClear($directory) {
59     if (is_dir($directory)) {
60       $this->fs->removeDirectory($directory);
61     }
62     mkdir($directory, 0777, true);
63   }
64
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');
70   }
71
72   /**
73    * Tests version specific files.
74    */
75   public function testFetchVersionSpecific() {
76     $fetcher = new FileFetcher(new RemoteFilesystem(new NullIO()), 'http://cgit.drupalcode.org/drupal/plain/{path}?h={version}', ['.eslintrc', '.eslintrc.json']);
77
78     $this->setExpectedException(TransportException::class);
79     $fetcher->fetch('8.2.x', $this->tmpDir);
80
81     $this->assertFileExists($this->tmpDir . '/.eslintrc');
82     $this->assertFileNotExists($this->tmpDir . '/.eslintrc.json');
83
84     // Remove downloaded files to retest with 8.3.x.
85     @unlink($this->tmpDir . '/.eslintrc');
86
87     $this->setExpectedException(TransportException::class);
88     $fetcher->fetch('8.3.x', $this->tmpDir);
89
90     $this->assertFileExists($this->tmpDir . '/.eslintrc.json');
91     $this->assertFileNotExists($this->tmpDir . '/.eslintrc');
92   }
93
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');
98   }
99 }