MultipleDistributionsProfileTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Component\Serialization\Yaml;
  4. /**
  5. * Tests multiple distribution profile support.
  6. *
  7. * @group Installer
  8. */
  9. class MultipleDistributionsProfileTest 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. /**
  21. * {@inheritdoc}
  22. */
  23. protected function prepareEnvironment() {
  24. parent::prepareEnvironment();
  25. // Create two distributions.
  26. foreach (['distribution_one', 'distribution_two'] as $name) {
  27. $info = [
  28. 'type' => 'profile',
  29. 'core_version_requirement' => '*',
  30. 'name' => $name . ' profile',
  31. 'distribution' => [
  32. 'name' => $name,
  33. 'install' => [
  34. 'theme' => 'bartik',
  35. ],
  36. ],
  37. ];
  38. // File API functions are not available yet.
  39. $path = $this->root . DIRECTORY_SEPARATOR . $this->siteDirectory . '/profiles/' . $name;
  40. mkdir($path, 0777, TRUE);
  41. file_put_contents("$path/$name.info.yml", Yaml::encode($info));
  42. }
  43. // Install the first distribution.
  44. $this->profile = 'distribution_one';
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. protected function setUpLanguage() {
  50. // Verify that the distribution name appears.
  51. $this->assertRaw('distribution_one');
  52. // Verify that the requested theme is used.
  53. $this->assertRaw('bartik');
  54. // Verify that the "Choose profile" step does not appear.
  55. $this->assertNoText('profile');
  56. parent::setUpLanguage();
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. protected function setUpProfile() {
  62. // This step is skipped, because there is a distribution profile.
  63. }
  64. /**
  65. * Confirms that the installation succeeded.
  66. */
  67. public function testInstalled() {
  68. $this->assertUrl('user/1');
  69. $this->assertSession()->statusCodeEquals(200);
  70. // Confirm that we are logged-in after installation.
  71. $this->assertText($this->rootUser->getAccountName());
  72. // Confirm that Drupal recognizes this distribution as the current profile.
  73. $this->assertEqual(\Drupal::installProfile(), 'distribution_one');
  74. $this->assertEqual($this->config('core.extension')->get('profile'), 'distribution_one', 'The install profile has been written to core.extension configuration.');
  75. $this->rebuildContainer();
  76. $this->assertEqual(\Drupal::installProfile(), 'distribution_one');
  77. }
  78. }