Skip to content

Commit

Permalink
Merge pull request #518 from magento-dragons/MAGETWO-40002
Browse files Browse the repository at this point in the history
[DRAGONS] Functional tests&Bugfixes
  • Loading branch information
Kasian,Andrii(akasian) committed Aug 12, 2015
2 parents e5a2d00 + dcc50d4 commit fc2de56
Show file tree
Hide file tree
Showing 29 changed files with 567 additions and 111 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/ConfigurableProduct/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<route url="/V1/configurable-products/:sku/children" method="GET">
<service class="Magento\ConfigurableProduct\Api\LinkManagementInterface" method="getChildren"/>
<resources>
<resource ref="Magento_Catalog::products"/>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/configurable-products/:sku/children/:childSku" method="DELETE">
Expand All @@ -34,13 +34,13 @@
<route url="/V1/configurable-products/:sku/options/:id" method="GET">
<service class="Magento\ConfigurableProduct\Api\OptionRepositoryInterface" method="get"/>
<resources>
<resource ref="Magento_Catalog::products"/>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/configurable-products/:sku/options/all" method="GET">
<service class="Magento\ConfigurableProduct\Api\OptionRepositoryInterface" method="getList"/>
<resources>
<resource ref="Magento_Catalog::products"/>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/configurable-products/:sku/options" method="POST">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

namespace Magento\Downloadable\Block\Adminhtml\Sales\Items\Column\Downloadable;

use Magento\Downloadable\Model\Link;
use Magento\Downloadable\Model\Link\Purchased;
use Magento\Store\Model\ScopeInterface;

/**
* Sales Order downloadable items name column renderer
Expand Down Expand Up @@ -61,8 +63,8 @@ public function __construct(
public function getLinks()
{
$this->_purchased = $this->_purchasedFactory->create()->load(
$this->getItem()->getOrder()->getId(),
'order_id'
$this->getItem()->getId(),
'order_item_id'
);
$purchasedItem = $this->_itemsFactory->create()->addFieldToFilter('order_item_id', $this->getItem()->getId());
$this->_purchased->setPurchasedItems($purchasedItem);
Expand All @@ -74,9 +76,9 @@ public function getLinks()
*/
public function getLinksTitle()
{
if ($this->_purchased && $this->_purchased->getLinkSectionTitle()) {
return $this->_purchased->getLinkSectionTitle();
}
return $this->_scopeConfig->getValue(\Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
return $this->getLinks()->getLinkSectionTitle() ?: $this->_scopeConfig->getValue(
Link::XML_PATH_LINKS_TITLE,
ScopeInterface::SCOPE_STORE
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

namespace Magento\Downloadable\Block\Sales\Order\Email\Items;

use Magento\Downloadable\Model\Link;
use Magento\Downloadable\Model\Link\Purchased;
use Magento\Downloadable\Model\Link\Purchased\Item;
use Magento\Store\Model\ScopeInterface;

/**
* Downlaodable Sales Order Email items renderer
Expand Down Expand Up @@ -63,12 +65,12 @@ public function __construct(
public function getLinks()
{
$this->_purchased = $this->_purchasedFactory->create()->load(
$this->getItem()->getOrder()->getId(),
'order_id'
$this->getItem()->getId(),
'order_item_id'
);
$purchasedLinks = $this->_itemsFactory->create()->addFieldToFilter(
'order_item_id',
$this->getItem()->getOrderItem()->getId()
$this->getItem()->getId()
);
$this->_purchased->setPurchasedItems($purchasedLinks);

Expand All @@ -80,10 +82,10 @@ public function getLinks()
*/
public function getLinksTitle()
{
if ($this->_purchased->getLinkSectionTitle()) {
return $this->_purchased->getLinkSectionTitle();
}
return $this->_scopeConfig->getValue(\Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
return $this->getLinks()->getLinkSectionTitle() ?: $this->_scopeConfig->getValue(
Link::XML_PATH_LINKS_TITLE,
ScopeInterface::SCOPE_STORE
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

namespace Magento\Downloadable\Block\Sales\Order\Email\Items\Order;

use Magento\Downloadable\Model\Link;
use Magento\Downloadable\Model\Link\Purchased\Item;
use Magento\Store\Model\ScopeInterface;

/**
* Downloadable Sales Order Email items renderer
Expand Down Expand Up @@ -57,8 +59,8 @@ public function __construct(
public function getLinks()
{
$this->_purchased = $this->_purchasedFactory->create()->load(
$this->getItem()->getOrder()->getId(),
'order_id'
$this->getItem()->getId(),
'order_item_id'
);
$purchasedLinks = $this->_itemsFactory->create()->addFieldToFilter('order_item_id', $this->getItem()->getId());
$this->_purchased->setPurchasedItems($purchasedLinks);
Expand All @@ -71,10 +73,10 @@ public function getLinks()
*/
public function getLinksTitle()
{
if ($this->_purchased->getLinkSectionTitle()) {
return $this->_purchased->getLinkSectionTitle();
}
return $this->_scopeConfig->getValue(\Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
return $this->getLinks()->getLinkSectionTitle() ?: $this->_scopeConfig->getValue(
Link::XML_PATH_LINKS_TITLE,
ScopeInterface::SCOPE_STORE
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

namespace Magento\Downloadable\Block\Sales\Order\Item\Renderer;

use Magento\Downloadable\Model\Link;
use Magento\Downloadable\Model\Link\Purchased;
use Magento\Store\Model\ScopeInterface;

/**
* Downloadable order item render block
Expand Down Expand Up @@ -57,8 +59,8 @@ public function __construct(
public function getLinks()
{
$this->_purchasedLinks = $this->_purchasedFactory->create()->load(
$this->getOrderItem()->getOrder()->getId(),
'order_id'
$this->getOrderItem()->getId(),
'order_item_id'
);
$purchasedItems = $this->_itemsFactory->create()->addFieldToFilter(
'order_item_id',
Expand All @@ -74,9 +76,9 @@ public function getLinks()
*/
public function getLinksTitle()
{
if ($this->_purchasedLinks->getLinkSectionTitle()) {
return $this->_purchasedLinks->getLinkSectionTitle();
}
return $this->_scopeConfig->getValue(\Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
return $this->getLinks()->getLinkSectionTitle() ?: $this->_scopeConfig->getValue(
Link::XML_PATH_LINKS_TITLE,
ScopeInterface::SCOPE_STORE
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Downloadable\Test\Unit\Block\Adminhtml\Sales\Items\Column\Downloadable;

use Magento\Downloadable\Model\Resource\Link\Purchased\Item\CollectionFactory;

/**
* Tests Magento\Downloadable\Block\Adminhtml\Sales\Items\Column\Downloadable\Name
*/
class NameTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Downloadable\Block\Adminhtml\Sales\Items\Column\Downloadable\Name
*/
protected $block;

/**
* @var \Magento\Downloadable\Model\Link\PurchasedFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $purchasedFactory;

/**
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $itemsFactory;

public function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$contextMock = $this->getMockBuilder('Magento\Backend\Block\Template\Context')
->disableOriginalConstructor()
->getMock();
$this->purchasedFactory = $this->getMockBuilder('Magento\Downloadable\Model\Link\PurchasedFactory')
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$this->itemsFactory = $this->getMockBuilder(
'Magento\Downloadable\Model\Resource\Link\Purchased\Item\CollectionFactory'
)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->block = $objectManager->getObject(
'Magento\Downloadable\Block\Adminhtml\Sales\Items\Column\Downloadable\Name',
[
'context' => $contextMock,
'purchasedFactory' => $this->purchasedFactory,
'itemsFactory' => $this->itemsFactory
]
);
}

public function testGetLinks()
{
$item = $this->getMockBuilder('\Magento\Sales\Model\Order\Item')
->disableOriginalConstructor()
->setMethods(['getId'])
->getMock();
$linkPurchased = $this->getMockBuilder('Magento\Downloadable\Model\Link\Purchased')
->disableOriginalConstructor()
->setMethods(['load'])
->getMock();
$itemCollection = $this->getMockBuilder('Magento\Downloadable\Model\Resource\Link\Purchased\Item\Collection')
->disableOriginalConstructor()
->setMethods(['addFieldToFilter'])
->getMock();

$this->block->setData('item', $item);
$this->purchasedFactory->expects($this->once())->method('create')->willReturn($linkPurchased);
$linkPurchased->expects($this->once())->method('load')->with('itemId', 'order_item_id')->willReturnSelf();
$item->expects($this->any())->method('getId')->willReturn('itemId');
$this->itemsFactory->expects($this->once())->method('create')->willReturn($itemCollection);
$itemCollection->expects($this->once())
->method('addFieldToFilter')
->with('order_item_id', 'itemId')
->willReturnSelf();

$this->assertEquals($linkPurchased, $this->block->getLinks());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Downloadable\Test\Unit\Block\Sales\Order\Email\Items;

use Magento\Downloadable\Model\Resource\Link\Purchased\Item\CollectionFactory;

/**
* Tests Magento\Downloadable\Test\Unit\Block\Sales\Order\Email\Items\Downloadable
*/
class DownloadableTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Downloadable\Block\Sales\Order\Email\Items\Downloadable
*/
protected $block;

/**
* @var \Magento\Downloadable\Model\Link\PurchasedFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $purchasedFactory;

/**
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
*/
protected $itemsFactory;

public function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$contextMock = $this->getMockBuilder('Magento\Backend\Block\Template\Context')
->disableOriginalConstructor()
->getMock();
$this->purchasedFactory = $this->getMockBuilder('Magento\Downloadable\Model\Link\PurchasedFactory')
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$this->itemsFactory = $this->getMockBuilder(
'Magento\Downloadable\Model\Resource\Link\Purchased\Item\CollectionFactory'
)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->block = $objectManager->getObject(
'Magento\Downloadable\Block\Sales\Order\Email\Items\Downloadable',
[
'context' => $contextMock,
'purchasedFactory' => $this->purchasedFactory,
'itemsFactory' => $this->itemsFactory
]
);
}

public function testGetLinks()
{
$item = $this->getMockBuilder('\Magento\Sales\Model\Order\Item')
->disableOriginalConstructor()
->setMethods(['getId'])
->getMock();
$linkPurchased = $this->getMockBuilder('Magento\Downloadable\Model\Link\Purchased')
->disableOriginalConstructor()
->setMethods(['load'])
->getMock();
$itemCollection = $this->getMockBuilder('Magento\Downloadable\Model\Resource\Link\Purchased\Item\Collection')
->disableOriginalConstructor()
->setMethods(['addFieldToFilter'])
->getMock();

$this->block->setData('item', $item);
$this->purchasedFactory->expects($this->once())->method('create')->willReturn($linkPurchased);
$linkPurchased->expects($this->once())->method('load')->with('itemId', 'order_item_id')->willReturnSelf();
$item->expects($this->any())->method('getId')->willReturn('itemId');
$this->itemsFactory->expects($this->once())->method('create')->willReturn($itemCollection);
$itemCollection->expects($this->once())
->method('addFieldToFilter')
->with('order_item_id', 'itemId')
->willReturnSelf();

$this->assertEquals($linkPurchased, $this->block->getLinks());
}
}
Loading

0 comments on commit fc2de56

Please sign in to comment.