init
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Checkout\Block\Cart;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\CatalogInventory\Api\StockItemRepositoryInterface;
|
||||
use Magento\CatalogInventory\Model\StockRegistryProvider;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
class AbstractCartTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Tests that product in shopping cart remains visible even after it becomes out of stock.
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote.php
|
||||
*/
|
||||
public function testProductsOutOfStockIsVisibleInShoppingCart()
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$reservedOrderId = 'test01';
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get($productSku);
|
||||
|
||||
$this->setProductOutOfStock($product->getId());
|
||||
|
||||
$quote = $this->getStoredQuote($reservedOrderId);
|
||||
|
||||
$checkoutSession = $this->getMockBuilder(Session::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$checkoutSession->method('getQuote')->willReturn($quote);
|
||||
|
||||
$abstractCart = $objectManager->create(
|
||||
AbstractCart::class,
|
||||
['checkoutSession' => $checkoutSession]
|
||||
);
|
||||
|
||||
$items = array_filter(
|
||||
$abstractCart->getItems(),
|
||||
function (\Magento\Quote\Model\Quote\Item $item) use ($productSku) {
|
||||
return $item->getSku() === $productSku;
|
||||
}
|
||||
);
|
||||
|
||||
$this->assertNotEmpty(
|
||||
$items,
|
||||
'Product disappeared from shopping cart after it had become out of stock.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @return void
|
||||
*/
|
||||
private function setProductOutOfStock($productId)
|
||||
{
|
||||
/** @var $stockRegistryProvider StockRegistryProvider */
|
||||
$stockRegistryProvider = Bootstrap::getObjectManager()->get(StockRegistryProvider::class);
|
||||
$stockItem = $stockRegistryProvider->getStockItem($productId, 0);
|
||||
$stockItem->setIsInStock(false);
|
||||
|
||||
/** @var $stockItemRepository StockItemRepositoryInterface */
|
||||
$stockItemRepository = Bootstrap::getObjectManager()->get(StockItemRepositoryInterface::class);
|
||||
$stockItemRepository->save($stockItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $reservedOrderId
|
||||
* @return \Magento\Quote\Api\Data\CartInterface
|
||||
*/
|
||||
private function getStoredQuote($reservedOrderId)
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId);
|
||||
|
||||
/** @var CartRepositoryInterface $cartRepository */
|
||||
$cartRepository = Bootstrap::getObjectManager()->create(CartRepositoryInterface::class);
|
||||
$quoteItems = $cartRepository->getList($searchCriteriaBuilder->create())->getItems();
|
||||
|
||||
return current($quoteItems);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Block\Cart;
|
||||
|
||||
use Magento\Catalog\Block\Product\ProductList\AbstractLinksTest;
|
||||
use Magento\Catalog\ViewModel\Product\Listing\PreparePostData;
|
||||
use Magento\Checkout\Model\Session;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
|
||||
use Magento\TestFramework\Store\ExecuteInStoreContext;
|
||||
|
||||
/**
|
||||
* Check the correct behavior of cross-sell products in the shopping cart
|
||||
*
|
||||
* @see \Magento\Checkout\Block\Cart\Crosssell
|
||||
* @magentoDbIsolation disabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class CrosssellTest extends AbstractLinksTest
|
||||
{
|
||||
private const MAX_ITEM_COUNT = 4;
|
||||
|
||||
/** @var Session */
|
||||
private $checkoutSession;
|
||||
|
||||
/** @var string */
|
||||
private $addToCartButtonXpath = "//div[contains(@class, 'actions-primary')]/button[@type='button']";
|
||||
|
||||
/** @var string */
|
||||
private $addToCartSubmitXpath = "//div[contains(@class, 'actions-primary')]"
|
||||
. "/form[@data-product-sku='%s']/button[@type='submit']";
|
||||
|
||||
/** @var string */
|
||||
private $addToLinksXpath = "//div[contains(@class, 'actions-secondary')]";
|
||||
|
||||
/** @var ExecuteInStoreContext */
|
||||
private $executeInStoreContext;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->block = $this->layout->createBlock(Crosssell::class);
|
||||
$this->linkType = 'crosssell';
|
||||
$this->titleName = (string)__('More Choices:');
|
||||
$this->checkoutSession = $this->objectManager->get(Session::class);
|
||||
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a simple cross-sell product when block code is generated
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @return void
|
||||
*/
|
||||
public function testSimpleCrosssellProduct(): void
|
||||
{
|
||||
$relatedProduct = $this->productRepository->get('simple-1');
|
||||
$this->linkProducts('simple', ['simple-1' => ['position' => 2]]);
|
||||
$this->setCheckoutSessionQuote('test_order_with_simple_product_without_address');
|
||||
$this->prepareBlock();
|
||||
$html = $this->block->toHtml();
|
||||
|
||||
$this->assertNotEmpty($html);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($this->titleXpath, $this->linkType, $this->titleName), $html),
|
||||
'Expected title is incorrect or missing!'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(sprintf($this->addToCartSubmitXpath, $relatedProduct->getSku()), $html),
|
||||
'Expected add to cart button is incorrect or missing!'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($this->addToLinksXpath, $html),
|
||||
'Expected add to links is incorrect or missing!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a cross-sell product with required option when block code is generated
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_virtual_with_options.php
|
||||
* @return void
|
||||
*/
|
||||
public function testCrosssellProductWithRequiredOption(): void
|
||||
{
|
||||
$this->linkProducts('simple', ['virtual' => ['position' => 1]]);
|
||||
$this->setCheckoutSessionQuote('test_order_with_simple_product_without_address');
|
||||
$this->prepareBlock();
|
||||
$html = $this->block->toHtml();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath($this->addToCartButtonXpath, $html),
|
||||
'Expected add to cart button is incorrect or missing!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the display of cross-sell products in the block
|
||||
*
|
||||
* @dataProvider displayLinkedProductsProvider
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_list.php
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function testDisplayCrosssellProducts(array $data): void
|
||||
{
|
||||
$this->updateProducts($data['updateProducts']);
|
||||
$this->linkProducts('simple', $this->existingProducts);
|
||||
$items = $this->getBlockItems('test_order_with_simple_product_without_address');
|
||||
|
||||
$this->assertEquals(
|
||||
$data['expectedProductLinks'],
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the position and max count of cross-sell products in the block
|
||||
*
|
||||
* @magentoDataFixture Magento/Checkout/_files/quote_with_simple_product_saved.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_list.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @return void
|
||||
*/
|
||||
public function testPositionCrosssellProducts(): void
|
||||
{
|
||||
$positionData = array_merge_recursive(
|
||||
$this->getPositionData(),
|
||||
[
|
||||
'productLinks' => [
|
||||
'simple-1' => ['position' => 5],
|
||||
'simple2' => ['position' => 4],
|
||||
],
|
||||
'expectedProductLinks' => [
|
||||
'simple2',
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->linkProducts('simple', $positionData['productLinks']);
|
||||
$items = $this->getBlockItems('test_order_with_simple_product_without_address');
|
||||
|
||||
$this->assertCount(
|
||||
self::MAX_ITEM_COUNT,
|
||||
$items,
|
||||
'Expected quantity of cross-sell products do not match the actual quantity!'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$positionData['expectedProductLinks'],
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the position and max count of cross-sell products in the block
|
||||
* when set last added product in checkout session
|
||||
*
|
||||
* @dataProvider positionWithLastAddedProductProvider
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_list.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @param array $positionData
|
||||
* @param array $expectedProductLinks
|
||||
* @return void
|
||||
*/
|
||||
public function testPositionCrosssellProductsWithLastAddedProduct(
|
||||
array $positionData,
|
||||
array $expectedProductLinks
|
||||
): void {
|
||||
foreach ($positionData as $sku => $productLinks) {
|
||||
$this->linkProducts($sku, $productLinks);
|
||||
}
|
||||
$this->checkoutSession->setLastAddedProductId($this->productRepository->get('simple-tableRate-1')->getId());
|
||||
$items = $this->getBlockItems('tableRate');
|
||||
|
||||
$this->assertCount(
|
||||
self::MAX_ITEM_COUNT,
|
||||
$items,
|
||||
'Expected quantity of cross-sell products do not match the actual quantity!'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expectedProductLinks,
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide test data to verify the position of linked products of the last added product.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function positionWithLastAddedProductProvider(): array
|
||||
{
|
||||
return [
|
||||
'less_four_linked_products_to_last_added_product' => [
|
||||
'positionData' => [
|
||||
'simple-tableRate-1' => [
|
||||
'simple-249' => ['position' => 2],
|
||||
'simple-156' => ['position' => 1],
|
||||
],
|
||||
'simple-tableRate-2' => [
|
||||
'simple-1' => ['position' => 2],
|
||||
'simple2' => ['position' => 1],
|
||||
'wrong-simple' => ['position' => 3],
|
||||
],
|
||||
],
|
||||
'expectedProductLinks' => [
|
||||
'simple-156',
|
||||
'simple-249',
|
||||
'simple2',
|
||||
'simple-1',
|
||||
],
|
||||
],
|
||||
'four_linked_products_to_last_added_product' => [
|
||||
'positionData' => [
|
||||
'simple-tableRate-1' => [
|
||||
'wrong-simple' => ['position' => 3],
|
||||
'simple-249' => ['position' => 1],
|
||||
'simple-156' => ['position' => 2],
|
||||
'simple2' => ['position' => 4],
|
||||
],
|
||||
'simple-tableRate-2' => [
|
||||
'simple-1' => ['position' => 1],
|
||||
],
|
||||
],
|
||||
'expectedProductLinks' => [
|
||||
'simple-249',
|
||||
'simple-156',
|
||||
'wrong-simple',
|
||||
'simple2',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the display of cross-sell products in the block on different websites
|
||||
*
|
||||
* @dataProvider multipleWebsitesLinkedProductsProvider
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_with_websites_and_stores.php
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products_list.php
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
public function testMultipleWebsitesCrosssellProducts(array $data): void
|
||||
{
|
||||
$this->updateProducts($this->prepareProductsWebsiteIds());
|
||||
$productLinks = array_merge($this->existingProducts, $data['productLinks']);
|
||||
$this->linkProducts('simple-tableRate-1', $productLinks);
|
||||
$items = $this->executeInStoreContext->execute($data['storeCode'], [$this, 'getBlockItems'], 'tableRate');
|
||||
|
||||
$this->assertEquals(
|
||||
$data['expectedProductLinks'],
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the invisibility of cross-sell products in the block which added to cart
|
||||
*
|
||||
* @magentoDataFixture Magento/Sales/_files/quote_with_multiple_products.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
|
||||
* @return void
|
||||
*/
|
||||
public function testInvisibilityCrosssellProductAddedToCart(): void
|
||||
{
|
||||
$productLinks = [
|
||||
'simple-1' => ['position' => 1],
|
||||
'simple-tableRate-2' => ['position' => 2],
|
||||
];
|
||||
$this->linkProducts('simple-tableRate-1', $productLinks);
|
||||
$items = $this->getBlockItems('tableRate');
|
||||
|
||||
$this->assertEquals(
|
||||
['simple-1'],
|
||||
$this->getActualLinks($items),
|
||||
'Expected cross-sell products do not match actual cross-sell products!'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get products of block when quote in checkout session
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return array
|
||||
*/
|
||||
public function getBlockItems(string $reservedOrderId): array
|
||||
{
|
||||
$this->setCheckoutSessionQuote($reservedOrderId);
|
||||
|
||||
return $this->block->getItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function prepareBlock(): void
|
||||
{
|
||||
parent::prepareBlock();
|
||||
|
||||
$this->block->setViewModel($this->objectManager->get(PreparePostData::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function prepareProductsWebsiteIds(): array
|
||||
{
|
||||
$productsWebsiteIds = parent::prepareProductsWebsiteIds();
|
||||
$simple = $productsWebsiteIds['simple-1'];
|
||||
unset($productsWebsiteIds['simple-1']);
|
||||
|
||||
return array_merge($productsWebsiteIds, ['simple-tableRate-1' => $simple]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set quoteId in checkoutSession object.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return void
|
||||
*/
|
||||
private function setCheckoutSessionQuote(string $reservedOrderId): void
|
||||
{
|
||||
$this->checkoutSession->clearQuote();
|
||||
$quote = $this->objectManager->get(GetQuoteByReservedOrderId::class)->execute($reservedOrderId);
|
||||
if ($quote !== null) {
|
||||
$this->checkoutSession->setQuoteId($quote->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Checkout\Block\Cart;
|
||||
|
||||
/**
|
||||
* Class GridTest
|
||||
* Test to verify default config value for
|
||||
* Store->Configuration->Sales->Checkout->Shopping Cart->Number of items to display pager
|
||||
*/
|
||||
class GridTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetDefaultConfig()
|
||||
{
|
||||
$configValue = 20;
|
||||
/** @var $scopeConfig \Magento\Framework\App\Config\ScopeConfigInterface */
|
||||
$scopeConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\App\Config\ScopeConfigInterface::class
|
||||
);
|
||||
$defaultConfigValue = $scopeConfig->getValue(
|
||||
\Magento\Checkout\Block\Cart\Grid::XPATH_CONFIG_NUMBER_ITEMS_TO_DISPLAY_PAGER,
|
||||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
$errorMessage = 'Default Config value for Store->Configuration->Sales->Checkout->Shopping Cart->'
|
||||
. 'Number of items to display pager shouold be ' . $configValue;
|
||||
$this->assertEquals($configValue, $defaultConfigValue, $errorMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Block\Cart\Item;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Quote\Api\CartRepositoryInterface;
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\Quote\Model\Quote\Item;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* Class RendererTest
|
||||
* @package Magento\Checkout\Block\Cart\Item
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class RendererTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $renderer;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $productRepository;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->renderer = $this->objectManager->get(Renderer::class);
|
||||
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets quote by reserved order id.
|
||||
*
|
||||
* @param string $reservedOrderId
|
||||
* @return Quote
|
||||
*/
|
||||
private function getQuote($reservedOrderId)
|
||||
{
|
||||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
|
||||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class);
|
||||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId)
|
||||
->create();
|
||||
|
||||
/** @var CartRepositoryInterface $quoteRepository */
|
||||
$quoteRepository = $this->objectManager->get(CartRepositoryInterface::class);
|
||||
|
||||
/** @var Quote[] $items */
|
||||
$items = $quoteRepository->getList($searchCriteria)->getItems();
|
||||
|
||||
return $items[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets \Magento\Quote\Model\Quote\Item from \Magento\Quote\Model\Quote by product id
|
||||
*
|
||||
* @param Quote $quote
|
||||
* @param string|int $productId
|
||||
*
|
||||
* @return Item|null
|
||||
*/
|
||||
private function _getQuoteItemIdByProductId($quote, $productId)
|
||||
{
|
||||
/** @var $quoteItems Item[] */
|
||||
$quoteItems = $quote->getAllItems();
|
||||
foreach ($quoteItems as $quoteItem) {
|
||||
if ($productId == $quoteItem->getProductId()) {
|
||||
return $quoteItem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Checkout/_files/cart_with_simple_product_and_custom_option_text_area.php
|
||||
*/
|
||||
public function testTextAreaCustomOption()
|
||||
{
|
||||
$quote = $this->getQuote('test_order_item_with_custom_option_text_area');
|
||||
|
||||
/** @var $product Product */
|
||||
$product = $this->productRepository->get('simple_with_custom_option_text_area');
|
||||
|
||||
$quoteItem = $this->_getQuoteItemIdByProductId($quote, $product->getId());
|
||||
$this->assertNotNull($quoteItem, 'Cannot get quote item for simple product with custom option text area');
|
||||
|
||||
$template = 'Magento_Checkout::cart/item/default.phtml';
|
||||
$this->renderer->setTemplate($template);
|
||||
$this->renderer->setItem($quoteItem);
|
||||
|
||||
$priceBlock = $this->objectManager->create(\Magento\Checkout\Block\Item\Price\Renderer::class);
|
||||
$this->renderer->getLayout()->setBlock('checkout.item.price.unit', $priceBlock);
|
||||
$this->renderer->getLayout()->setBlock('checkout.item.price.row', $priceBlock);
|
||||
$html = $this->renderer->toHtml();
|
||||
|
||||
$this->assertMatchesRegularExpression(<<<EOT
|
||||
/Test product simple with
|
||||
custom option text area
|
||||
with more 50 characters/
|
||||
EOT
|
||||
, $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Checkout\Block\Cart
|
||||
*/
|
||||
namespace Magento\Checkout\Block;
|
||||
|
||||
class CartTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetMethods()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
$child = $layout->createBlock(
|
||||
\Magento\Framework\View\Element\Text::class
|
||||
)->setChild(
|
||||
'child1',
|
||||
$layout->createBlock(
|
||||
\Magento\Framework\View\Element\Text::class,
|
||||
'method1'
|
||||
)
|
||||
)->setChild(
|
||||
'child2',
|
||||
$layout->createBlock(
|
||||
\Magento\Framework\View\Element\Text::class,
|
||||
'method2'
|
||||
)
|
||||
);
|
||||
/** @var $block \Magento\Checkout\Block\Cart */
|
||||
$block = $layout->createBlock(\Magento\Checkout\Block\Cart::class)->setChild('child', $child);
|
||||
$methods = $block->getMethods('child');
|
||||
$this->assertEquals(['method1', 'method2'], $methods);
|
||||
}
|
||||
|
||||
public function testGetMethodsEmptyChild()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
$childEmpty = $layout->createBlock(\Magento\Framework\View\Element\Text::class);
|
||||
/** @var $block \Magento\Checkout\Block\Cart */
|
||||
$block = $layout->createBlock(\Magento\Checkout\Block\Cart::class)->setChild('child', $childEmpty);
|
||||
$methods = $block->getMethods('child');
|
||||
$this->assertEquals([], $methods);
|
||||
}
|
||||
|
||||
public function testGetMethodsNoChild()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Checkout\Block\Cart */
|
||||
$block = $layout->createBlock(\Magento\Checkout\Block\Cart::class);
|
||||
$methods = $block->getMethods('child');
|
||||
$this->assertEquals([], $methods);
|
||||
}
|
||||
|
||||
public function testGetPagerHtml()
|
||||
{
|
||||
/** @var $layout \Magento\Framework\View\Layout */
|
||||
$layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
);
|
||||
/** @var $block \Magento\Checkout\Block\Cart */
|
||||
$block = $layout->createBlock(\Magento\Checkout\Block\Cart::class);
|
||||
$pager = $block->getPagerHtml();
|
||||
$this->assertEquals('', $pager);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Checkout\Block\Checkout;
|
||||
|
||||
use Magento\Framework\App\Config\MutableScopeConfigInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LayoutProcessorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Tests default country for shipping address.
|
||||
*
|
||||
* @param string $defaultCountryId
|
||||
* @param bool $isCountryValueExpected
|
||||
* @magentoConfigFixture default_store checkout/options/display_billing_address_on 1
|
||||
* @magentoDataFixture Magento/Backend/_files/allowed_countries_fr.php
|
||||
* @dataProvider defaultCountryDataProvider
|
||||
*/
|
||||
public function testShippingAddressCountryId(string $defaultCountryId, bool $isCountryValueExpected): void
|
||||
{
|
||||
/** @var MutableScopeConfigInterface $mutableConfig */
|
||||
$mutableConfig = Bootstrap::getObjectManager()->get(MutableScopeConfigInterface::class);
|
||||
$mutableConfig->setValue('general/country/default', $defaultCountryId, ScopeInterface::SCOPE_STORE, 'default');
|
||||
|
||||
/** @var $layoutProcessor LayoutProcessor */
|
||||
$layoutProcessor = Bootstrap::getObjectManager()->get(LayoutProcessor::class);
|
||||
|
||||
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
|
||||
['children']['shippingAddress']['children']['shipping-address-fieldset']['children'] = [];
|
||||
$data = $layoutProcessor->process($jsLayout);
|
||||
|
||||
$countryId = $data["components"]["checkout"]["children"]["steps"]["children"]["shipping-step"]["children"]
|
||||
["shippingAddress"]["children"]["shipping-address-fieldset"]["children"]["country_id"];
|
||||
|
||||
$isCountryValueExists = array_key_exists('value', $countryId);
|
||||
|
||||
$this->assertEquals($isCountryValueExpected, $isCountryValueExists);
|
||||
if ($isCountryValueExpected) {
|
||||
$this->assertEquals($defaultCountryId, $countryId['value']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function defaultCountryDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'Default country isn\'t in allowed country list' => [
|
||||
'defaultCountryId' => 'US',
|
||||
'isCountryValueExpected' => false
|
||||
],
|
||||
'Default country is in allowed country list' => [
|
||||
'defaultCountryId' => 'FR',
|
||||
'isCountryValueExpected' => true
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user