diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerDownloadableProduct/CustomerDownloadableProductTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerDownloadableProduct/CustomerDownloadableProductTest.php index 6b8aad83edac..d0ad772e9bb2 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerDownloadableProduct/CustomerDownloadableProductTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerDownloadableProduct/CustomerDownloadableProductTest.php @@ -63,6 +63,18 @@ public function testGuestCannotAccessDownloadableProducts() { $this->graphQlQuery($this->getQuery()); } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable_with_download_limit.php + * @magentoApiDataFixture Magento/Downloadable/_files/customer_order_with_downloadable_product.php + */ + public function testRemainingDownloads() + { + $query = $this->getQuery(); + $response = $this->graphQlQuery($query, [], '', $this->getHeaderMap()); + self::assertArrayHasKey('remaining_downloads', $response['customerDownloadableProducts']['items'][0]); + self::assertEquals(100, $response['customerDownloadableProducts']['items'][0]['remaining_downloads']); + } /** * @magentoApiDataFixture Magento/Customer/_files/customer.php */ diff --git a/dev/tests/integration/testsuite/Magento/Downloadable/_files/product_downloadable_with_download_limit.php b/dev/tests/integration/testsuite/Magento/Downloadable/_files/product_downloadable_with_download_limit.php new file mode 100644 index 000000000000..7f1701d4ca6a --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Downloadable/_files/product_downloadable_with_download_limit.php @@ -0,0 +1,67 @@ +get(ProductRepositoryInterface::class); +/** @var LinkRepositoryInterface $linkRepository */ +$linkRepository = Bootstrap::getObjectManager() + ->create(LinkRepositoryInterface::class); +/** @var ProductInterface $product */ +$product = Bootstrap::getObjectManager() + ->create(ProductInterface::class); +/** @var LinkInterface $downloadableProductLink */ +$downloadableProductLink = Bootstrap::getObjectManager() + ->create(LinkInterface::class); + +$downloadableProductLink +// ->setId(null) + ->setLinkType(Download::LINK_TYPE_URL) + ->setTitle('Downloadable Product Link') + ->setIsShareable(Link::LINK_SHAREABLE_CONFIG) + ->setLinkUrl('http://example.com/downloadable.txt') + ->setNumberOfDownloads(100) + ->setSortOrder(1) + ->setPrice(0); + +$downloadableProductLinks[] = $downloadableProductLink; + +$product + ->setId(1) + ->setTypeId(Type::TYPE_DOWNLOADABLE) + ->setExtensionAttributes( + $product->getExtensionAttributes() + ->setDownloadableProductLinks($downloadableProductLinks) + ) + ->setSku('downloadable-product') + ->setAttributeSetId(4) + ->setWebsiteIds([1]) + ->setName('Downloadable Product Limited') + ->setPrice(10) + ->setVisibility(Visibility::VISIBILITY_BOTH) + ->setStatus(Status::STATUS_ENABLED) + ->setLinksPurchasedSeparately(true) + ->setStockData( + [ + 'qty' => 100, + 'is_in_stock' => 1, + 'manage_stock' => 1, + ] + ); + +$productRepository->save($product); diff --git a/dev/tests/integration/testsuite/Magento/Downloadable/_files/product_downloadable_with_download_limit_rollback.php b/dev/tests/integration/testsuite/Magento/Downloadable/_files/product_downloadable_with_download_limit_rollback.php new file mode 100644 index 000000000000..d88f6f180343 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Downloadable/_files/product_downloadable_with_download_limit_rollback.php @@ -0,0 +1,8 @@ +