DistributionProfileTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. protected function prepareEnvironment() {
  17. parent::prepareEnvironment();
  18. $this->info = [
  19. 'type' => 'profile',
  20. 'core' => \Drupal::CORE_COMPATIBILITY,
  21. 'name' => 'Distribution profile',
  22. 'distribution' => [
  23. 'name' => 'My Distribution',
  24. 'install' => [
  25. 'theme' => 'bartik',
  26. 'finish_url' => '/myrootuser',
  27. ],
  28. ],
  29. ];
  30. // File API functions are not available yet.
  31. $path = $this->siteDirectory . '/profiles/mydistro';
  32. mkdir($path, 0777, TRUE);
  33. file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
  34. file_put_contents("$path/mydistro.install", "<?php function mydistro_install() {\Drupal::service('path.alias_storage')->save('/user/1', '/myrootuser');}");
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. protected function setUpLanguage() {
  40. // Verify that the distribution name appears.
  41. $this->assertRaw($this->info['distribution']['name']);
  42. // Verify that the distribution name is used in the site title.
  43. $this->assertTitle('Choose language | ' . $this->info['distribution']['name']);
  44. // Verify that the requested theme is used.
  45. $this->assertRaw($this->info['distribution']['install']['theme']);
  46. // Verify that the "Choose profile" step does not appear.
  47. $this->assertNoText('profile');
  48. parent::setUpLanguage();
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. protected function setUpProfile() {
  54. // This step is skipped, because there is a distribution profile.
  55. }
  56. /**
  57. * Confirms that the installation succeeded.
  58. */
  59. public function testInstalled() {
  60. $this->assertUrl('myrootuser');
  61. $this->assertResponse(200);
  62. // Confirm that we are logged-in after installation.
  63. $this->assertText($this->rootUser->getUsername());
  64. // Confirm that Drupal recognizes this distribution as the current profile.
  65. $this->assertEqual(\Drupal::installProfile(), 'mydistro');
  66. $this->assertEqual($this->config('core.extension')->get('profile'), 'mydistro', 'The install profile has been written to core.extension configuration.');
  67. }
  68. }