Skip to content

Commit 987f975

Browse files
committed
MC-20697: Admin: Create a category
1 parent d428884 commit 987f975

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/CategoryTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Magento\Catalog\Model\Category as Category;
1313
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1414
use Magento\Framework\App\Request\Http as HttpRequest;
15-
use Magento\Framework\Exception\AuthenticationException;
1615
use Magento\Framework\Message\MessageInterface;
1716
use Magento\Framework\Serialize\Serializer\Json;
1817
use Magento\Store\Api\StoreRepositoryInterface;
@@ -37,19 +36,20 @@ class CategoryTest extends AbstractBackendController
3736
/** @var StoreRepositoryInterface */
3837
private $storeRepository;
3938

39+
/** @var Json */
40+
private $json;
41+
4042
/**
4143
* @inheritdoc
42-
*
43-
* @throws AuthenticationException
4444
*/
4545
protected function setUp()
4646
{
4747
parent::setUp();
48-
4948
/** @var ProductResource $productResource */
5049
$this->productResource = $this->_objectManager->get(ProductResource::class);
5150
$this->categoryRepository = $this->_objectManager->get(CategoryRepositoryInterface::class);
5251
$this->storeRepository = $this->_objectManager->get(StoreRepositoryInterface::class);
52+
$this->json = $this->_objectManager->get(Json::class);
5353
}
5454

5555
/**
@@ -134,6 +134,10 @@ public function testDefaultValueForCategoryUrlPath(): void
134134
$this->dispatch('backend/catalog/category/save');
135135
$category = $this->categoryRepository->get($categoryId);
136136
$this->assertEquals($defaultUrlPath, $category->getData('url_path'));
137+
$this->assertSessionMessages(
138+
$this->equalTo([(string)__('You saved the category.')]),
139+
MessageInterface::TYPE_SUCCESS
140+
);
137141
}
138142

139143
/**
@@ -157,7 +161,7 @@ public function testSaveActionFromProductCreationPage($postData): void
157161
$this->stringContains('http://localhost/index.php/backend/catalog/category/edit/')
158162
);
159163
} else {
160-
$result = $this->_objectManager->get(Json::class)->unserialize($body);
164+
$result = $this->json->unserialize($body);
161165
$this->assertArrayHasKey('messages', $result);
162166
$this->assertFalse($result['error']);
163167
$category = $result['category'];
@@ -445,9 +449,9 @@ public function testMoveAction(
445449
->setPostValue('pid', $parentId)
446450
->setMethod(HttpRequest::METHOD_POST);
447451
$this->dispatch('backend/catalog/category/move');
448-
$jsonResponse = json_decode($this->getResponse()->getBody());
452+
$jsonResponse = $this->json->unserialize($this->getResponse()->getBody());
449453
$this->assertNotNull($jsonResponse);
450-
$this->assertEquals($error, $jsonResponse->error);
454+
$this->assertEquals($error, $jsonResponse['error']);
451455
}
452456

453457
/**
@@ -485,6 +489,10 @@ public function testSaveCategoryWithProductPosition(array $postData): void
485489
$this->getRequest()->setPostValue($postData);
486490
$this->dispatch('backend/catalog/category/save');
487491
$newCategoryProductsCount = $this->getCategoryProductsCount();
492+
$this->assertSessionMessages(
493+
$this->equalTo([(string)__('You saved the category.')]),
494+
MessageInterface::TYPE_SUCCESS
495+
);
488496
$this->assertEquals(
489497
$oldCategoryProductsCount,
490498
$newCategoryProductsCount,

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class CategoryTest extends TestCase
5555
/** @var CategoryRepositoryInterface */
5656
private $categoryRepository;
5757

58+
/**
59+
* @inheritdoc
60+
*/
5861
protected function setUp()
5962
{
6063
$this->objectManager = Bootstrap::getObjectManager();
@@ -395,14 +398,8 @@ public function testCategoryCreateWithDifferentFields(array $data): void
395398
$this->_model->setData(array_merge($requiredData, $data));
396399
$this->categoryResource->save($this->_model);
397400
$category = $this->categoryRepository->get($this->_model->getId());
398-
399-
foreach ($data as $key => $value) {
400-
$this->assertEquals(
401-
$value,
402-
$category->getData($key),
403-
sprintf('The field "%s" does not match expected value', $key)
404-
);
405-
}
401+
$categoryData = $category->toArray(array_keys($data));
402+
$this->assertSame($data, $categoryData);
406403
}
407404

408405
/**

0 commit comments

Comments
 (0)