PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/app/code/Magento/Theme/Test/Unit/Block/Adminhtml/System/Design/Theme/Tab/CssTest.php

https://gitlab.com/crazybutterfly815/magento2
PHP | 148 lines | 100 code | 19 blank | 29 comment | 0 complexity | 186e187abe3c8be87c8a401118bdaa03 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. // @codingStandardsIgnoreFile
  7. namespace Magento\Theme\Test\Unit\Block\Adminhtml\System\Design\Theme\Tab;
  8. /**
  9. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  10. */
  11. class CssTest extends \PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @var \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css
  15. */
  16. protected $_model;
  17. /**
  18. * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $_objectManager;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $urlBuilder;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $urlCoder;
  29. protected function setUp()
  30. {
  31. $this->_objectManager = $this->getMock(\Magento\Framework\ObjectManagerInterface::class);
  32. $this->urlBuilder = $this->getMock(\Magento\Backend\Model\Url::class, [], [], '', false);
  33. $this->urlCoder = $this->getMock(\Magento\Framework\Encryption\UrlCoder::class, [], [], '', false);
  34. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  35. $constructArguments = $objectManagerHelper->getConstructArguments(
  36. \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css::class,
  37. [
  38. 'formFactory' => $this->getMock(\Magento\Framework\Data\FormFactory::class, [], [], '', false),
  39. 'objectManager' => $this->_objectManager,
  40. 'uploaderService' => $this->getMock(
  41. \Magento\Theme\Model\Uploader\Service::class,
  42. [],
  43. [],
  44. '',
  45. false
  46. ),
  47. 'urlBuilder' => $this->urlBuilder,
  48. 'urlCoder' => $this->urlCoder
  49. ]
  50. );
  51. $this->_model = $this->getMock(
  52. \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css::class,
  53. ['_getCurrentTheme'],
  54. $constructArguments,
  55. '',
  56. true
  57. );
  58. }
  59. public function testGetUploadCssFileNote()
  60. {
  61. $method = self::getMethod('_getUploadCssFileNote');
  62. /** @var $sizeModel \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\File\Size */
  63. $sizeModel = $this->getMock(\Magento\Framework\File\Size::class, [], [], '', false);
  64. $sizeModel->expects($this->any())->method('getMaxFileSizeInMb')->willReturn('2M');
  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. $result = $method->invokeArgs($this->_model, []);
  75. $expectedResult = 'Allowed file types *.css.<br />';
  76. $expectedResult .= 'This file will replace the current custom.css file and can\'t be more than 2 MB.<br />';
  77. $expectedResult .= sprintf('Max file size to upload %sM', $sizeModel->getMaxFileSizeInMb());
  78. $this->assertEquals($expectedResult, $result);
  79. }
  80. public function testGetAdditionalElementTypes()
  81. {
  82. $method = self::getMethod('_getAdditionalElementTypes');
  83. /** @var $configModel \Magento\Framework\App\Config\ScopeConfigInterface */
  84. $configModel = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  85. $this->_objectManager->expects(
  86. $this->any()
  87. )->method(
  88. 'get'
  89. )->with(
  90. \Magento\Framework\App\Config\ScopeConfigInterface::class
  91. )->will(
  92. $this->returnValue($configModel)
  93. );
  94. $result = $method->invokeArgs($this->_model, []);
  95. $expectedResult = [
  96. 'links' => \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\Links::class,
  97. 'css_file' => \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Form\Element\File::class,
  98. ];
  99. $this->assertEquals($expectedResult, $result);
  100. }
  101. public function testGetTabLabel()
  102. {
  103. $this->assertEquals('CSS Editor', $this->_model->getTabLabel());
  104. }
  105. /**
  106. * @param string $name
  107. * @return \ReflectionMethod
  108. */
  109. protected static function getMethod($name)
  110. {
  111. $class = new \ReflectionClass(\Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css::class);
  112. $method = $class->getMethod($name);
  113. $method->setAccessible(true);
  114. return $method;
  115. }
  116. /**
  117. * cover \Magento\Theme\Block\Adminhtml\System\Design\Theme\Edit\Tab\Css::getDownloadUrl
  118. */
  119. public function testGetterDownloadUrl()
  120. {
  121. $fileId = 1;
  122. $themeId = 1;
  123. $this->urlCoder->expects($this->atLeastOnce())->method('encode')->with($fileId)
  124. ->will($this->returnValue('encoded'));
  125. $this->urlBuilder->expects($this->atLeastOnce())->method('getUrl')
  126. ->with($this->anything(), ['theme_id' => $themeId, 'file' => 'encoded']);
  127. $this->_model->getDownloadUrl($fileId, $themeId);
  128. }
  129. }