88
99namespace Magento \Downloadable \Api ;
1010
11+ use Magento \Downloadable \Test \Fixture \DownloadableProduct ;
1112use Magento \Framework \Webapi \Rest \Request ;
1213use Magento \TestFramework \Helper \Bootstrap ;
1314use Magento \TestFramework \TestCase \WebapiAbstract ;
@@ -25,7 +26,6 @@ class StockItemUpdatePreservesLinksTest extends WebapiAbstract
2526{
2627 private const ADMIN_TOKEN_RESOURCE_PATH = '/V1/integration/admin/token ' ;
2728 private const PRODUCT_RESOURCE_PATH = '/V1/products ' ;
28- private const TEST_PRODUCT_SKU = 'downloadable-product ' ;
2929
3030 /**
3131 * @var DataFixtureStorage
@@ -47,28 +47,67 @@ protected function setUp(): void
4747 * Verify that REST-API updating product stock_item does not delete downloadable_product_links
4848 */
4949 #[DataFixture(User::class, ['role_id ' => 1 ], 'admin_user ' )]
50- #[DataFixture('Magento/Downloadable/_files/downloadable_product_with_files_and_sample_url.php ' )]
50+ #[DataFixture(DownloadableProduct::class, [
51+ 'sku ' => 'downloadable-product ' ,
52+ 'name ' => 'Downloadable Product Test ' ,
53+ 'price ' => 50.00 ,
54+ 'type_id ' => 'downloadable ' ,
55+ 'links_purchased_separately ' => 1 ,
56+ 'links_title ' => 'Downloadable Links ' ,
57+ 'extension_attributes ' => [
58+ 'website_ids ' => [1 ],
59+ 'stock_item ' => [
60+ 'use_config_manage_stock ' => true ,
61+ 'qty ' => 100 ,
62+ 'is_qty_decimal ' => false ,
63+ 'is_in_stock ' => true ,
64+ ],
65+ 'downloadable_product_links ' => [
66+ [
67+ 'title ' => 'Downloadable Product Link ' ,
68+ 'price ' => 10.00 ,
69+ 'link_type ' => 'url ' ,
70+ 'is_shareable ' => 0 ,
71+ 'number_of_downloads ' => 5 ,
72+ 'sort_order ' => 1
73+ ],
74+ [
75+ 'title ' => 'Another Link ' ,
76+ 'price ' => 15.00 ,
77+ 'link_type ' => 'file ' ,
78+ 'link_file ' => 'test-file.txt ' ,
79+ 'is_shareable ' => 1 ,
80+ 'number_of_downloads ' => 10 ,
81+ 'sort_order ' => 2
82+ ]
83+ ]
84+ ]
85+ ], 'downloadable_product ' )]
5186 public function testStockItemUpdatePreservesDownloadableLinks ()
5287 {
5388 // Steps 1-7: Generate admin access token
5489 $ adminToken = $ this ->generateAdminAccessToken ();
5590
91+ // Get the product SKU from the fixture
92+ $ product = $ this ->fixtures ->get ('downloadable_product ' );
93+ $ productSku = $ product ->getSku ();
94+
5695 // Get original product and verify it has downloadable links
57- $ originalProduct = $ this ->getProductBySku (self :: TEST_PRODUCT_SKU );
96+ $ originalProduct = $ this ->getProductBySku ($ productSku );
5897 $ this ->verifyProductHasDownloadableLinks ($ originalProduct , 'Original product should have downloadable links ' );
5998 $ originalLinks = $ originalProduct ['extension_attributes ' ]['downloadable_product_links ' ];
6099
61100 // Steps 8-14: Update product stock_item via catalogProductRepositoryV1 PUT endpoint
62- $ updatedProduct = $ this ->updateProductStockItem ($ adminToken );
101+ $ updatedProduct = $ this ->updateProductStockItem ($ adminToken, $ productSku );
63102
64103 // Verify the API call was successful (Step 14: Server response Code=200)
65104 $ this ->assertNotEmpty ($ updatedProduct , 'API response should not be empty ' );
66- $ this ->assertEquals (self :: TEST_PRODUCT_SKU , $ updatedProduct ['sku ' ]);
105+ $ this ->assertEquals ($ productSku , $ updatedProduct ['sku ' ]);
67106 $ this ->assertEquals ('99.99 ' , $ updatedProduct ['price ' ]);
68107 $ this ->assertEquals ('1 ' , $ updatedProduct ['status ' ]);
69108
70109 // Steps 15-16: Verify downloadable product links are preserved
71- $ this ->verifyDownloadableLinksPreserved ($ originalLinks );
110+ $ this ->verifyDownloadableLinksPreserved ($ originalLinks, $ productSku );
72111 }
73112
74113 /**
@@ -100,19 +139,19 @@ private function generateAdminAccessToken(): string
100139 /**
101140 * Update Product Stock Item
102141 */
103- private function updateProductStockItem (string $ adminToken ): array
142+ private function updateProductStockItem (string $ adminToken, string $ productSku ): array
104143 {
105144 $ serviceInfo = [
106145 'rest ' => [
107- 'resourcePath ' => self ::PRODUCT_RESOURCE_PATH . '/ ' . self :: TEST_PRODUCT_SKU ,
146+ 'resourcePath ' => self ::PRODUCT_RESOURCE_PATH . '/ ' . $ productSku ,
108147 'httpMethod ' => Request::HTTP_METHOD_PUT ,
109148 'token ' => $ adminToken ,
110149 ],
111150 ];
112151
113152 $ productData = [
114153 'product ' => [
115- 'sku ' => self :: TEST_PRODUCT_SKU ,
154+ 'sku ' => $ productSku ,
116155 'status ' => '1 ' ,
117156 'price ' => '99.99 ' ,
118157 'type_id ' => 'downloadable ' ,
@@ -130,9 +169,9 @@ private function updateProductStockItem(string $adminToken): array
130169 /**
131170 * Verify Downloadable Links are Preserved
132171 */
133- private function verifyDownloadableLinksPreserved (array $ originalLinks ): void
172+ private function verifyDownloadableLinksPreserved (array $ originalLinks, string $ productSku ): void
134173 {
135- $ updatedProduct = $ this ->getProductBySku (self :: TEST_PRODUCT_SKU );
174+ $ updatedProduct = $ this ->getProductBySku ($ productSku );
136175 $ this ->verifyProductHasDownloadableLinks ($ updatedProduct , 'Updated product should preserve downloadable links ' );
137176
138177 $ preservedLinks = $ updatedProduct ['extension_attributes ' ]['downloadable_product_links ' ];
0 commit comments