AjaxTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Translation\Controller;
  7. class AjaxTest extends \Magento\TestFramework\TestCase\AbstractController
  8. {
  9. protected function setUp()
  10. {
  11. /* Called getConfig as workaround for setConfig bug */
  12. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  13. \Magento\Store\Model\StoreManagerInterface::class
  14. )->getStore(
  15. 'default'
  16. )->getConfig(
  17. 'dev/translate_inline/active'
  18. );
  19. \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  20. \Magento\Framework\App\Config\MutableScopeConfigInterface::class
  21. )->setValue(
  22. 'dev/translate_inline/active',
  23. true,
  24. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  25. 'default'
  26. );
  27. parent::setUp();
  28. }
  29. /**
  30. * @dataProvider indexActionDataProvider
  31. */
  32. public function testIndexAction($postData, $expected)
  33. {
  34. $this->getRequest()->setPostValue('translate', $postData);
  35. $this->dispatch('translation/ajax/index');
  36. $this->assertEquals($expected, $this->getResponse()->getBody());
  37. }
  38. public function indexActionDataProvider()
  39. {
  40. return [
  41. [
  42. [
  43. [
  44. 'original' => 'phrase1',
  45. 'custom' => 'translation1'
  46. ]
  47. ],
  48. '{"phrase1":"translation1"}'
  49. ],
  50. [
  51. [
  52. [
  53. 'original' => 'phrase2',
  54. 'custom' => 'translation2'
  55. ]
  56. ],
  57. '{"phrase1":"translation1","phrase2":"translation2"}'
  58. ]
  59. ];
  60. }
  61. }