Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Extend test coverage for CustomerDownloadableGraphQl #990

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Downloadable\Api\Data\LinkInterface;
use Magento\Downloadable\Api\LinkRepositoryInterface;
use Magento\Downloadable\Helper\Download;
use Magento\Downloadable\Model\Link;
use Magento\Downloadable\Model\Product\Type;
use Magento\TestFramework\Helper\Bootstrap;

/** @var ProductRepositoryInterface $productRepository */
$productRepository = Bootstrap::getObjectManager()
->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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

require __DIR__ . '/product_downloadable_rollback.php';