Skip to content

Commit

Permalink
MAGETWO-66506: imagento/magento2#8515: Downloadable product is availa…
Browse files Browse the repository at this point in the history
…ble for downloa… #8917
  • Loading branch information
Oleksii Korshenko authored Mar 23, 2017
2 parents 55f180c + 08528cf commit e1602e8
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
if ($item->getProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
|| $item->getRealProductType() == \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
) {
if (in_array($item->getStatusId(), $expiredStatuses)) {
if ($order->isCanceled() || in_array($item->getStatusId(), $expiredStatuses)) {
$downloadableItemsStatuses[$item->getId()] = $linkStatuses['expired'];
} else {
$downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AssertAuthorizationInCommentsHistory extends AbstractConstraint
/**
* Pattern of message about authorized amount in order.
*/
const AUTHORIZED_AMOUNT_PATTERN = '/(IPN "Pending" )*Authorized amount of \w*\W{1,2}%s. Transaction ID: "[\w\-]*"/';
const AUTHORIZED_AMOUNT_PATTERN = '/(IPN "Pending" )*Authorized amount of .+?%s. Transaction ID: "[\w\-]*"/';

/**
* Assert that comment about authorized amount exists in Comments History section on order page in Admin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AssertCaptureInCommentsHistory extends AbstractConstraint
/**
* Pattern of message about captured amount in order.
*/
const CAPTURED_AMOUNT_PATTERN = '/^Captured amount of [\W]{1,2}%s online\. Transaction ID: "[\w\-]*"/';
const CAPTURED_AMOUNT_PATTERN = '/^Captured amount of .+?%s online\. Transaction ID: "[\w\-]*"/';

/**
* Assert that comment about captured amount exists in Comments History section on order page in Admin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AssertRefundInCommentsHistory extends AbstractConstraint
/**
* Pattern of message about refunded amount in order.
*/
const REFUNDED_AMOUNT_PATTERN = '/^We refunded \w*\W{1,2}%s online. Transaction ID: "[\w\-]*"/';
const REFUNDED_AMOUNT_PATTERN = '/^We refunded .+?%s online. Transaction ID: "[\w\-]*"/';

/**
* Assert that comment about refunded amount exists in Comments History section on order page in Admin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@
<item name="comment_text" xsi:type="string">Partial Invoice with changed qty = 0</item>
</item>
</field>
<field name="1" xsi:type="array">
<item name="form_data" xsi:type="array">
<item name="do_shipment" xsi:type="string">No</item>
<item name="comment_text" xsi:type="string">Partial Invoice to the rest of order items</item>
</item>
</field>
</dataset>
</repository>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<constraint name="Magento\Tax\Test\Constraint\AssertTaxRuleForm" />
</variation>
<variation name="CreateTaxRuleEntityTestVariation4">
<data name="tag" xsi:type="string">stable:no</data>
<data name="taxRule/data/code" xsi:type="string">TaxIdentifier%isolation%</data>
<data name="taxRule/data/tax_rate/dataset/rate_0" xsi:type="string">withZipRange</data>
<data name="taxRule/data/tax_rate/dataset/rate_1" xsi:type="string">US-CA-Rate_1</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
<testCase name="Magento\UrlRewrite\Test\TestCase\CreateProductWithSeveralWebsitesUrlRewriteTest" summary="Test product url rewrites when it is created in several websites">
<variation name="CreateSimpleProductEntityWithSeveralWebsites" summary="Create product with several websites and check URL Rewites" ticketId="MAGETWO-27238">
<data name="issue" xsi:type="string">MAGETWO-63645: [FT] Magento\UrlRewrite\Test\TestCase\CreateProductWithSeveralWebsitesUrlRewriteTest randomly fails on CI</data>
<data name="tag" xsi:type="string">to_maintain:yes</data>
<data name="tag" xsi:type="string">stable:no</data>
<data name="issue" xsi:type="string">MAGETWO-66532: [FT] Magento\UrlRewrite\Test\TestCase\CreateProductWithSeveralWebsitesUrlRewriteTest randomly fails on Jenkins</data>
<data name="product/data/url_key" xsi:type="string">simple-product-%isolation%</data>
<data name="product/data/name" xsi:type="string">Simple Product %isolation%</data>
<data name="product/data/sku" xsi:type="string">simple_sku_%isolation%</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Downloadable\Model\Observer;

/**
* Integration test for case, when customer is able to download
* downloadable product, after order was canceled.
*/
class SetLinkStatusObserverTest extends \PHPUnit_Framework_TestCase
{
/**
* Object manager
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;

/**
* Initialization of dependencies
*/
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
}

/**
* Asserting, that links status is expired after canceling of order.
* This test relates to the GitHub issue magento/magento2#8515.
*
* @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php
* @magentoDataFixture Magento/Downloadable/_files/order_with_downloadable_product.php
*/
public function testCheckStatusOnOrderCancel()
{
/** @var \Magento\Sales\Model\Order $order */
$order = $this->objectManager->create(\Magento\Sales\Model\Order::class);
$order->loadByIncrementId('100000001');

$orderItems = $order->getAllItems();
$items = array_values($orderItems);
/** @var \Magento\Sales\Model\Order\Item $orderItem */
$orderItem = array_shift($items);

/** Canceling order to reproduce test case */
$order->setState(\Magento\Sales\Model\Order::STATE_CANCELED);
$order->save();

/** @var \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\Collection $linkCollection */
$linkCollection = $this->objectManager->create(
\Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\CollectionFactory::class
)->create();

$linkCollection->addFieldToFilter('order_item_id', $orderItem->getId());

/** Assert there are items in linkCollection to avoid false-positive test result. */
$this->assertGreaterThan(0, $linkCollection->count());

/** @var \Magento\Downloadable\Model\Link\Purchased\Item $linkItem */
foreach ($linkCollection->getItems() as $linkItem) {
$this->assertEquals(
\Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_EXPIRED,
$linkItem->getStatus()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@
\Magento\Sales\Model\Order\Payment::class);
$payment->setMethod('checkmo');

/** @var \Magento\Sales\Model\Order\Item $orderItem */
$orderItem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Sales\Model\Order\Item::class);

/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$product = $productRepository->getById(1);
$link = $product->getExtensionAttributes()->getDownloadableProductLinks()[0];

$orderItem->setProductId(
1
)->setProductType(
\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE
)->setProductOptions(
['links' => [$link->getId()]]
)->setBasePrice(
100
)->setQtyOrdered(
Expand Down

0 comments on commit e1602e8

Please sign in to comment.