Skip to content

Commit 1af376b

Browse files
committed
MC-31757: Wishlist configurations enabled/disabled
1 parent 2d46d98 commit 1af376b

File tree

9 files changed

+632
-6
lines changed

9 files changed

+632
-6
lines changed

dev/tests/integration/testsuite/Magento/Customer/Controller/Section/LoadTest.php

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,104 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Customer\Controller\Section;
89

9-
class LoadTest extends \Magento\TestFramework\TestCase\AbstractController
10+
use Magento\Customer\Model\Session;
11+
use Magento\Framework\App\Request\Http as HttpRequest;
12+
use Magento\Framework\Serialize\SerializerInterface;
13+
use Magento\TestFramework\TestCase\AbstractController;
14+
use Magento\Framework\Escaper;
15+
16+
/**
17+
* Load customer data test class.
18+
*
19+
* @magentoDbIsolation enabled
20+
* @magentoAppArea frontend
21+
*/
22+
class LoadTest extends AbstractController
1023
{
11-
public function testLoadInvalidSection()
24+
/** @var Session */
25+
private $customerSession;
26+
27+
/** @var SerializerInterface */
28+
private $json;
29+
30+
/** @var Escaper */
31+
private $escaper;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp()
37+
{
38+
parent::setUp();
39+
40+
$this->customerSession = $this->_objectManager->get(Session::class);
41+
$this->json = $this->_objectManager->get(SerializerInterface::class);
42+
$this->escaper = $this->_objectManager->get(Escaper::class);
43+
}
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
protected function tearDown()
49+
{
50+
$this->customerSession->setCustomerId(null);
51+
52+
parent::tearDown();
53+
}
54+
55+
/**
56+
* @return void
57+
*/
58+
public function testLoadInvalidSection(): void
1259
{
13-
$expected = [
14-
'message' => 'The "section<invalid" section source isn't supported.',
15-
];
60+
$message = $this->escaper->escapeHtml('The "section<invalid" section source isn\'t supported.');
61+
$expected = ['message' => $message];
1662
$this->dispatch(
1763
'/customer/section/load/?sections=section<invalid&force_new_section_timestamp=false&_=147066166394'
1864
);
19-
self::assertEquals(json_encode($expected), $this->getResponse()->getBody());
65+
$this->assertEquals($this->json->serialize($expected), $this->getResponse()->getBody());
66+
}
67+
68+
/**
69+
* @magentoConfigFixture current_store wishlist/wishlist_link/use_qty 1
70+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_three.php
71+
*
72+
* @return void
73+
*/
74+
public function testWishListCounterUseQty(): void
75+
{
76+
$this->customerSession->setCustomerId(1);
77+
$response = $this->performWishListSectionRequest();
78+
$this->assertEquals('3 items', $response['wishlist']['counter']);
79+
}
80+
81+
/**
82+
* @magentoConfigFixture current_store wishlist/wishlist_link/use_qty 0
83+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_three.php
84+
*
85+
* @return void
86+
*/
87+
public function testWishListCounterNotUseQty(): void
88+
{
89+
$this->customerSession->setCustomerId(1);
90+
$response = $this->performWishListSectionRequest();
91+
$this->assertEquals('1 item', $response['wishlist']['counter']);
92+
}
93+
94+
/**
95+
* Perform wish list section request.
96+
*
97+
* @return array
98+
*/
99+
private function performWishListSectionRequest(): array
100+
{
101+
$this->getRequest()->setParam('sections', 'wishlist')->setMethod(HttpRequest::METHOD_GET);
102+
$this->dispatch('customer/section/load');
103+
104+
return $this->json->unserialize($this->getResponse()->getBody());
20105
}
21106
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Block\Account;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\View\Result\Page;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Checks My Wish List link displaying in account dashboard
17+
*
18+
* @magentoAppArea frontend
19+
* @magentoDbIsolation enabled
20+
* @magentoAppIsolation enabled
21+
*/
22+
class LinkTest extends TestCase
23+
{
24+
/** @var ObjectManagerInterface */
25+
private $objectManager;
26+
27+
/** @var Page */
28+
private $page;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
protected function setUp()
34+
{
35+
parent::setUp();
36+
37+
$this->objectManager = Bootstrap::getObjectManager();
38+
$this->page = $this->objectManager->create(Page::class);
39+
}
40+
41+
/**
42+
* @return void
43+
*/
44+
public function testNewsletterLink(): void
45+
{
46+
$this->preparePage();
47+
$block = $this->page->getLayout()->getBlock('customer-account-navigation-wish-list-link');
48+
$this->assertNotFalse($block);
49+
$html = $block->toHtml();
50+
$this->assertContains('wishlist/', $html);
51+
$this->assertEquals('My Wish List', strip_tags($html));
52+
}
53+
54+
/**
55+
* @magentoConfigFixture current_store wishlist/general/active 0
56+
*
57+
* @return void
58+
*/
59+
public function testNewsletterLinkDisabled(): void
60+
{
61+
$this->preparePage();
62+
$block = $this->page->getLayout()->getBlock('customer-account-navigation-wish-list-link');
63+
$this->assertFalse($block);
64+
}
65+
66+
/**
67+
* Prepare page before render
68+
*
69+
* @return void
70+
*/
71+
private function preparePage(): void
72+
{
73+
$this->page->addHandle([
74+
'default',
75+
'customer_account',
76+
]);
77+
$this->page->getLayout()->generateXml();
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Block\Catalog\Product\ProductList\Item\AddTo;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Checks add to wishlist button on category page.
18+
*
19+
* @magentoAppArea frontend
20+
* @magentoDbIsolation enabled
21+
* @magentoAppIsolation disabled
22+
*/
23+
class WishlistTest extends TestCase
24+
{
25+
/** @var ObjectManagerInterface */
26+
private $objectManager;
27+
28+
/** @var Wishlist */
29+
private $block;
30+
31+
/** @var ProductRepositoryInterface */
32+
private $productRepository;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp()
38+
{
39+
$this->objectManager = Bootstrap::getObjectManager();
40+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
41+
$this->productRepository->cleanCache();
42+
$this->block = $this->objectManager->get(LayoutInterface::class)
43+
->createBlock(Wishlist::class)->setTemplate('Magento_Wishlist::catalog/product/list/addto/wishlist.phtml');
44+
}
45+
46+
/**
47+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
48+
*
49+
* @return void
50+
*/
51+
public function testAddToWishListVisible(): void
52+
{
53+
$product = $this->productRepository->get('simple2');
54+
$html = $this->block->setProduct($product)->toHtml();
55+
$this->assertEquals('Add to Wish List', trim(strip_tags($html)));
56+
}
57+
58+
/**
59+
* @magentoConfigFixture current_store wishlist/general/active 0
60+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
61+
*
62+
* @return void
63+
*/
64+
public function testAddToWishListNotVisible(): void
65+
{
66+
$product = $this->productRepository->get('simple2');
67+
$this->assertEmpty($this->block->setProduct($product)->toHtml());
68+
}
69+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Wishlist\Block\Catalog\Product\View\AddTo;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Framework\Registry;
14+
use Magento\Framework\View\LayoutInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\TestFramework\Helper\Xpath;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* Checks add to wishlist button on product page.
21+
*
22+
* @magentoAppArea frontend
23+
* @magentoDbIsolation enabled
24+
* @magentoAppIsolation disabled
25+
*/
26+
class WishlistTest extends TestCase
27+
{
28+
private const ADD_TO_WISHLIST_XPATH = "//a[@data-action='add-to-wishlist']"
29+
. "/span[contains(text(), 'Add to Wish List')]";
30+
31+
/** @var ObjectManagerInterface */
32+
private $objectManager;
33+
34+
/** @var Registry */
35+
private $registry;
36+
37+
/** @var Wishlist */
38+
private $block;
39+
40+
/** @var ProductRepositoryInterface */
41+
private $productRepository;
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
protected function setUp()
47+
{
48+
$this->objectManager = Bootstrap::getObjectManager();
49+
$this->registry = $this->objectManager->get(Registry::class);
50+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
51+
$this->productRepository->cleanCache();
52+
$this->block = $this->objectManager->get(LayoutInterface::class)
53+
->createBlock(Wishlist::class)->setTemplate('Magento_Wishlist::catalog/product/view/addto/wishlist.phtml');
54+
}
55+
56+
/**
57+
* @inheritdoc
58+
*/
59+
protected function tearDown()
60+
{
61+
$this->registry->unregister('product');
62+
63+
parent::tearDown();
64+
}
65+
66+
/**
67+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
68+
*
69+
* @return void
70+
*/
71+
public function testAddToWishListVisible(): void
72+
{
73+
$product = $this->productRepository->get('simple2');
74+
$this->registerProduct($product);
75+
$this->assertEquals(
76+
1,
77+
Xpath::getElementsCountForXpath(self::ADD_TO_WISHLIST_XPATH, $this->block->toHtml())
78+
);
79+
}
80+
81+
/**
82+
* @magentoConfigFixture current_store wishlist/general/active 0
83+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
84+
*
85+
* @return void
86+
*/
87+
public function testAddToWishListNotVisible(): void
88+
{
89+
$product = $this->productRepository->get('simple2');
90+
$this->registerProduct($product);
91+
$this->assertEquals(
92+
0,
93+
Xpath::getElementsCountForXpath(self::ADD_TO_WISHLIST_XPATH, $this->block->toHtml())
94+
);
95+
}
96+
97+
/**
98+
* Register the product.
99+
*
100+
* @param ProductInterface $product
101+
* @return void
102+
*/
103+
private function registerProduct(ProductInterface $product): void
104+
{
105+
$this->registry->unregister('product');
106+
$this->registry->register('product', $product);
107+
}
108+
}

0 commit comments

Comments
 (0)