Skip to content

Commit 9ed9f0c

Browse files
committed
MC-31251: Wishlist configurations enabled/disabled
1 parent b7a3f9a commit 9ed9f0c

File tree

9 files changed

+615
-3
lines changed

9 files changed

+615
-3
lines changed

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

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,100 @@
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+
15+
/**
16+
* Load customer data test class.
17+
*
18+
* @magentoDbIsolation enabled
19+
* @magentoAppArea frontend
20+
*/
21+
class LoadTest extends AbstractController
1022
{
11-
public function testLoadInvalidSection()
23+
/** @var Session */
24+
private $customerSession;
25+
26+
/** @var SerializerInterface */
27+
private $json;
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
protected function setUp()
33+
{
34+
parent::setUp();
35+
36+
$this->customerSession = $this->_objectManager->get(Session::class);
37+
$this->json = $this->_objectManager->get(SerializerInterface::class);
38+
}
39+
40+
/**
41+
* @inheritdoc
42+
*/
43+
protected function tearDown()
44+
{
45+
$this->customerSession->setCustomerId(null);
46+
47+
parent::tearDown();
48+
}
49+
50+
/**
51+
* @return void
52+
*/
53+
public function testLoadInvalidSection(): void
1254
{
1355
$expected = [
1456
'message' => 'The "section<invalid" section source isn't supported.',
1557
];
1658
$this->dispatch(
1759
'/customer/section/load/?sections=section<invalid&force_new_section_timestamp=false&_=147066166394'
1860
);
19-
self::assertEquals(json_encode($expected), $this->getResponse()->getBody());
61+
$this->assertEquals($this->json->serialize($expected), $this->getResponse()->getBody());
62+
}
63+
64+
/**
65+
* @magentoConfigFixture current_store wishlist/wishlist_link/use_qty 1
66+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_three.php
67+
*
68+
* @return void
69+
*/
70+
public function testWishListCounterUseQty(): void
71+
{
72+
$this->customerSession->setCustomerId(1);
73+
$response = $this->performWishListSectionRequest();
74+
$this->assertEquals('3 items', $response['wishlist']['counter']);
75+
}
76+
77+
/**
78+
* @magentoConfigFixture current_store wishlist/wishlist_link/use_qty 0
79+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_product_qty_three.php
80+
*
81+
* @return void
82+
*/
83+
public function testWishListCounterNotUseQty(): void
84+
{
85+
$this->customerSession->setCustomerId(1);
86+
$response = $this->performWishListSectionRequest();
87+
$this->assertEquals('1 item', $response['wishlist']['counter']);
88+
}
89+
90+
/**
91+
* Perform wish list section request.
92+
*
93+
* @return array
94+
*/
95+
private function performWishListSectionRequest(): array
96+
{
97+
$this->getRequest()->setParam('sections', 'wishlist')->setMethod(HttpRequest::METHOD_GET);
98+
$this->dispatch('customer/section/load');
99+
100+
return $this->json->unserialize($this->getResponse()->getBody());
20101
}
21102
}
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,68 @@
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+
* Test button add to wish list link 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+
->addBlock(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+
$this->assertContains('Add to Wish List', strip_tags($this->block->setProduct($product)->toHtml()));
55+
}
56+
57+
/**
58+
* @magentoConfigFixture current_store wishlist/general/active 0
59+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
60+
*
61+
* @return void
62+
*/
63+
public function testAddToWishListNotVisible(): void
64+
{
65+
$product = $this->productRepository->get('simple2');
66+
$this->assertEmpty($this->block->setProduct($product)->toHtml());
67+
}
68+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Test button add to wish list link on product page.
20+
*
21+
* @magentoAppArea frontend
22+
* @magentoDbIsolation enabled
23+
* @magentoAppIsolation disabled
24+
*/
25+
class WishlistTest extends TestCase
26+
{
27+
/** @var ObjectManagerInterface */
28+
private $objectManager;
29+
30+
/** @var Registry */
31+
private $registry;
32+
33+
/** @var Wishlist */
34+
private $block;
35+
36+
/** @var ProductRepositoryInterface */
37+
private $productRepository;
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
protected function setUp()
43+
{
44+
$this->objectManager = Bootstrap::getObjectManager();
45+
$this->registry = $this->objectManager->get(Registry::class);
46+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
47+
$this->productRepository->cleanCache();
48+
$this->block = $this->objectManager->get(LayoutInterface::class)
49+
->addBlock(Wishlist::class)->setTemplate('Magento_Wishlist::catalog/product/view/addto/wishlist.phtml');
50+
}
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
protected function tearDown()
56+
{
57+
$this->registry->unregister('product');
58+
59+
parent::tearDown();
60+
}
61+
62+
/**
63+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
64+
*
65+
* @return void
66+
*/
67+
public function testAddToWishListVisible(): void
68+
{
69+
$product = $this->productRepository->get('simple2');
70+
$this->registerProduct($product);
71+
$this->assertContains('Add to Wish List', strip_tags($this->block->toHtml()));
72+
}
73+
74+
/**
75+
* @magentoConfigFixture current_store wishlist/general/active 0
76+
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
77+
*
78+
* @return void
79+
*/
80+
public function testAddToWishListNotVisible(): void
81+
{
82+
$product = $this->productRepository->get('simple2');
83+
$this->registerProduct($product);
84+
$this->assertNotContains('Add to Wish List', strip_tags($this->block->toHtml()));
85+
}
86+
87+
/**
88+
* Register the product.
89+
*
90+
* @param ProductInterface $product
91+
* @return void
92+
*/
93+
private function registerProduct(ProductInterface $product): void
94+
{
95+
$this->registry->unregister('product');
96+
$this->registry->register('product', $product);
97+
}
98+
}

0 commit comments

Comments
 (0)