Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CssTest.php
Go to the documentation of this file.
1 <?php
8 
12 class CssTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $_model;
18 
22  protected $_objectManager;
23 
27  protected $urlBuilder;
28 
32  protected $urlCoder;
33 
34  protected function setUp()
35  {
36  $this->_objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
37  $this->urlBuilder = $this->createMock(\Magento\Backend\Model\Url::class);
38  $this->urlCoder = $this->createMock(\Magento\Framework\Encryption\UrlCoder::class);
39 
40  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
41  $constructArguments = $objectManagerHelper->getConstructArguments(
42  \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css::class,
43  [
44  'formFactory' => $this->createMock(\Magento\Framework\Data\FormFactory::class),
45  'objectManager' => $this->_objectManager,
46  'uploaderService' => $this->createMock(\Magento\Theme\Model\Uploader\Service::class),
47  'urlBuilder' => $this->urlBuilder,
48  'urlCoder' => $this->urlCoder
49  ]
50  );
51 
52  $this->_model = $this->getMockBuilder(\Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css::class)
53  ->setMethods(['_getCurrentTheme'])
54  ->setConstructorArgs($constructArguments)
55  ->getMock();
56  }
57 
58  public function testGetUploadCssFileNote()
59  {
60  $method = self::getMethod('_getUploadCssFileNote');
62  $sizeModel = $this->createMock(\Magento\Framework\File\Size::class);
63  $sizeModel->expects($this->any())->method('getMaxFileSizeInMb')->willReturn('2M');
64 
65  $this->_objectManager->expects(
66  $this->any()
67  )->method(
68  'get'
69  )->with(
70  \Magento\Framework\File\Size::class
71  )->will(
72  $this->returnValue($sizeModel)
73  );
74 
75  $result = $method->invokeArgs($this->_model, []);
76  $expectedResult = 'Allowed file types *.css.<br />';
77  $expectedResult .= 'This file will replace the current custom.css file and can\'t be more than 2 MB.<br />';
78  $expectedResult .= sprintf('Max file size to upload %sM', $sizeModel->getMaxFileSizeInMb());
79  $this->assertEquals($expectedResult, $result);
80  }
81 
82  public function testGetAdditionalElementTypes()
83  {
84  $method = self::getMethod('_getAdditionalElementTypes');
85 
87  $configModel = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
88 
89  $this->_objectManager->expects(
90  $this->any()
91  )->method(
92  'get'
93  )->with(
94  \Magento\Framework\App\Config\ScopeConfigInterface::class
95  )->will(
96  $this->returnValue($configModel)
97  );
98 
99  $result = $method->invokeArgs($this->_model, []);
100  $expectedResult = [
101  'links' => \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\Links::class,
102  'css_file' => \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\File::class,
103  ];
104  $this->assertEquals($expectedResult, $result);
105  }
106 
107  public function testGetTabLabel()
108  {
109  $this->assertEquals('CSS Editor', $this->_model->getTabLabel());
110  }
111 
116  protected static function getMethod($name)
117  {
118  $class = new \ReflectionClass(\Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css::class);
119  $method = $class->getMethod($name);
120  $method->setAccessible(true);
121  return $method;
122  }
123 
127  public function testGetterDownloadUrl()
128  {
129  $fileId = 1;
130  $themeId = 1;
131  $this->urlCoder->expects($this->atLeastOnce())->method('encode')->with($fileId)
132  ->will($this->returnValue('encoded'));
133  $this->urlBuilder->expects($this->atLeastOnce())->method('getUrl')
134  ->with($this->anything(), ['theme_id' => $themeId, 'file' => 'encoded']);
135  $this->_model->getDownloadUrl($fileId, $themeId);
136  }
137 }
$_option $_optionId $class
Definition: date.phtml:13
$method
Definition: info.phtml:13
if(!isset($_GET['name'])) $name
Definition: log.php:14