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