Skip to content

Commit

Permalink
magento-engcom#101: Adjust tests to new behaviour.
Browse files Browse the repository at this point in the history
  • Loading branch information
pogster committed Aug 18, 2018
1 parent f27826e commit c39d756
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,34 @@ class SkuTest extends \PHPUnit\Framework\TestCase
/**
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testGenerateUniqueSkuExistingProduct()
public function testGenerateUniqueSkuExistingProductDuplication()
{
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\ProductRepository::class
);
$product = $repository->get('simple');
$product->setId(null);
$product->setIsDuplicate(true);
$this->assertEquals('simple', $product->getSku());
$product->getResource()->getAttribute('sku')->getBackend()->beforeSave($product);
$this->assertEquals('simple-1', $product->getSku());
}

/**
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testGenerateUniqueSkuExistingProductNoDuplication()
{
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\ProductRepository::class
);
$product = $repository->get('simple');
$product->setId(null);
$this->assertEquals('simple', $product->getSku());
$product->getResource()->getAttribute('sku')->getBackend()->beforeSave($product);
$this->assertEquals('simple', $product->getSku());
}

/**
* @param $product \Magento\Catalog\Model\Product
* @dataProvider uniqueSkuDataProvider
Expand Down Expand Up @@ -54,10 +70,14 @@ public function testGenerateUniqueLongSku()
$copier = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Catalog\Model\Product\Copier::class
);
$copier->copy($product);
$duplicate = $copier->copy($product);
$this->assertEquals('0123456789012345678901234567890123456789012345678901234567890123', $product->getSku());
$product->getResource()->getAttribute('sku')->getBackend()->beforeSave($product);
$this->assertEquals('01234567890123456789012345678901234567890123456789012345678901-1', $product->getSku());
$this->assertEquals('0123456789012345678901234567890123456789012345678901234567890123', $product->getSku());
$duplicate->assertEquals('01234567890123456789012345678901234567890123456789012345678901-1', $duplicate->getSku());

$duplicate->getResource()->getAttribute('sku')->getBackend()->beforeSave($duplicate);
$duplicate->assertEquals('01234567890123456789012345678901234567890123456789012345678901-2', $duplicate->getSku());
}

/**
Expand Down

0 comments on commit c39d756

Please sign in to comment.