DistributionProfileTest.php 2.38 KB
Newer Older
1 2
<?php

3
namespace Drupal\FunctionalTests\Installer;
4

5
use Drupal\Core\Serialization\Yaml;
6 7

/**
8 9 10
 * Tests distribution profile support.
 *
 * @group Installer
11 12 13 14 15 16 17 18 19 20
 */
class DistributionProfileTest extends InstallerTestBase {

  /**
   * The distribution profile info.
   *
   * @var array
   */
  protected $info;

21 22
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
23
    $this->info = [
24
      'type' => 'profile',
25
      'core_version_requirement' => '*',
26
      'name' => 'Distribution profile',
27
      'distribution' => [
28
        'name' => 'My Distribution',
29
        'install' => [
30
          'theme' => 'bartik',
31
          'finish_url' => '/myrootuser',
32 33 34
        ],
      ],
    ];
35 36 37
    // File API functions are not available yet.
    $path = $this->siteDirectory . '/profiles/mydistro';
    mkdir($path, 0777, TRUE);
38
    file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
39
    file_put_contents("$path/mydistro.install", "<?php function mydistro_install() {\Drupal::entityTypeManager()->getStorage('path_alias')->create(['path' => '/user/1', 'alias' => '/myrootuser'])->save();}");
40 41 42
  }

  /**
43
   * {@inheritdoc}
44 45 46 47
   */
  protected function setUpLanguage() {
    // Verify that the distribution name appears.
    $this->assertRaw($this->info['distribution']['name']);
48 49
    // Verify that the distribution name is used in the site title.
    $this->assertTitle('Choose language | ' . $this->info['distribution']['name']);
50 51 52 53 54 55 56 57 58
    // Verify that the requested theme is used.
    $this->assertRaw($this->info['distribution']['install']['theme']);
    // Verify that the "Choose profile" step does not appear.
    $this->assertNoText('profile');

    parent::setUpLanguage();
  }

  /**
59
   * {@inheritdoc}
60 61 62 63 64 65 66 67 68
   */
  protected function setUpProfile() {
    // This step is skipped, because there is a distribution profile.
  }

  /**
   * Confirms that the installation succeeded.
   */
  public function testInstalled() {
69
    $this->assertUrl('myrootuser');
70 71
    $this->assertResponse(200);
    // Confirm that we are logged-in after installation.
72
    $this->assertText($this->rootUser->getAccountName());
73 74 75 76

    // Confirm that Drupal recognizes this distribution as the current profile.
    $this->assertEqual(\Drupal::installProfile(), 'mydistro');
    $this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.');
77 78 79
  }

}