Skip to content

Commit f4851c5

Browse files
committed
AC-13311: Invalid SKU Handling for Linked Products in Magento
1 parent bdbb253 commit f4851c5

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\ProductLink;
9+
10+
use Magento\Catalog\Api\ProductLinkRepositoryInterface;
11+
use Magento\Catalog\Model\ProductLink\Link;
12+
use Magento\Framework\Exception\CouldNotSaveException;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* @magentoAppIsolation enabled
18+
*/
19+
class RepositorySaveTest extends TestCase
20+
{
21+
/**
22+
* @var ProductLinkRepositoryInterface
23+
*/
24+
private $repository;
25+
26+
protected function setUp(): void
27+
{
28+
parent::setUp();
29+
$this->repository = Bootstrap::getObjectManager()->get(ProductLinkRepositoryInterface::class);
30+
}
31+
32+
public function testSaveWithNullLinkedProductSku(): void
33+
{
34+
$this->expectException(CouldNotSaveException::class);
35+
$this->expectExceptionMessage('The linked product SKU is invalid. Verify the data and try again.');
36+
37+
$objectManager = Bootstrap::getObjectManager();
38+
/** @var Link $link */
39+
$link = $objectManager->create(Link::class);
40+
$link->setSku('sku1');
41+
$link->setLinkedProductSku(null);
42+
43+
$this->repository->save($link);
44+
}
45+
46+
public function testSaveWithEmptyLinkedProductSku(): void
47+
{
48+
$this->expectException(CouldNotSaveException::class);
49+
$this->expectExceptionMessage('The linked product SKU is invalid. Verify the data and try again.');
50+
51+
$objectManager = Bootstrap::getObjectManager();
52+
/** @var Link $link */
53+
$link = $objectManager->create(Link::class);
54+
$link->setSku('sku1');
55+
$link->setLinkedProductSku('');
56+
57+
$this->repository->save($link);
58+
}
59+
}

0 commit comments

Comments
 (0)