Skip to content

Commit ef56812

Browse files
committedOct 8, 2019
ENGCOM-6042: Extend test coverage for CustomerDownloadableGraphQl #990
- Merge Pull Request magento/graphql-ce#990 from TomashKhamlai/graphql-ce:issue/989 - Merged commits: 1. bccd287
2 parents 61a5a30 + bccd287 commit ef56812

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed
 

‎dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerDownloadableProduct/CustomerDownloadableProductTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ public function testGuestCannotAccessDownloadableProducts()
6363
{
6464
$this->graphQlQuery($this->getQuery());
6565
}
66+
/**
67+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
68+
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable_with_download_limit.php
69+
* @magentoApiDataFixture Magento/Downloadable/_files/customer_order_with_downloadable_product.php
70+
*/
71+
public function testRemainingDownloads()
72+
{
73+
$query = $this->getQuery();
74+
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());
75+
self::assertArrayHasKey('remaining_downloads', $response['customerDownloadableProducts']['items'][0]);
76+
self::assertEquals(100, $response['customerDownloadableProducts']['items'][0]['remaining_downloads']);
77+
}
6678
/**
6779
* @magentoApiDataFixture Magento/Customer/_files/customer.php
6880
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
11+
use Magento\Catalog\Model\Product\Visibility;
12+
use Magento\Downloadable\Api\Data\LinkInterface;
13+
use Magento\Downloadable\Api\LinkRepositoryInterface;
14+
use Magento\Downloadable\Helper\Download;
15+
use Magento\Downloadable\Model\Link;
16+
use Magento\Downloadable\Model\Product\Type;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
19+
/** @var ProductRepositoryInterface $productRepository */
20+
$productRepository = Bootstrap::getObjectManager()
21+
->get(ProductRepositoryInterface::class);
22+
/** @var LinkRepositoryInterface $linkRepository */
23+
$linkRepository = Bootstrap::getObjectManager()
24+
->create(LinkRepositoryInterface::class);
25+
/** @var ProductInterface $product */
26+
$product = Bootstrap::getObjectManager()
27+
->create(ProductInterface::class);
28+
/** @var LinkInterface $downloadableProductLink */
29+
$downloadableProductLink = Bootstrap::getObjectManager()
30+
->create(LinkInterface::class);
31+
32+
$downloadableProductLink
33+
// ->setId(null)
34+
->setLinkType(Download::LINK_TYPE_URL)
35+
->setTitle('Downloadable Product Link')
36+
->setIsShareable(Link::LINK_SHAREABLE_CONFIG)
37+
->setLinkUrl('http://example.com/downloadable.txt')
38+
->setNumberOfDownloads(100)
39+
->setSortOrder(1)
40+
->setPrice(0);
41+
42+
$downloadableProductLinks[] = $downloadableProductLink;
43+
44+
$product
45+
->setId(1)
46+
->setTypeId(Type::TYPE_DOWNLOADABLE)
47+
->setExtensionAttributes(
48+
$product->getExtensionAttributes()
49+
->setDownloadableProductLinks($downloadableProductLinks)
50+
)
51+
->setSku('downloadable-product')
52+
->setAttributeSetId(4)
53+
->setWebsiteIds([1])
54+
->setName('Downloadable Product Limited')
55+
->setPrice(10)
56+
->setVisibility(Visibility::VISIBILITY_BOTH)
57+
->setStatus(Status::STATUS_ENABLED)
58+
->setLinksPurchasedSeparately(true)
59+
->setStockData(
60+
[
61+
'qty' => 100,
62+
'is_in_stock' => 1,
63+
'manage_stock' => 1,
64+
]
65+
);
66+
67+
$productRepository->save($product);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
require __DIR__ . '/product_downloadable_rollback.php';

0 commit comments

Comments
 (0)
Please sign in to comment.