|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Translation\Test\Unit\Model\Inline; |
| 7 | + |
| 8 | +/** |
| 9 | + * Class ParserTest to test \Magento\Translation\Model\Inline\Parser |
| 10 | + */ |
| 11 | +class ParserTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var \Magento\Translation\Model\Inline\Parser|\PHPUnit_Framework_MockObject_MockObject |
| 15 | + */ |
| 16 | + private $model; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \Magento\Translation\Model\ResourceModel\StringUtilsFactory|\PHPUnit_Framework_MockObject_MockObject |
| 20 | + */ |
| 21 | + private $resourceMock; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 25 | + */ |
| 26 | + private $storeManagerMock; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var \Zend_Filter_Interface|\PHPUnit_Framework_MockObject_MockObject |
| 30 | + */ |
| 31 | + private $inputFilterMock; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject |
| 35 | + */ |
| 36 | + private $appStateMock; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var \Magento\Framework\App\Cache\TypeListInterface|\PHPUnit_Framework_MockObject_MockObject |
| 40 | + */ |
| 41 | + private $appCacheMock; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var \Magento\Framework\Translate\InlineInterface|\PHPUnit_Framework_MockObject_MockObject |
| 45 | + */ |
| 46 | + private $translateInlineMock; |
| 47 | + |
| 48 | + protected function setUp() |
| 49 | + { |
| 50 | + $this->resourceMock = $this->getMockBuilder('Magento\Translation\Model\ResourceModel\StringUtilsFactory') |
| 51 | + ->disableOriginalConstructor() |
| 52 | + ->setMethods([]) |
| 53 | + ->getMock(); |
| 54 | + |
| 55 | + $this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface') |
| 56 | + ->disableOriginalConstructor() |
| 57 | + ->setMethods([]) |
| 58 | + ->getMock(); |
| 59 | + |
| 60 | + $this->inputFilterMock = $this->getMockBuilder('Zend_Filter_Interface') |
| 61 | + ->disableOriginalConstructor() |
| 62 | + ->setMethods([]) |
| 63 | + ->getMock(); |
| 64 | + |
| 65 | + $this->appStateMock = $this->getMockBuilder('Magento\Framework\App\State') |
| 66 | + ->disableOriginalConstructor() |
| 67 | + ->setMethods([]) |
| 68 | + ->getMock(); |
| 69 | + |
| 70 | + $this->appCacheMock = $this->getMockBuilder('Magento\Framework\App\Cache\TypeListInterface') |
| 71 | + ->disableOriginalConstructor() |
| 72 | + ->setMethods([]) |
| 73 | + ->getMock(); |
| 74 | + |
| 75 | + $this->translateInlineMock= $this->getMockBuilder('Magento\Framework\Translate\InlineInterface') |
| 76 | + ->disableOriginalConstructor() |
| 77 | + ->setMethods([]) |
| 78 | + ->getMock(); |
| 79 | + |
| 80 | + $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 81 | + $this->model = $objectManagerHelper->getObject( |
| 82 | + 'Magento\Translation\Model\Inline\Parser', |
| 83 | + [ |
| 84 | + "_resourceFactory" => $this->resourceMock, |
| 85 | + "_storeManager" => $this->storeManagerMock, |
| 86 | + "_inputFilter" => $this->inputFilterMock, |
| 87 | + "_appState" => $this->appStateMock, |
| 88 | + "_appCache" => $this->appCacheMock, |
| 89 | + "_translateInline" => $this->translateInlineMock |
| 90 | + ] |
| 91 | + ); |
| 92 | + } |
| 93 | + |
| 94 | + public function testProcessResponseBodyStringProcessingAttributesCorrectly() |
| 95 | + { |
| 96 | + $testContent = file_get_contents(__DIR__ . '/_files/datatranslate_fixture.html'); |
| 97 | + $processedAttributes = [ |
| 98 | + "data-translate=\"[{'shown':'* Required Fields','translated':'* Required Fields'," |
| 99 | + . "'original':'* Required Fields','location':'Tag attribute (ALT, TITLE, etc.)'}]\"", |
| 100 | + "data-translate=\"[{'shown':'Email','translated':'Email','original':'Email'," |
| 101 | + . "'location':'Tag attribute (ALT, TITLE, etc.)'}]\"", |
| 102 | + "data-translate=\"[{'shown':'Password','translated':'Password','original':'Password'," |
| 103 | + . "'location':'Tag attribute (ALT, TITLE, etc.)'}]\"" |
| 104 | + ]; |
| 105 | + $this->translateInlineMock->expects($this->any())->method('getAdditionalHtmlAttribute')->willReturn(null); |
| 106 | + |
| 107 | + $processedContent = $this->model->processResponseBodyString($testContent); |
| 108 | + foreach ($processedAttributes as $attribute) { |
| 109 | + $this->assertContains($attribute, $processedContent, "data-translate attribute not processed correctly"); |
| 110 | + } |
| 111 | + } |
| 112 | +} |
0 commit comments