ConfigTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Controller\Adminhtml\System;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Magento\Framework\App\Request\Http as HttpRequest;
  9. /**
  10. * @magentoAppArea adminhtml
  11. */
  12. class ConfigTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  13. {
  14. /**
  15. * Test Configuration page existing.
  16. */
  17. public function testEditAction()
  18. {
  19. $this->dispatch('backend/admin/system_config/edit');
  20. $this->assertContains('<div id="system_config_tabs"', $this->getResponse()->getBody());
  21. }
  22. /**
  23. * Test redirect after changing base URL.
  24. *
  25. * @magentoAppIsolation enabled
  26. * @magentoDbIsolation enabled
  27. */
  28. public function testChangeBaseUrl()
  29. {
  30. $defaultHost = Bootstrap::getObjectManager()->create(\Magento\Framework\Url::class)->getBaseUrl();
  31. $newHost = 'm2test123.loc';
  32. $request = $this->getRequest();
  33. $request->setPostValue(
  34. [
  35. 'groups' =>
  36. ['unsecure' =>
  37. ['fields' =>
  38. ['base_url' =>
  39. ['value' => 'http://' . $newHost . '/']
  40. ]
  41. ]
  42. ],
  43. 'config_state' => ['web_unsecure' => 1]
  44. ]
  45. )->setParam(
  46. 'section',
  47. 'web'
  48. )->setMethod(
  49. HttpRequest::METHOD_POST
  50. );
  51. $this->dispatch('backend/admin/system_config/save');
  52. $this->assertTrue($this->getResponse()->isRedirect(), 'Redirect was expected, but none was performed.');
  53. /** @var array|bool $url */
  54. $url = parse_url($this->getResponse()->getHeader('Location')->getFieldValue());
  55. $this->assertArrayNotHasKey(
  56. 'query',
  57. $url,
  58. 'No GET params, including "SID", were expected, but somewhat exists'
  59. );
  60. $this->assertEquals($newHost, $url['host'], 'A new host in the url expected, but there is old one');
  61. $this->resetBaseUrl($defaultHost);
  62. }
  63. /**
  64. * Reset test framework default base url.
  65. *
  66. * @param string $defaultHost
  67. */
  68. protected function resetBaseUrl($defaultHost)
  69. {
  70. $baseUrlData = [
  71. 'section' => 'web',
  72. 'website' => null,
  73. 'store' => null,
  74. 'groups' => [
  75. 'unsecure' => [
  76. 'fields' => [
  77. 'base_url' => [
  78. 'value' => $defaultHost
  79. ]
  80. ]
  81. ]
  82. ]
  83. ];
  84. Bootstrap::getObjectManager()->create(\Magento\Config\Model\Config\Factory::class)
  85. ->create()
  86. ->addData($baseUrlData)
  87. ->save();
  88. }
  89. }