InlineTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Translate;
  7. class InlineTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\Translate\Inline
  11. */
  12. protected $_model;
  13. /**
  14. * @var string
  15. */
  16. protected $_storeId = 'default';
  17. /**
  18. * @var \Magento\Framework\Translate\Inline\StateInterface
  19. */
  20. protected $state;
  21. public static function setUpBeforeClass()
  22. {
  23. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
  24. ->setAreaCode('frontend');
  25. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  26. \Magento\Framework\View\DesignInterface::class
  27. )->setDesignTheme(
  28. 'Magento/blank'
  29. );
  30. }
  31. protected function setUp()
  32. {
  33. $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  34. \Magento\Framework\Translate\Inline::class
  35. );
  36. $this->state = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  37. \Magento\Framework\Translate\Inline\StateInterface::class
  38. );
  39. /* Called getConfig as workaround for setConfig bug */
  40. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  41. \Magento\Store\Model\StoreManagerInterface::class
  42. )->getStore(
  43. $this->_storeId
  44. )->getConfig(
  45. 'dev/translate_inline/active'
  46. );
  47. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  48. \Magento\Framework\App\Config\MutableScopeConfigInterface::class
  49. )->setValue(
  50. 'dev/translate_inline/active',
  51. true,
  52. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  53. $this->_storeId
  54. );
  55. }
  56. public function testIsAllowed()
  57. {
  58. $this->assertTrue($this->_model->isAllowed());
  59. $this->assertTrue($this->_model->isAllowed($this->_storeId));
  60. $this->assertTrue(
  61. $this->_model->isAllowed(
  62. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  63. \Magento\Store\Model\StoreManagerInterface::class
  64. )->getStore(
  65. $this->_storeId
  66. )
  67. )
  68. );
  69. $this->state->suspend();
  70. $this->assertFalse($this->_model->isAllowed());
  71. $this->assertFalse($this->_model->isAllowed($this->_storeId));
  72. $this->assertFalse(
  73. $this->_model->isAllowed(
  74. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  75. \Magento\Store\Model\StoreManagerInterface::class
  76. )->getStore(
  77. $this->_storeId
  78. )
  79. )
  80. );
  81. }
  82. /**
  83. * @param string $originalText
  84. * @param string $expectedText
  85. * @dataProvider processResponseBodyDataProvider
  86. */
  87. public function testProcessResponseBody($originalText, $expectedText)
  88. {
  89. $actualText = $originalText;
  90. $this->_model->processResponseBody($actualText, false);
  91. $this->markTestIncomplete('Bug MAGE-2494');
  92. $expected = new \DOMDocument();
  93. $expected->preserveWhiteSpace = false;
  94. $expected->loadHTML($expectedText);
  95. $actual = new \DOMDocument();
  96. $actual->preserveWhiteSpace = false;
  97. $actual->loadHTML($actualText);
  98. $this->assertEquals($expected, $actual);
  99. }
  100. /**
  101. * @return array
  102. */
  103. public function processResponseBodyDataProvider()
  104. {
  105. $originalText = file_get_contents(__DIR__ . '/_files/_inline_page_original.html');
  106. $expectedText = file_get_contents(__DIR__ . '/_files/_inline_page_expected.html');
  107. $package = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  108. \Magento\Framework\View\DesignInterface::class
  109. )->getDesignTheme()->getPackageCode();
  110. $expectedText = str_replace('{{design_package}}', $package, $expectedText);
  111. return [
  112. 'plain text' => ['text with no translations and tags', 'text with no translations and tags'],
  113. 'html string' => [$originalText, $expectedText],
  114. 'html array' => [[$originalText], [$expectedText]]
  115. ];
  116. }
  117. }