PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/update/dev/tests/integration/testsuite/Magento/Update/StatusCheckTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 108 lines | 65 code | 12 blank | 31 comment | 1 complexity | 1c674e38b2a2164572ce6af52fe35e7a MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Update;
  7. class StatusCheckTest extends \PHPUnit_Framework_TestCase
  8. {
  9. const REQUEST_TYPE_AJAX = 'ajax';
  10. /**
  11. * @var string
  12. */
  13. protected $indexScript;
  14. /**
  15. * @var \Magento\Update\Status
  16. */
  17. protected $status;
  18. /**
  19. * @var string
  20. */
  21. protected $uniqueMessage;
  22. protected function setUp()
  23. {
  24. $this->indexScript = UPDATER_BP . '/index.php';
  25. $this->status = new \Magento\Update\Status();
  26. $this->status->clear();
  27. $this->uniqueMessage = 'Test Message' . uniqid();
  28. }
  29. protected function tearDown()
  30. {
  31. $this->status->clear();
  32. unset($this->uniqueMessage);
  33. }
  34. /**
  35. * @param bool $isInProgress
  36. * @param string $statusMessage
  37. * @dataProvider progressStatusDataProvider
  38. */
  39. public function testStatusCheck($isInProgress, $statusMessage)
  40. {
  41. $this->status->add($this->uniqueMessage);
  42. $this->status->setUpdateInProgress($isInProgress);
  43. $actualResponse = $this->getResponse();
  44. $this->assertContains($this->uniqueMessage, $actualResponse);
  45. $this->assertContains($statusMessage, $actualResponse);
  46. }
  47. /**
  48. * @param bool $isInProgress
  49. * @dataProvider progressStatusDataProvider
  50. */
  51. public function testStatusCheckAjax($isInProgress)
  52. {
  53. $this->status->add($this->uniqueMessage);
  54. $this->status->setUpdateInProgress($isInProgress);
  55. $actualResponse = json_decode($this->getResponse(self::REQUEST_TYPE_AJAX), true);
  56. $this->assertInternalType('array', $actualResponse);
  57. $this->assertArrayHasKey('statusMessage', $actualResponse);
  58. $this->assertArrayHasKey('isUpdateInProgress', $actualResponse);
  59. $this->assertContains($this->uniqueMessage, $actualResponse['statusMessage']);
  60. $this->assertEquals($isInProgress, $actualResponse['isUpdateInProgress']);
  61. }
  62. /**
  63. * @return array
  64. */
  65. public function progressStatusDataProvider()
  66. {
  67. return [
  68. 'isRunning' => [
  69. 'isInProgress' => true,
  70. 'statusMessage' => 'Update application is running'
  71. ],
  72. 'isNotRunning' => [
  73. 'isInProgress' => false,
  74. 'statusMessage' => 'Update application is not running'
  75. ],
  76. ];
  77. }
  78. /**
  79. * Return response of index.php, according to the request type
  80. *
  81. * @param string|null $requestType
  82. * @return string
  83. */
  84. protected function getResponse($requestType = null)
  85. {
  86. if ($requestType === self::REQUEST_TYPE_AJAX) {
  87. $_SERVER['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest';
  88. }
  89. ob_start();
  90. include $this->indexScript;
  91. $response = ob_get_contents();
  92. ob_end_clean();
  93. unset($_SERVER['HTTP_X_REQUESTED_WITH']);
  94. return $response;
  95. }
  96. }