QuickStartTestBase.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Drupal\BuildTests\QuickStart;
  3. use Drupal\BuildTests\Framework\BuildTestBase;
  4. use Symfony\Component\Process\PhpExecutableFinder;
  5. /**
  6. * Helper methods for using the quickstart feature of Drupal.
  7. */
  8. abstract class QuickStartTestBase extends BuildTestBase {
  9. /**
  10. * User name of the admin account generated during install.
  11. *
  12. * @var string
  13. */
  14. protected $adminUsername;
  15. /**
  16. * Password of the admin account generated during install.
  17. *
  18. * @var string
  19. */
  20. protected $adminPassword;
  21. /**
  22. * Install a Drupal site using the quick start feature.
  23. *
  24. * @param string $profile
  25. * Drupal profile to install.
  26. * @param string $working_dir
  27. * (optional) A working directory relative to the workspace, within which to
  28. * execute the command. Defaults to the workspace directory.
  29. */
  30. public function installQuickStart($profile, $working_dir = NULL) {
  31. $php_finder = new PhpExecutableFinder();
  32. $install_process = $this->executeCommand($php_finder->find() . ' ./core/scripts/drupal install ' . $profile, $working_dir);
  33. $this->assertCommandOutputContains('Username:');
  34. preg_match('/Username: (.+)\vPassword: (.+)/', $install_process->getOutput(), $matches);
  35. $this->assertNotEmpty($this->adminUsername = $matches[1]);
  36. $this->assertNotEmpty($this->adminPassword = $matches[2]);
  37. }
  38. /**
  39. * Helper that uses Drupal's user/login form to log in.
  40. *
  41. * @param string $username
  42. * Username.
  43. * @param string $password
  44. * Password.
  45. * @param string $working_dir
  46. * (optional) A working directory within which to login. Defaults to the
  47. * workspace directory.
  48. */
  49. public function formLogin($username, $password, $working_dir = NULL) {
  50. $this->visit('/user/login', $working_dir);
  51. $assert = $this->getMink()->assertSession();
  52. $assert->statusCodeEquals(200);
  53. $assert->fieldExists('edit-name')->setValue($username);
  54. $assert->fieldExists('edit-pass')->setValue($password);
  55. $session = $this->getMink()->getSession();
  56. $session->getPage()->findButton('Log in')->submit();
  57. }
  58. }