-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
12535: Product change sku via repository.
- Loading branch information
1 parent
321278b
commit 4996ea2
Showing
3 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
dev/tests/integration/testsuite/Magento/Catalog/Model/ProductRepositoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\ResourceModel\Product as ProductResource; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** | ||
* Provide tests for ProductRepository model. | ||
*/ | ||
class ProductRepositoryTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Test subject. | ||
* | ||
* @var ProductRepositoryInterface | ||
*/ | ||
private $productRepository; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); | ||
} | ||
|
||
/** | ||
* Test Product Repository can change(update) "sku" for given product. | ||
* | ||
* @magentoDataFixture Magento/Catalog/_files/product_simple.php | ||
* @magentoDbIsolation enabled | ||
* @magentoAppArea adminhtml | ||
*/ | ||
public function testUpdateProductSku() | ||
{ | ||
$newSku = 'simple-edited'; | ||
$productId = Bootstrap::getObjectManager()->get(ProductResource::class)->getIdBySku('simple'); | ||
$initialProduct = Bootstrap::getObjectManager()->create(Product::class)->load($productId); | ||
|
||
$initialProduct->setSku($newSku); | ||
$this->productRepository->save($initialProduct); | ||
|
||
$updatedProduct = Bootstrap::getObjectManager()->create(Product::class); | ||
$updatedProduct->load($productId); | ||
self::assertSame($newSku, $updatedProduct->getSku()); | ||
|
||
//clean up. | ||
$this->productRepository->delete($updatedProduct); | ||
} | ||
} |