Skip to content

Commit d2ceb87

Browse files
committed
Merge branch 'MC-36914' into 2.4-develop-com-pr16
2 parents 30cd67d + 33ffe08 commit d2ceb87

File tree

3 files changed

+353
-0
lines changed

3 files changed

+353
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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\Review\Block\Account;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\View\Result\Page;
12+
use Magento\Framework\View\Result\PageFactory;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Checks "My Product Reviews" link displaying in customer account dashboard
18+
*
19+
* @magentoAppArea frontend
20+
* @magentoDbIsolation enabled
21+
* @magentoAppIsolation enabled
22+
*/
23+
class LinkTest extends TestCase
24+
{
25+
/** @var ObjectManagerInterface */
26+
private $objectManager;
27+
28+
/** @var Page */
29+
private $page;
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
protected function setUp(): void
35+
{
36+
parent::setUp();
37+
38+
$this->objectManager = Bootstrap::getObjectManager();
39+
$this->page = $this->objectManager->get(PageFactory::class)->create();
40+
}
41+
42+
/**
43+
* @return void
44+
*/
45+
public function testMyProductReviewsLink(): void
46+
{
47+
$this->preparePage();
48+
$block = $this->page->getLayout()->getBlock('customer-account-navigation-product-reviews-link');
49+
$this->assertNotFalse($block);
50+
$html = $block->toHtml();
51+
$this->assertStringContainsString('/review/customer/', $html);
52+
$this->assertEquals((string)__('My Product Reviews'), strip_tags($html));
53+
}
54+
55+
/**
56+
* @magentoConfigFixture current_store catalog/review/active 0
57+
*
58+
* @return void
59+
*/
60+
public function testMyProductReviewsLinkDisabled(): void
61+
{
62+
$this->preparePage();
63+
$block = $this->page->getLayout()->getBlock('customer-account-navigation-product-reviews-link');
64+
$this->assertFalse($block);
65+
}
66+
67+
/**
68+
* Prepare page before render
69+
*
70+
* @return void
71+
*/
72+
private function preparePage(): void
73+
{
74+
$this->page->addHandle([
75+
'default',
76+
'customer_account',
77+
]);
78+
$this->page->getLayout()->generateXml();
79+
}
80+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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\Review\Block\Customer;
9+
10+
use Magento\Customer\Model\Session;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\Helper\Xpath;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Test for customer product reviews grid.
20+
*
21+
* @see \Magento\Review\Block\Customer\ListCustomer
22+
* @magentoAppArea frontend
23+
* @magentoDbIsolation enabled
24+
*/
25+
class ListCustomerTest extends TestCase
26+
{
27+
/** @var ObjectManagerInterface */
28+
private $objectManager;
29+
30+
/** @var Session */
31+
private $customerSession;
32+
33+
/** @var ListCustomer */
34+
private $block;
35+
36+
/** @var CollectionFactory */
37+
private $collectionFactory;
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
protected function setUp(): void
43+
{
44+
parent::setUp();
45+
46+
$this->objectManager = Bootstrap::getObjectManager();
47+
$this->customerSession = $this->objectManager->get(Session::class);
48+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(ListCustomer::class)
49+
->setTemplate('Magento_Review::customer/list.phtml');
50+
$this->collectionFactory = $this->objectManager->get(CollectionFactory::class);
51+
}
52+
53+
/**
54+
* @inheritdoc
55+
*/
56+
protected function tearDown(): void
57+
{
58+
$this->customerSession->setCustomerId(null);
59+
60+
parent::tearDown();
61+
}
62+
63+
/**
64+
* @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
65+
*
66+
* @return void
67+
*/
68+
public function testCustomerProductReviewsGrid(): void
69+
{
70+
$this->customerSession->setCustomerId(1);
71+
$review = $this->collectionFactory->create()->addCustomerFilter(1)->addReviewSummary()->getFirstItem();
72+
$this->assertNotNull($review->getReviewId());
73+
$blockHtml = $this->block->toHtml();
74+
$createdDate = $this->block->dateFormat($review->getReviewCreatedAt());
75+
$this->assertEquals(
76+
1,
77+
Xpath::getElementsCountForXpath(
78+
sprintf("//td[contains(@class, 'date') and contains(text(), '%s')]", $createdDate),
79+
$blockHtml
80+
),
81+
sprintf('Created date wasn\'t found or not equals to %s.', $createdDate)
82+
);
83+
$this->assertEquals(
84+
1,
85+
Xpath::getElementsCountForXpath(
86+
sprintf("//td[contains(@class, 'item')]//a[contains(text(), '%s')]", $review->getName()),
87+
$blockHtml
88+
),
89+
'Product name wasn\'t found.'
90+
);
91+
$rating = $review->getSum() / $review->getCount();
92+
$this->assertEquals(
93+
1,
94+
Xpath::getElementsCountForXpath(
95+
sprintf("//td[contains(@class, 'summary')]//span[contains(text(), '%s%%')]", $rating),
96+
$blockHtml
97+
),
98+
sprintf('Rating wasn\'t found or not equals to %s%%.', $rating)
99+
);
100+
$this->assertEquals(
101+
1,
102+
Xpath::getElementsCountForXpath(
103+
sprintf("//td[contains(@class, 'description') and contains(text(), '%s')]", $review->getDetail()),
104+
$blockHtml
105+
),
106+
'Review description wasn\'t found.'
107+
);
108+
$this->assertEquals(
109+
1,
110+
Xpath::getElementsCountForXpath(
111+
sprintf(
112+
"//td[contains(@class, 'actions')]//a[contains(@href, '%s')]/span[contains(text(), '%s')]",
113+
$this->block->getReviewUrl($review),
114+
__('See Details')
115+
),
116+
$blockHtml
117+
),
118+
sprintf('%s button wasn\'t found.', __('See Details'))
119+
);
120+
}
121+
122+
/**
123+
* @magentoDataFixture Magento/Customer/_files/customer.php
124+
*
125+
* @return void
126+
*/
127+
public function testCustomerWithoutReviews(): void
128+
{
129+
$this->customerSession->setCustomerId(1);
130+
$this->assertStringContainsString(
131+
(string)__('You have submitted no reviews.'),
132+
strip_tags($this->block->toHtml())
133+
);
134+
}
135+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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\Review\Block\Customer;
9+
10+
use Magento\Customer\Model\Session;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\Helper\Xpath;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Test for displaying customer product review block.
20+
*
21+
* @see \Magento\Review\Block\Customer\View
22+
* @magentoAppArea frontend
23+
* @magentoDbIsolation enabled
24+
*/
25+
class ViewTest extends TestCase
26+
{
27+
/** @var ObjectManagerInterface */
28+
private $objectManager;
29+
30+
/** @var Session */
31+
private $customerSession;
32+
33+
/** @var CollectionFactory */
34+
private $collectionFactory;
35+
36+
/** @var View */
37+
private $block;
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
protected function setUp(): void
43+
{
44+
parent::setUp();
45+
46+
$this->objectManager = Bootstrap::getObjectManager();
47+
$this->customerSession = $this->objectManager->get(Session::class);
48+
$this->collectionFactory = $this->objectManager->get(CollectionFactory::class);
49+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(View::class);
50+
}
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
protected function tearDown(): void
56+
{
57+
$this->customerSession->setCustomerId(null);
58+
59+
parent::tearDown();
60+
}
61+
62+
/**
63+
* @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
64+
*
65+
* @return void
66+
*/
67+
public function testCustomerProductReviewBlock(): void
68+
{
69+
$this->customerSession->setCustomerId(1);
70+
$review = $this->collectionFactory->create()->addCustomerFilter(1)->getFirstItem();
71+
$this->assertNotNull($review->getReviewId());
72+
$blockHtml = $this->block->setReviewId($review->getReviewId())->toHtml();
73+
$this->assertEquals(
74+
1,
75+
Xpath::getElementsCountForXpath(
76+
sprintf("//div[contains(@class, 'product-info')]/h2[contains(text(), '%s')]", $review->getName()),
77+
$blockHtml
78+
),
79+
'Product name wasn\'t found.'
80+
);
81+
$ratings = $this->block->getRating();
82+
$this->assertCount(2, $ratings);
83+
foreach ($ratings as $rating) {
84+
$this->assertEquals(
85+
1,
86+
Xpath::getElementsCountForXpath(
87+
sprintf(
88+
"//div[contains(@class, 'rating-summary')]//span[contains(text(), '%s')]"
89+
. "/../..//span[contains(text(), '%s%%')]",
90+
$rating->getRatingCode(),
91+
$rating->getPercent()
92+
),
93+
$blockHtml
94+
),
95+
sprintf('Rating %s was not found or not equals to %s.', $rating->getRatingCode(), $rating->getPercent())
96+
);
97+
}
98+
$this->assertEquals(
99+
1,
100+
Xpath::getElementsCountForXpath(
101+
sprintf("//div[contains(@class, 'review-title') and contains(text(), '%s')]", $review->getTitle()),
102+
$blockHtml
103+
),
104+
'Review title wasn\'t found.'
105+
);
106+
$this->assertEquals(
107+
1,
108+
Xpath::getElementsCountForXpath(
109+
sprintf("//div[contains(@class, 'review-content') and contains(text(), '%s')]", $review->getDetail()),
110+
$blockHtml
111+
),
112+
'Review description wasn\'t found.'
113+
);
114+
$this->assertEquals(
115+
1,
116+
Xpath::getElementsCountForXpath(
117+
sprintf(
118+
"//div[contains(@class, 'review-date') and contains(text(), '%s')]/time[contains(text(), '%s')]",
119+
__('Submitted on'),
120+
$this->block->dateFormat($review->getCreatedAt())
121+
),
122+
$blockHtml
123+
),
124+
'Created date wasn\'t found.'
125+
);
126+
$this->assertEquals(
127+
1,
128+
Xpath::getElementsCountForXpath(
129+
sprintf(
130+
"//a[contains(@href, '/review/customer/')]/span[contains(text(), '%s')]",
131+
__('Back to My Reviews')
132+
),
133+
$blockHtml
134+
),
135+
sprintf('%s button wasn\'t found.', __('Back to My Reviews'))
136+
);
137+
}
138+
}

0 commit comments

Comments
 (0)