DistributionProfileTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\Serialization\Yaml;
  4. /**
  5. * Tests distribution profile support.
  6. *
  7. * @group Installer
  8. */
  9. class DistributionProfileTest extends InstallerTestBase {
  10. /**
  11. * The distribution profile info.
  12. *
  13. * @var array
  14. */
  15. protected $info;
  16. /**
  17. * {@inheritdoc}
  18. */
  19. protected $defaultTheme = 'stark';
  20. protected function prepareEnvironment() {
  21. parent::prepareEnvironment();
  22. $this->info = [
  23. 'type' => 'profile',
  24. 'core_version_requirement' => '*',
  25. 'name' => 'Distribution profile',
  26. 'distribution' => [
  27. 'name' => 'My Distribution',
  28. 'install' => [
  29. 'theme' => 'bartik',
  30. 'finish_url' => '/myrootuser',
  31. ],
  32. ],
  33. ];
  34. // File API functions are not available yet.
  35. $path = $this->siteDirectory . '/profiles/mydistro';
  36. mkdir($path, 0777, TRUE);
  37. file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
  38. file_put_contents("$path/mydistro.install", "<?php function mydistro_install() {\Drupal::entityTypeManager()->getStorage('path_alias')->create(['path' => '/user/1', 'alias' => '/myrootuser'])->save();}");
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function setUpLanguage() {
  44. // Verify that the distribution name appears.
  45. $this->assertRaw($this->info['distribution']['name']);
  46. // Verify that the distribution name is used in the site title.
  47. $this->assertTitle('Choose language | ' . $this->info['distribution']['name']);
  48. // Verify that the requested theme is used.
  49. $this->assertRaw($this->info['distribution']['install']['theme']);
  50. // Verify that the "Choose profile" step does not appear.
  51. $this->assertNoText('profile');
  52. parent::setUpLanguage();
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. protected function setUpProfile() {
  58. // This step is skipped, because there is a distribution profile.
  59. }
  60. /**
  61. * Confirms that the installation succeeded.
  62. */
  63. public function testInstalled() {
  64. $this->assertUrl('myrootuser');
  65. $this->assertSession()->statusCodeEquals(200);
  66. // Confirm that we are logged-in after installation.
  67. $this->assertText($this->rootUser->getAccountName());
  68. // Confirm that Drupal recognizes this distribution as the current profile.
  69. $this->assertEqual(\Drupal::installProfile(), 'mydistro');
  70. $this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.');
  71. }
  72. }