AbstractTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Framework\Image\Adapter\AbstractAdapter.
  8. */
  9. namespace Magento\Framework\Image\Test\Unit\Adapter;
  10. class AbstractTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Framework\Image\Adapter\AbstractAdapter
  14. */
  15. protected $_model;
  16. /**
  17. * @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Framework\Filesystem\Directory\Write
  18. */
  19. protected $directoryWriteMock;
  20. /**
  21. * @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Framework\Filesystem
  22. */
  23. protected $filesystemMock;
  24. /**
  25. * @var \PHPUnit_Framework_MockObject_MockObject |\Psr\Log\LoggerInterface
  26. */
  27. protected $loggerMock;
  28. protected function setUp()
  29. {
  30. $this->directoryWriteMock = $this->createMock(\Magento\Framework\Filesystem\Directory\Write::class);
  31. $this->filesystemMock =
  32. $this->createPartialMock(\Magento\Framework\Filesystem::class, ['getDirectoryWrite', 'createDirectory']);
  33. $this->filesystemMock->expects(
  34. $this->once()
  35. )->method(
  36. 'getDirectoryWrite'
  37. )->will(
  38. $this->returnValue($this->directoryWriteMock)
  39. );
  40. $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
  41. $this->_model = $this->getMockForAbstractClass(
  42. \Magento\Framework\Image\Adapter\AbstractAdapter::class,
  43. [$this->filesystemMock, $this->loggerMock]
  44. );
  45. }
  46. protected function tearDown()
  47. {
  48. $this->directoryWriteMock = null;
  49. $this->_model = null;
  50. $this->filesystemMock = null;
  51. $this->loggerMock = null;
  52. }
  53. /**
  54. * Test adaptResizeValues with null as a value one of parameters
  55. *
  56. * @dataProvider adaptResizeValuesDataProvider
  57. */
  58. public function testAdaptResizeValues($width, $height, $expectedResult)
  59. {
  60. $method = new \ReflectionMethod($this->_model, '_adaptResizeValues');
  61. $method->setAccessible(true);
  62. $result = $method->invoke($this->_model, $width, $height);
  63. $this->assertEquals($expectedResult, $result);
  64. }
  65. /**
  66. * @return array
  67. */
  68. public function adaptResizeValuesDataProvider()
  69. {
  70. $expected = [
  71. 'src' => ['x' => 0, 'y' => 0],
  72. 'dst' => ['x' => 0, 'y' => 0, 'width' => 135, 'height' => 135],
  73. 'frame' => ['width' => 135, 'height' => 135],
  74. ];
  75. return [[135, null, $expected], [null, 135, $expected]];
  76. }
  77. /**
  78. * @dataProvider prepareDestinationDataProvider
  79. */
  80. public function testPrepareDestination($destination, $newName, $expectedResult)
  81. {
  82. $property = new \ReflectionProperty(get_class($this->_model), '_fileSrcPath');
  83. $property->setAccessible(true);
  84. $property->setValue($this->_model, '_fileSrcPath');
  85. $property = new \ReflectionProperty(get_class($this->_model), '_fileSrcName');
  86. $property->setAccessible(true);
  87. $property->setValue($this->_model, '_fileSrcName');
  88. $method = new \ReflectionMethod($this->_model, '_prepareDestination');
  89. $method->setAccessible(true);
  90. $result = $method->invoke($this->_model, $destination, $newName);
  91. $this->assertEquals($expectedResult, $result);
  92. }
  93. /**
  94. * @return array
  95. */
  96. public function prepareDestinationDataProvider()
  97. {
  98. return [
  99. [__DIR__, 'name.txt', __DIR__ . '/name.txt'],
  100. [__DIR__ . '/name.txt', null, __DIR__ . '/name.txt'],
  101. [null, 'name.txt', '_fileSrcPath' . '/name.txt'],
  102. [null, null, '_fileSrcPath' . '/_fileSrcName']
  103. ];
  104. }
  105. }