Skip to content

Commit e0783cf

Browse files
author
Hayder Sharhan
committed
MAGETWO-49097: Staging. Shopping Cart Price Rules. Builds stabilization
- Updated integration tests for inline parser. - Removed setter for object inserted into parser. Reflect the class if need unit test.
1 parent 69c8226 commit e0783cf

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed

app/code/Magento/Translation/Model/FileManager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ public function getTranslationFilePath()
9696
*/
9797
public function updateTranslationFileContent($content)
9898
{
99+
$translationDir = $this->directoryList->getPath(DirectoryList::STATIC_VIEW) .
100+
\DIRECTORY_SEPARATOR .
101+
$this->assetRepo->getStaticViewFileContext()->getPath();
102+
if (!$this->driverFile->isExists($this->getTranslationFileFullPath())) {
103+
$this->driverFile->createDirectory(
104+
$translationDir,
105+
\Magento\Framework\Filesystem\Driver\File::WRITEABLE_DIRECTORY_MODE
106+
);
107+
}
99108
$this->driverFile->filePutContents($this->getTranslationFileFullPath(), $content);
100109
}
101110
}

app/code/Magento/Translation/Model/Inline/Parser.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,6 @@ private function getCacheManger()
141141
return $this->cacheManager;
142142
}
143143

144-
/**
145-
* For unit testing purpose only
146-
*
147-
* @param \Magento\Translation\Model\Inline\CacheManager $cacheManager
148-
* @return void
149-
* @deprecated
150-
*/
151-
public function setCacheManager(\Magento\Translation\Model\Inline\CacheManager $cacheManager)
152-
{
153-
if ($this->cacheManager != null) {
154-
throw new \LogicException(__('cacheManager is already set'));
155-
}
156-
$this->cacheManager = $cacheManager;
157-
}
158-
159144
/**
160145
* Initialize base inline translation model
161146
*
@@ -186,12 +171,12 @@ public function __construct(
186171
* Parse and save edited translation
187172
*
188173
* @param array $translateParams
189-
* @return $this
174+
* @return array
190175
*/
191176
public function processAjaxPost(array $translateParams)
192177
{
193178
if (!$this->_translateInline->isAllowed()) {
194-
return $this;
179+
return ['inline' => 'not allowed'];
195180
}
196181
$this->_appCache->invalidate(\Magento\Framework\App\Cache\Type\Translate::TYPE_IDENTIFIER);
197182

dev/tests/integration/testsuite/Magento/Translation/Controller/AjaxTest.php

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,63 @@
66

77
namespace Magento\Translation\Controller;
88

9+
use Magento\Rma\Block\Adminhtml\Rma\Item\Attribute\Edit\Js;
10+
911
class AjaxTest extends \Magento\TestFramework\TestCase\AbstractController
1012
{
13+
protected function setUp()
14+
{
15+
/* Called getConfig as workaround for setConfig bug */
16+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
17+
'Magento\Store\Model\StoreManagerInterface'
18+
)->getStore(
19+
'default'
20+
)->getConfig(
21+
'dev/translate_inline/active'
22+
);
23+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
24+
'Magento\Framework\App\Config\MutableScopeConfigInterface'
25+
)->setValue(
26+
'dev/translate_inline/active',
27+
true,
28+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
29+
'default'
30+
);
31+
parent::setUp();
32+
}
33+
34+
1135
/**
1236
* @dataProvider indexActionDataProvider
1337
*/
14-
public function testIndexAction($postData)
38+
public function testIndexAction($postData, $expected)
1539
{
1640
$this->getRequest()->setPostValue('translate', $postData);
1741
$this->dispatch('translation/ajax/index');
18-
$this->assertEquals('{success:true}', $this->getResponse()->getBody());
42+
$this->assertEquals($expected, $this->getResponse()->getBody());
1943
}
2044

2145
public function indexActionDataProvider()
2246
{
23-
return [['test'], [['test']]];
47+
return [
48+
[
49+
[
50+
[
51+
'original' => 'phrase1',
52+
'custom' => 'translation1'
53+
]
54+
],
55+
'{"phrase1":"translation1"}'
56+
],
57+
[
58+
[
59+
[
60+
'original' => 'phrase2',
61+
'custom' => 'translation2'
62+
]
63+
],
64+
'{"phrase1":"translation1","phrase2":"translation2"}'
65+
]
66+
];
2467
}
2568
}

0 commit comments

Comments
 (0)