20 private $objectManager;
25 private $imageUploader;
42 $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
44 $this->attribute = $this->getMockForAbstractClass(
54 $this->attribute->expects($this->once())
56 ->will($this->returnValue(
'test_attribute'));
58 $this->logger = $this->getMockForAbstractClass(
59 \Psr\Log\LoggerInterface::class,
68 $this->imageUploader = $this->createPartialMock(
69 \
Magento\Catalog\Model\ImageUploader::class,
73 $this->filesystem = $this->getMockBuilder(\
Magento\Framework\Filesystem::class)->disableOriginalConstructor()
96 $model->setAttribute($this->attribute);
98 $object = new \Magento\Framework\DataObject([
102 $model->beforeSave($object);
104 $this->assertEquals(
null, $object->getTestAttribute());
112 $closure =
function () {
121 [[
'a' => 1,
'b' => 2]]
133 $model->setAttribute($this->attribute);
135 $object = new \Magento\Framework\DataObject([
136 'test_attribute' =>
$value 139 $model->beforeSave($object);
141 $this->assertEquals(
'', $object->getTestAttribute());
150 $model->setAttribute($this->attribute);
152 $object = new \Magento\Framework\DataObject([
153 'test_attribute' => [
154 [
'name' =>
'test123.jpg']
158 $model->beforeSave($object);
160 $this->assertEquals(
'test123.jpg', $object->getTestAttribute());
169 'filesystem' => $this->filesystem
172 $model->setAttribute($this->attribute);
175 ->expects($this->once())
178 ->willReturn(
'pub/media');
180 $object = new \Magento\Framework\DataObject([
181 'test_attribute' => [
183 'name' =>
'/test123.jpg',
184 'url' =>
'/pub/media/wysiwyg/test123.jpg',
189 $model->beforeSave($object);
191 $this->assertEquals(
'/pub/media/wysiwyg/test123.jpg', $object->getTestAttribute());
193 [[
'name' =>
'/pub/media/wysiwyg/test123.jpg',
'url' =>
'/pub/media/wysiwyg/test123.jpg']],
194 $object->getData(
'_additional_data_test_attribute')
204 $model->setAttribute($this->attribute);
206 $object = new \Magento\Framework\DataObject([
207 'test_attribute' => [
208 [
'name' =>
'test123.jpg',
'tmp_name' =>
'abc123',
'url' =>
'http://www.example.com/test123.jpg']
212 $model->beforeSave($object);
214 $this->assertEquals([
215 [
'name' =>
'test123.jpg',
'tmp_name' =>
'abc123',
'url' =>
'http://www.example.com/test123.jpg']
216 ], $object->getData(
'_additional_data_test_attribute'));
225 $model->setAttribute($this->attribute);
227 $object = new \Magento\Framework\DataObject([
228 'test_attribute' =>
'test123.jpg' 231 $model->beforeSave($object);
233 $this->assertEquals(
'test123.jpg', $object->getTestAttribute());
234 $this->assertNull($object->getData(
'_additional_data_test_attribute'));
240 private function setUpModelForAfterSave()
242 $objectManagerMock = $this->createPartialMock(\
Magento\Framework\
App\ObjectManager::class, [
'get']);
244 $imageUploaderMock = $this->imageUploader;
246 $objectManagerMock->expects($this->any())
248 ->will($this->returnCallback(
function (
$class,
$params = []) use ($imageUploaderMock) {
250 return $imageUploaderMock;
257 'objectManager' => $objectManagerMock,
258 'logger' => $this->logger
260 $this->objectManager->setBackwardCompatibleProperty(
$model,
'imageUploader', $this->imageUploader);
262 return $model->setAttribute($this->attribute);
271 [[[
'name' =>
'test1234.jpg']]],
285 $model = $this->setUpModelForAfterSave();
287 $this->imageUploader->expects($this->once())
288 ->method(
'moveFileFromTmp')
289 ->with($this->equalTo(
'test1234.jpg'));
291 $object = new \Magento\Framework\DataObject(
293 'test_attribute' =>
$value,
294 '_additional_data_test_attribute' => [[
'name' =>
'test1234.jpg',
'tmp_name' =>
'test-test-1234']]
298 $model->afterSave($object);
308 $model = $this->setUpModelForAfterSave();
310 $this->imageUploader->expects($this->never())
311 ->method(
'moveFileFromTmp');
313 $object = new \Magento\Framework\DataObject(
315 'test_attribute' =>
$value 319 $model->afterSave($object);
327 $model = $this->setUpModelForAfterSave();
329 $exception = new \Exception();
331 $this->imageUploader->expects($this->any())
332 ->method(
'moveFileFromTmp')
333 ->will($this->throwException($exception));
335 $this->logger->expects($this->once())
337 ->with($this->equalTo($exception));
339 $object = new \Magento\Framework\DataObject(
341 '_additional_data_test_attribute' => [[
'name' =>
'test1234.jpg',
'tmp_name' =>
'test-test-1234']]
345 $model->afterSave($object);
testBeforeSaveTemporaryAttribute()
testBeforeSaveAttributeFileNameOutsideOfCategoryDir()
invalidValueDataProvider()
testAfterSaveWithoutAdditionalData($value)
testBeforeSaveValueInvalid($value)
testBeforeSaveAttributeStringValue()
$_option $_optionId $class
testAfterSaveWithExceptions()
testBeforeSaveValueDeletion($value)
testAfterSaveWithAdditionalData($value)
attributeValueDataProvider()
testBeforeSaveAttributeFileName()
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
deletedValueDataProvider()