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

Made getAllOptions() and toOptionArray() compatible #34

Merged
merged 1 commit into from
Feb 8, 2018
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 @@ -42,9 +42,9 @@ public function __construct(
}

/**
* @return array
* @inheritdoc
*/
public function getAllOptions()
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
if (!$this->_options) {
$groups = $this->_groupManagement->getLoggedInGroups();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function __construct(
}

/**
* @return array
* @inheritdoc
*/
public function getAllOptions()
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
if (!$this->_options) {
$collection = $this->_createStoresCollection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function __construct(
}

/**
* @return array
* @inheritdoc
*/
public function getAllOptions()
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
if (!$this->_options) {
$this->_options = $this->_store->getWebsiteValuesForForm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ public function __construct(
}

/**
* Retrieve all options
*
* @return array
* @inheritdoc
*/
public function getAllOptions()
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
if (!$this->_options) {
$this->_options = $this->_createCountriesCollection()->loadByStore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ public function __construct(
}

/**
* Retrieve all options
*
* @return array
* @inheritdoc
*/
public function getAllOptions()
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
if (!$this->options) {
$allowedCountries = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ public function __construct(
}

/**
* Retrieve all region options
*
* @return array
* @inheritdoc
*/
public function getAllOptions()
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
if (!$this->_options) {
$this->_options = $this->_createRegionsCollection()->load()->toOptionArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
class Full extends \Magento\Directory\Model\Config\Source\Country implements \Magento\Framework\Option\ArrayInterface
{
/**
* @param bool $isMultiselect
* @return array
* @inheritdoc
*/
public function toOptionArray($isMultiselect = false)
public function toOptionArray($isMultiselect = false, $foregroundCountries = '')
{
return parent::toOptionArray(true);
return parent::toOptionArray(true, $foregroundCountries);
}
}
5 changes: 2 additions & 3 deletions app/code/Magento/Eav/Model/Entity/Attribute/Source/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public function __construct(

/**
* Retrieve Full Option values array
*
* @return array
* @inheritdoc
*/
public function getAllOptions()
public function getAllOptions($withEmpty = true, $defaultValues = false)
{
if ($this->_options === null) {
$this->_options = $this->_storeCollectionFactory->create()->load()->toOptionArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ class Country extends \Magento\Directory\Model\Config\Source\Country
protected $_options;

/**
* @param bool $noEmpty
* @return array
* @inheritdoc
*/
public function toOptionArray($noEmpty = false)
public function toOptionArray($noEmpty = false, $foregroundCountries = '')
{
$options = parent::toOptionArray($noEmpty);
$options = parent::toOptionArray($noEmpty, $foregroundCountries);

if (!$noEmpty) {
if ($options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,63 @@
*/
namespace Magento\Tax\Test\Unit\Plugin\Checkout\CustomerData;

class CartTest extends \PHPUnit\Framework\TestCase
use Magento\Checkout\CustomerData\Cart as CheckoutCart;
use Magento\Checkout\Helper\Data;
use Magento\Checkout\Model\Session;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote\Item;
use Magento\Tax\Block\Item\Price\Renderer;
use Magento\Tax\Plugin\Checkout\CustomerData\Cart;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

class CartTest extends TestCase
{

/**
* @var \Magento\Checkout\Model\Session
* @var Session|MockObject
*/
protected $checkoutSession;
private $checkoutSession;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var Data|MockObject
*/
protected $checkoutHelper;
private $checkoutHelper;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var Renderer|MockObject
*/
protected $itemPriceRenderer;
private $itemPriceRenderer;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var CheckoutCart|MockObject
*/
protected $checkoutCart;
private $checkoutCart;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var Quote|MockObject
*/
protected $quote;
private $quote;

/**
* @var \Magento\Tax\Plugin\Checkout\CustomerData\Cart
* @var Cart
*/
protected $cart;
private $cart;

protected function setUp()
{
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->checkoutSession = $this->createMock(\Magento\Checkout\Model\Session::class);
$this->checkoutHelper = $this->createMock(\Magento\Checkout\Helper\Data::class);
$this->itemPriceRenderer = $this->createMock(\Magento\Tax\Block\Item\Price\Renderer::class);
$this->checkoutCart = $this->createMock(\Magento\Checkout\CustomerData\Cart::class);
$this->quote = $this->createMock(\Magento\Quote\Model\Quote::class);

$this->checkoutSession->expects(
$this->any()
)->method(
'getQuote'
)->willReturn($this->quote);

$this->cart = $helper->getObject(
\Magento\Tax\Plugin\Checkout\CustomerData\Cart::class,
[
'checkoutSession' => $this->checkoutSession,
'checkoutHelper' => $this->checkoutHelper,
'itemPriceRenderer' => $this->itemPriceRenderer,
]
$this->checkoutSession = $this->createMock(Session::class);
$this->checkoutHelper = $this->createMock(Data::class);
$this->itemPriceRenderer = $this->createMock(Renderer::class);
$this->checkoutCart = $this->createMock(CheckoutCart::class);
$this->quote = $this->createMock(Quote::class);

$this->checkoutSession->method('getQuote')
->willReturn($this->quote);

$this->cart = new Cart(
$this->checkoutSession,
$this->checkoutHelper,
$this->itemPriceRenderer
);
}

Expand All @@ -77,49 +79,34 @@ public function testAfterGetSectionData()
]
];

$this->checkoutHelper->expects(
$this->atLeastOnce()
)->method(
'formatPrice'
)->willReturn('formatted');

$item1 = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
$item2 = $this->createMock(\Magento\Quote\Model\Quote\Item::class);

$item1->expects(
$this->atLeastOnce()
)->method(
'getItemId'
)->willReturn(1);
$item2->expects(
$this->atLeastOnce()
)->method(
'getItemId'
)->willReturn(2);

$this->quote->expects(
$this->any()
)->method(
'getAllVisibleItems'
)->willReturn([
$item1,
$item2,
]);

$this->itemPriceRenderer->expects(
$this->atLeastOnce(1)
)->method(
'toHtml'
)->willReturn(1);
$this->checkoutHelper->method('formatPrice')
->willReturn('formatted');

$item1 = $this->createMock(Item::class);
$item2 = $this->createMock(Item::class);

$item1->method('getItemId')
->willReturn(1);
$item2->method('getItemId')
->willReturn(2);

$this->quote->method('getAllVisibleItems')
->willReturn([
$item1,
$item2,
]);

$this->itemPriceRenderer->method('toHtml')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joni-jones @buskamuza It looks like missing check that method toHtml will be called at least once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ihor-sviziev, this expects is redundant because if toHtml() won't be called the test will fail. "Price assertions" check this case.

->willReturn(1);

$result = $this->cart->afterGetSectionData($this->checkoutCart, $input);

$this->assertArrayHasKey('subtotal_incl_tax', $result);
$this->assertArrayHasKey('subtotal_excl_tax', $result);
$this->assertArrayHasKey('items', $result);
$this->assertTrue(is_array($result['items']));
$this->assertEquals(2, count($result['items']));
$this->assertEquals(1, count($result['items'][0]['product_price']));
$this->assertEquals(1, count($result['items'][1]['product_price']));
self::assertArrayHasKey('subtotal_incl_tax', $result);
self::assertArrayHasKey('subtotal_excl_tax', $result);
self::assertArrayHasKey('items', $result);
self::assertTrue(is_array($result['items']));
self::assertEquals(2, count($result['items']));
self::assertEquals(1, $result['items'][0]['product_price']);
self::assertEquals(1, $result['items'][1]['product_price']);
}
}