Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InlineParserTest.php
Go to the documentation of this file.
1 <?php
7 
8 class InlineParserTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_inlineParser;
14 
16  protected $_storeId = 'default';
17 
18  protected function setUp()
19  {
22  ->create(\Magento\Framework\Translate\Inline::class);
23  $this->_inlineParser = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
24  \Magento\Translation\Model\Inline\Parser::class,
25  ['translateInline' => $inline]
26  );
27  /* Called getConfig as workaround for setConfig bug */
29  \Magento\Store\Model\StoreManagerInterface::class
30  )->getStore(
31  $this->_storeId
32  )->getConfig(
33  'dev/translate_inline/active'
34  );
36  \Magento\Framework\App\Config\MutableScopeConfigInterface::class
37  )->setValue(
38  'dev/translate_inline/active',
39  true,
40  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
41  $this->_storeId
42  );
43  }
44 
48  public function testProcessAjaxPost($originalText, $translatedText, $isPerStore = null)
49  {
50  $inputArray = [['original' => $originalText, 'custom' => $translatedText]];
51  if ($isPerStore !== null) {
52  $inputArray[0]['perstore'] = $isPerStore;
53  }
54  $this->_inlineParser->processAjaxPost($inputArray);
55 
57  \Magento\Translation\Model\StringUtils::class
58  );
59  $model->load($originalText);
60  try {
61  $this->assertEquals($translatedText, $model->getTranslate());
62  $model->delete();
63  } catch (\Exception $e) {
64  $model->delete();
66  ->get(\Psr\Log\LoggerInterface::class)
67  ->critical($e);
68  }
69  }
70 
74  public function processAjaxPostDataProvider()
75  {
76  return [
77  ['original text 1', 'translated text 1'],
78  ['original text 2', 'translated text 2', true]
79  ];
80  }
81 
82  public function testSetGetIsJson()
83  {
84  $isJsonProperty = new \ReflectionProperty(get_class($this->_inlineParser), '_isJson');
85  $isJsonProperty->setAccessible(true);
86 
87  $this->assertFalse($isJsonProperty->getValue($this->_inlineParser));
88 
89  $setIsJsonMethod = new \ReflectionMethod($this->_inlineParser, 'setIsJson');
90  $setIsJsonMethod->setAccessible(true);
91  $setIsJsonMethod->invoke($this->_inlineParser, true);
92 
93  $this->assertTrue($isJsonProperty->getValue($this->_inlineParser));
94  }
95 }
testProcessAjaxPost($originalText, $translatedText, $isPerStore=null)