create(Inline::class); $this->model = Bootstrap::getObjectManager()->create(Parser::class, ['translateInline' => $inline]); Bootstrap::getObjectManager()->get(MutableScopeConfigInterface::class) ->setValue(self::XML_PATH_TRANSLATE_INLINE_ACTIVE, true, ScopeInterface::SCOPE_STORE, self::STUB_STORE); } /** * Process ajax post test * * @dataProvider processAjaxPostDataProvider * * @param string $originalText * @param string $translatedText * @param string $area * @param bool|null $isPerStore * @return void */ public function testProcessAjaxPost( string $originalText, string $translatedText, string $area, ?bool $isPerStore = null ): void { Bootstrap::getObjectManager()->get(State::class) ->setAreaCode($area); $inputArray = [['original' => $originalText, 'custom' => $translatedText]]; if ($isPerStore !== null) { $inputArray[0]['perstore'] = $isPerStore; } $this->model->processAjaxPost($inputArray); $model = Bootstrap::getObjectManager()->create(StringUtils::class); $model->load($originalText); try { $this->assertEquals($translatedText, $model->getTranslate()); $model->delete(); } catch (\Exception $e) { $model->delete(); Bootstrap::getObjectManager()->get(LoggerInterface::class) ->critical($e); } } /** * Data provider for testProcessAjaxPost * * @return array */ public function processAjaxPostDataProvider(): array { return [ ['original text 1', 'translated text 1', Area::AREA_ADMINHTML], ['original text 1', 'translated text 1', Area::AREA_FRONTEND], ['original text 2', 'translated text 2', Area::AREA_ADMINHTML, true], ['original text 2', 'translated text 2', Area::AREA_FRONTEND, true], ]; } /** * Set get is json test * * @dataProvider allowedAreasDataProvider * * @param string $area * @return void */ public function testSetGetIsJson(string $area): void { Bootstrap::getObjectManager()->get(State::class) ->setAreaCode($area); $isJsonProperty = new \ReflectionProperty(get_class($this->model), '_isJson'); $isJsonProperty->setAccessible(true); $this->assertFalse($isJsonProperty->getValue($this->model)); $setIsJsonMethod = new \ReflectionMethod($this->model, 'setIsJson'); $setIsJsonMethod->setAccessible(true); $setIsJsonMethod->invoke($this->model, true); $this->assertTrue($isJsonProperty->getValue($this->model)); } /** * Data provider for testSetGetIsJson * * @return array */ public function allowedAreasDataProvider(): array { return [ [Area::AREA_ADMINHTML], [Area::AREA_FRONTEND] ]; } }