Skip to content

Commit 6d05df0

Browse files
committed
MC-36956: Create automated test for "Upload Category Image"
1 parent 2c97bb8 commit 6d05df0

File tree

1 file changed

+9
-8
lines changed
  • dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel

1 file changed

+9
-8
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/CategoryTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\Category as CategoryModel;
1313
use Magento\Catalog\Model\ResourceModel\Category as CategoryResource;
1414
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
15+
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
1516
use Magento\Framework\App\Filesystem\DirectoryList;
1617
use Magento\Framework\Filesystem;
1718
use Magento\Framework\Filesystem\Directory\WriteInterface;
@@ -64,7 +65,7 @@ protected function setUp(): void
6465
$this->categoryRepository = $this->objectManager->get(CategoryRepositoryInterface::class);
6566
$this->categoryResource = $this->objectManager->get(CategoryResource::class);
6667
$this->storeManager = $this->objectManager->get(StoreManagerInterface::class);
67-
$this->categoryCollection = $this->objectManager->get(CategoryCollection::class);
68+
$this->categoryCollection = $this->objectManager->get(CategoryCollectionFactory::class)->create();
6869
$this->filesystem = $this->objectManager->get(Filesystem::class);
6970
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
7071
}
@@ -92,8 +93,8 @@ public function testAddImageForCategory(): void
9293
'type' => 'image/jpg',
9394
'tmp_name' => '/tmp/phpDstnAx',
9495
'file' => 'magento_small_image.jpg',
96+
'url' => $this->prepareDataImageUrl('magento_small_image.jpg'),
9597
];
96-
$this->prepareDataImageUrl($dataImage);
9798
$imageRelativePath = self::BASE_PATH . DIRECTORY_SEPARATOR . $dataImage['file'];
9899
$expectedImage = DIRECTORY_SEPARATOR . $this->storeManager->getStore()->getBaseMediaDir()
99100
. DIRECTORY_SEPARATOR . $imageRelativePath;
@@ -116,14 +117,14 @@ public function testAddImageForCategory(): void
116117
}
117118

118119
/**
119-
* Add image url to image data
120+
* Prepare image url for image data
120121
*
121-
* @param array $dataImage
122-
* @return void
122+
* @param string $file
123+
* @return string
123124
*/
124-
private function prepareDataImageUrl(array &$dataImage): void
125+
private function prepareDataImageUrl(string $file): string
125126
{
126-
$dataImage['url'] = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
127-
. self::BASE_TMP_PATH . DIRECTORY_SEPARATOR . $dataImage['file'];
127+
return $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
128+
. self::BASE_TMP_PATH . DIRECTORY_SEPARATOR . $file;
128129
}
129130
}

0 commit comments

Comments
 (0)