/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
dev/tests/integration/testsuite/Magento/Framework/TranslateTest.php
148 строк
6 KB
Raj Mohan R
AC-16236::Upgrade Core Test Framework to PHPUnit 12 and Migrate from PHPUnit 10
11 фев 2026, 13:51
11 фев 2026, 13:51
152ed41
Код
Авторство
О чём код?
<?php /** * Copyright 2014 Adobe * All Rights Reserved. */ namespace Magento\Framework; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\Helper\CacheCleaner; use PHPUnit\Framework\MockObject\MockObject as MockObject; use PHPUnit\Framework\Attributes\DataProvider; /** * @magentoAppIsolation enabled * @magentoCache all disabled * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class TranslateTest extends \PHPUnit\Framework\TestCase { /** * @var \Magento\Framework\Translate */ private $translate; /** * @inheritdoc */ protected function setUp(): void { /** @var \Magento\Framework\View\FileSystem|MockObject $viewFileSystem */ $viewFileSystem = $this->createPartialMock( \Magento\Framework\View\FileSystem::class, ['getLocaleFileName'] ); $viewFileSystem->expects($this->any()) ->method('getLocaleFileName') ->willReturn( dirname(__DIR__) . '/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv' ); /** @var \Magento\Framework\View\Design\ThemeInterface|MockObject $theme */ $theme = $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class); $theme->expects($this->any())->method('getThemePath')->willReturn('Magento/luma'); /** @var \Magento\TestFramework\ObjectManager $objectManager */ $objectManager = Bootstrap::getObjectManager(); $objectManager->addSharedInstance($viewFileSystem, \Magento\Framework\View\FileSystem::class); /** @var $moduleReader \Magento\Framework\Module\Dir\Reader */ $moduleReader = $objectManager->get(\Magento\Framework\Module\Dir\Reader::class); $moduleReader->setModuleDir( 'Magento_Store', 'i18n', dirname(__DIR__) . '/Translation/Model/_files/Magento/Store/i18n' ); $moduleReader->setModuleDir( 'Magento_Catalog', 'i18n', dirname(__DIR__) . '/Translation/Model/_files/Magento/Catalog/i18n' ); /** @var \Magento\Theme\Model\View\Design|MockObject $designModel */ $designModel = $this->getMockBuilder(\Magento\Theme\Model\View\Design::class) ->onlyMethods(['getDesignTheme']) ->setConstructorArgs( [ $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class), $objectManager->get(\Magento\Framework\View\Design\Theme\FlyweightFactory::class), $objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class), $objectManager->get(\Magento\Theme\Model\ThemeFactory::class), $objectManager->get(\Magento\Framework\ObjectManagerInterface::class), $objectManager->get(\Magento\Framework\App\State::class), ['frontend' => 'Test/default'] ] ) ->getMock(); $designModel->expects($this->any())->method('getDesignTheme')->willReturn($theme); $objectManager->addSharedInstance($designModel, \Magento\Theme\Model\View\Design\Proxy::class); $this->translate = $objectManager->create(\Magento\Framework\Translate::class); $objectManager->addSharedInstance($this->translate, \Magento\Framework\Translate::class); $objectManager->removeSharedInstance(\Magento\Framework\Phrase\Renderer\Composite::class); $objectManager->removeSharedInstance(\Magento\Framework\Phrase\Renderer\Translate::class); \Magento\Framework\Phrase::setRenderer( $objectManager->get(\Magento\Framework\Phrase\RendererInterface::class) ); } public function testLoadData() { $data = $this->translate->loadData(null, true)->getData(); $this->translate->loadData()->getData(); $dataCached = $this->translate->loadData()->getData(); $this->assertEquals($data, $dataCached); } /** * @magentoCache all disabled * * @param string $inputText * @param string $expectedTranslation * @return void * @throws Exception\LocalizedException */ #[DataProvider('translateDataProvider')] public function testTranslate($inputText, $expectedTranslation) { $this->translate->loadData(\Magento\Framework\App\Area::AREA_FRONTEND); $actualTranslation = new \Magento\Framework\Phrase($inputText); $this->assertEquals($expectedTranslation, $actualTranslation); } /** * @return array */ public static function translateDataProvider() { return [ ['', ''], [ 'Theme phrase will be translated', 'Theme phrase is translated', ], [ 'Phrase in Magento_Store module that doesn\'t need translation', 'Phrase in Magento_Store module that doesn\'t need translation', ], [ 'Phrase in Magento_Catalog module that doesn\'t need translation', 'Phrase in Magento_Catalog module that doesn\'t need translation', ], [ 'Magento_Store module phrase will be overridden by theme translation', 'Magento_Store module phrase is overridden by theme translation', ], [ 'Magento_Catalog module phrase will be overridden by theme translation', 'Magento_Catalog module phrase is overridden by theme translation', ], ]; } }