Skip to content

Commit

Permalink
ENGCOM-6042: Extend test coverage for CustomerDownloadableGraphQl #990
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaorobei authored Oct 10, 2019
2 parents 207100a + ef56812 commit e15cd9e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
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';

0 comments on commit e15cd9e

Please sign in to comment.