init
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Block\Account;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\Result\Page;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Checks "My Product Reviews" link displaying in customer account dashboard
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
class LinkTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Page */
|
||||
private $page;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->page = $this->objectManager->get(PageFactory::class)->create();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testMyProductReviewsLink(): void
|
||||
{
|
||||
$this->preparePage();
|
||||
$block = $this->page->getLayout()->getBlock('customer-account-navigation-product-reviews-link');
|
||||
$this->assertNotFalse($block);
|
||||
$html = $block->toHtml();
|
||||
$this->assertStringContainsString('/review/customer/', $html);
|
||||
$this->assertEquals((string)__('My Product Reviews'), strip_tags($html));
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store catalog/review/active 0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testMyProductReviewsLinkDisabled(): void
|
||||
{
|
||||
$this->preparePage();
|
||||
$block = $this->page->getLayout()->getBlock('customer-account-navigation-product-reviews-link');
|
||||
$this->assertFalse($block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare page before render
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function preparePage(): void
|
||||
{
|
||||
$this->page->addHandle([
|
||||
'default',
|
||||
'customer_account',
|
||||
]);
|
||||
$this->page->getLayout()->generateXml();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Review\Block\Adminhtml\Edit;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review.php
|
||||
*/
|
||||
public function testCustomerOnForm()
|
||||
{
|
||||
/** @var Customer $customer */
|
||||
$customer = Bootstrap::getObjectManager()->create(Customer::class)
|
||||
->setWebsiteId(1)
|
||||
->loadByEmail('customer@example.com');
|
||||
$block = Bootstrap::getObjectManager()->create(Form::class);
|
||||
$block->setNameInLayout('test_block_name');
|
||||
/** @var Escaper $escaper */
|
||||
$escaper = Bootstrap::getObjectManager()->get(Escaper::class);
|
||||
$this->assertStringMatchesFormat(
|
||||
'%A' . __(
|
||||
'<a href="%1" onclick="this.target=\'blank\'">%2 %3</a> <a href="mailto:%4">(%4)</a>',
|
||||
'%A',
|
||||
$escaper->escapeHtml($customer->getFirstname()),
|
||||
$escaper->escapeHtml($customer->getLastname()),
|
||||
$escaper->escapeHtml($customer->getEmail())
|
||||
) . '%A',
|
||||
$block->toHtml()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify review form hidden input will contain all review stores.
|
||||
*
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review.php
|
||||
* @return void
|
||||
*/
|
||||
public function testStoresOnForm(): void
|
||||
{
|
||||
$registry = Bootstrap::getObjectManager()->get(Registry::class);
|
||||
$review = $registry->registry('review_data');
|
||||
$block = Bootstrap::getObjectManager()->create(Form::class);
|
||||
$block->setNameInLayout('test_block_name');
|
||||
foreach ($review->getStores() as $storeId) {
|
||||
$regex = sprintf('/input id="select_stores" (.*) value="%d" type="hidden"/', $storeId);
|
||||
$this->assertMatchesRegularExpression(
|
||||
$regex,
|
||||
$block->toHtml()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
\Magento\Review\Block\Adminhtml\Rating\Edit\Tab\Form::class,
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\Review\Block\Adminhtml\Rating\Edit\Tab\Form::class
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Checks customer products reviews tab
|
||||
*
|
||||
* @see \Magento\Review\Block\Adminhtml\Edit\Tab\Reviews
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ReviewsTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Reviews */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Reviews::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReviewGrid(): void
|
||||
{
|
||||
$this->block->setCustomerId(1);
|
||||
$this->assertCount(1, $this->block->getPreparedCollection());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Review\Block\Adminhtml;
|
||||
|
||||
class MainTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var \Magento\Customer\Api\AccountManagementInterface $accountManagement */
|
||||
$accountManagement = $objectManager->create(\Magento\Customer\Api\AccountManagementInterface::class);
|
||||
|
||||
/** @var \Magento\Customer\Helper\View $customerViewHelper */
|
||||
$customerViewHelper = $objectManager->create(\Magento\Customer\Helper\View::class);
|
||||
|
||||
$customer = $accountManagement->authenticate('customer@example.com', 'password');
|
||||
$request = $objectManager->get(\Magento\Framework\App\RequestInterface::class);
|
||||
$request->setParam('customerId', $customer->getId());
|
||||
/** @var \Magento\Framework\View\LayoutInterface $layout */
|
||||
$layout = $objectManager->get(\Magento\Framework\View\LayoutInterface::class);
|
||||
$block = $layout->createBlock(\Magento\Review\Block\Adminhtml\Main::class);
|
||||
$customerName = $customerViewHelper->getCustomerName($customer);
|
||||
/** @var \Magento\Framework\Escaper $escaper */
|
||||
$escaper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\Escaper::class);
|
||||
$this->assertStringMatchesFormat(
|
||||
'%A' . __('All Reviews of Customer `%1`', $escaper->escapeHtml($customerName)) . '%A',
|
||||
$block->getHeaderHtml()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Block\Customer;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for customer product reviews grid.
|
||||
*
|
||||
* @see \Magento\Review\Block\Customer\ListCustomer
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class ListCustomerTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Session */
|
||||
private $customerSession;
|
||||
|
||||
/** @var ListCustomer */
|
||||
private $block;
|
||||
|
||||
/** @var CollectionFactory */
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->customerSession = $this->objectManager->get(Session::class);
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(ListCustomer::class)
|
||||
->setTemplate('Magento_Review::customer/list.phtml');
|
||||
$this->collectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->customerSession->setCustomerId(null);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCustomerProductReviewsGrid(): void
|
||||
{
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$review = $this->collectionFactory->create()->addCustomerFilter(1)->addReviewSummary()->getFirstItem();
|
||||
$this->assertNotNull($review->getReviewId());
|
||||
$blockHtml = $this->block->toHtml();
|
||||
$createdDate = $this->block->dateFormat($review->getReviewCreatedAt());
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf("//td[contains(@class, 'date') and contains(text(), '%s')]", $createdDate),
|
||||
$blockHtml
|
||||
),
|
||||
sprintf('Created date wasn\'t found or not equals to %s.', $createdDate)
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf("//td[contains(@class, 'item')]//a[contains(text(), '%s')]", $review->getName()),
|
||||
$blockHtml
|
||||
),
|
||||
'Product name wasn\'t found.'
|
||||
);
|
||||
$rating = $review->getSum() / $review->getCount();
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf("//td[contains(@class, 'summary')]//span[contains(text(), '%s%%')]", $rating),
|
||||
$blockHtml
|
||||
),
|
||||
sprintf('Rating wasn\'t found or not equals to %s%%.', $rating)
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf("//td[contains(@class, 'description') and contains(text(), '%s')]", $review->getDetail()),
|
||||
$blockHtml
|
||||
),
|
||||
'Review description wasn\'t found.'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf(
|
||||
"//td[contains(@class, 'actions')]//a[contains(@href, '%s')]/span[contains(text(), '%s')]",
|
||||
$this->block->getReviewUrl($review),
|
||||
__('See Details')
|
||||
),
|
||||
$blockHtml
|
||||
),
|
||||
sprintf('%s button wasn\'t found.', __('See Details'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Customer/_files/customer.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCustomerWithoutReviews(): void
|
||||
{
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$this->assertStringContainsString(
|
||||
(string)__('You have submitted no reviews.'),
|
||||
strip_tags($this->block->toHtml())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Block\Customer;
|
||||
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for displaying customer product review block.
|
||||
*
|
||||
* @see \Magento\Review\Block\Customer\View
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class ViewTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Session */
|
||||
private $customerSession;
|
||||
|
||||
/** @var CollectionFactory */
|
||||
private $collectionFactory;
|
||||
|
||||
/** @var View */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->customerSession = $this->objectManager->get(Session::class);
|
||||
$this->collectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(View::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->customerSession->setCustomerId(null);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCustomerProductReviewBlock(): void
|
||||
{
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$review = $this->collectionFactory->create()->addCustomerFilter(1)->getFirstItem();
|
||||
$this->assertNotNull($review->getReviewId());
|
||||
$blockHtml = $this->block->setReviewId($review->getReviewId())->toHtml();
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf("//div[contains(@class, 'product-info')]/h2[contains(text(), '%s')]", $review->getName()),
|
||||
$blockHtml
|
||||
),
|
||||
'Product name wasn\'t found.'
|
||||
);
|
||||
$ratings = $this->block->getRating();
|
||||
$this->assertCount(2, $ratings);
|
||||
foreach ($ratings as $rating) {
|
||||
$this->assertNotEmpty($rating->getRatingId());
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf(
|
||||
"//div[contains(@id, 'rating-div-".$rating->getRatingId()."')]//span[contains(text(), '%s')]",
|
||||
$rating->getPercent()
|
||||
),
|
||||
$blockHtml
|
||||
),
|
||||
sprintf('Rating %s was not found or not equals to %s.', $rating->getRatingCode(), $rating->getPercent())
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf("//div[contains(@class, 'review-title') and contains(text(), '%s')]", $review->getTitle()),
|
||||
$blockHtml
|
||||
),
|
||||
'Review title wasn\'t found.'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf("//div[contains(@class, 'review-content') and contains(text(), '%s')]", $review->getDetail()),
|
||||
$blockHtml
|
||||
),
|
||||
'Review description wasn\'t found.'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf(
|
||||
"//div[contains(@class, 'review-date') and contains(text(), '%s')]/time[contains(text(), '%s')]",
|
||||
__('Submitted on'),
|
||||
$this->block->dateFormat($review->getCreatedAt())
|
||||
),
|
||||
$blockHtml
|
||||
),
|
||||
'Created date wasn\'t found.'
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf(
|
||||
"//a[contains(@href, '/review/customer/')]/span[contains(text(), '%s')]",
|
||||
__('Back to My Reviews')
|
||||
),
|
||||
$blockHtml
|
||||
),
|
||||
sprintf('%s button wasn\'t found.', __('Back to My Reviews'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Review\Block;
|
||||
|
||||
use Magento\Framework\App\Area;
|
||||
use Magento\Framework\App\Config\Value;
|
||||
use Magento\Framework\App\ReinitableConfig;
|
||||
use Magento\Framework\App\State;
|
||||
use Magento\Framework\View\Element\ButtonLockManager;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager;
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = $this->getObjectManager();
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoDataFixture Magento/Review/_files/config.php
|
||||
* @dataProvider getCorrectFlagDataProvider
|
||||
*/
|
||||
public function testGetCorrectFlag(
|
||||
$path,
|
||||
$scope,
|
||||
$scopeId,
|
||||
$value,
|
||||
$expectedResult
|
||||
) {
|
||||
/** @var State $appState */
|
||||
$appState = $this->objectManager->get(State::class);
|
||||
$appState->setAreaCode(Area::AREA_FRONTEND);
|
||||
|
||||
/** @var Value $config */
|
||||
$config = $this->objectManager->create(Value::class);
|
||||
$config->setPath($path);
|
||||
$config->setScope($scope);
|
||||
$config->setScopeId($scopeId);
|
||||
$config->setValue($value);
|
||||
$config->save();
|
||||
/** @var ReinitableConfig $reinitableConfig */
|
||||
$reinitableConfig = $this->objectManager->create(ReinitableConfig::class);
|
||||
$reinitableConfig->reinit();
|
||||
|
||||
/** @var \Magento\Review\Block\Form $form */
|
||||
$form = $this->objectManager->create(\Magento\Review\Block\Form::class);
|
||||
$form->setButtonLockManager(
|
||||
$this->objectManager->create(ButtonLockManager::class, ['buttonLockPool' => []])
|
||||
);
|
||||
$result = $form->getAllowWriteReviewFlag();
|
||||
$this->assertEquals($result, $expectedResult);
|
||||
}
|
||||
|
||||
public function getCorrectFlagDataProvider()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'path' => 'catalog/review/allow_guest',
|
||||
'scope' => 'websites',
|
||||
'scopeId' => '1',
|
||||
'value' => 0,
|
||||
'expectedResult' => false,
|
||||
],
|
||||
[
|
||||
'path' => 'catalog/review/allow_guest',
|
||||
'scope' => 'websites',
|
||||
'scopeId' => '1',
|
||||
'value' => 1,
|
||||
'expectedResult' => true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getObjectManager()
|
||||
{
|
||||
return \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Review\Block\Product;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Review\Block\Product\ReviewRenderer
|
||||
*/
|
||||
class ReviewRendererTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test verifies ReviewRenderer::getReviewsSummaryHtml call with $displayIfNoReviews = false
|
||||
* The reviews summary will be shown as expected only if there is at least one review available
|
||||
*
|
||||
* @magentoDataFixture Magento/Review/_files/different_reviews.php
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
public function testGetReviewSummaryHtml()
|
||||
{
|
||||
$productSku = 'simple';
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get($productSku);
|
||||
/** @var ReviewRenderer $reviewRenderer */
|
||||
$reviewRenderer = $objectManager->create(ReviewRenderer::class);
|
||||
$actualResult = $reviewRenderer->getReviewsSummaryHtml($product);
|
||||
$this->assertEquals(2, $reviewRenderer->getReviewsCount());
|
||||
$this->assertStringContainsString('<span itemprop="reviewCount">2</span>', $actualResult);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Block;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for displaying product review block.
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class ViewTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var Session */
|
||||
private $customerSession;
|
||||
|
||||
/** @var CollectionFactory */
|
||||
private $collectionFactory;
|
||||
|
||||
/** @var Registry */
|
||||
private $registry;
|
||||
|
||||
/** @var View */
|
||||
private $block;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->customerSession = $this->objectManager->get(Session::class);
|
||||
$this->collectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
$this->registry = $this->objectManager->get(Registry::class);
|
||||
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(View::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->registry->unregister('current_review');
|
||||
$this->registry->unregister('current_product');
|
||||
$this->registry->unregister('product');
|
||||
$this->customerSession->setCustomerId(null);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test product review block
|
||||
*
|
||||
* @magentoDataFixture Magento/Review/_files/product_review_with_rating.php
|
||||
*
|
||||
* @return void
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function testProductReviewBlock(): void
|
||||
{
|
||||
$this->customerSession->setCustomerId(1);
|
||||
$review = $this->collectionFactory->create()->addCustomerFilter(1)->getFirstItem();
|
||||
$this->registerReview($review);
|
||||
$this->assertNotNull($review->getReviewId());
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
|
||||
/** @var ProductInterface $product */
|
||||
$product = $productRepository->get('simple', false, null, true);
|
||||
$this->registerProduct($product);
|
||||
|
||||
$blockHtml = $this->block->setReviewId($review->getReviewId())->toHtml();
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf("//div[contains(@class, 'details')]/h3[contains(text(), '%s')]", $review->getName()),
|
||||
$blockHtml
|
||||
),
|
||||
'Product name wasn\'t found.'
|
||||
);
|
||||
$ratings = $this->block->getRating();
|
||||
$this->assertCount(2, $ratings);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
sprintf(
|
||||
"//a[contains(@class, 'action back')]/span[contains(text(), '%s')]",
|
||||
__('Back to Product Reviews')
|
||||
),
|
||||
$blockHtml
|
||||
),
|
||||
sprintf('%s button wasn\'t found.', __('Back to Product Reviews'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the product
|
||||
*
|
||||
* @param ProductInterface $product
|
||||
* @return void
|
||||
*/
|
||||
private function registerProduct(ProductInterface $product): void
|
||||
{
|
||||
$this->registry->unregister('current_product');
|
||||
$this->registry->unregister('product');
|
||||
$this->registry->register('current_product', $product);
|
||||
$this->registry->register('product', $product);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the current review
|
||||
*
|
||||
* @param Product $review
|
||||
* @return void
|
||||
*/
|
||||
private function registerReview(Product $review): void
|
||||
{
|
||||
$this->registry->unregister('current_review');
|
||||
$this->registry->register('current_review', $review);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Controller\Adminhtml\Customer;
|
||||
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use Magento\Framework\App\Request\Http as HttpRequest;
|
||||
use Magento\Framework\View\LayoutInterface;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* Test for customer product reviews page.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ProductReviewsTest extends AbstractBackendController
|
||||
{
|
||||
/** @var LayoutInterface */
|
||||
private $layout;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->layout = $this->_objectManager->get(LayoutInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Customer product review action.
|
||||
*
|
||||
* @magentoDataFixture Magento/Customer/_files/customer_sample.php
|
||||
* @return void
|
||||
*/
|
||||
public function testProductReviewsAction(): void
|
||||
{
|
||||
$this->dispatchWithIdParam(1);
|
||||
$this->assertStringContainsString('<div id="reviewGrid"', $this->getResponse()->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testProductReviews(): void
|
||||
{
|
||||
$customerId = 1;
|
||||
$this->dispatchWithIdParam($customerId);
|
||||
$block = $this->layout->getBlock('admin.customer.reviews');
|
||||
$this->assertNotFalse($block);
|
||||
$this->assertEquals(
|
||||
$customerId,
|
||||
$block->getCustomerId(),
|
||||
'Block customer id value does not match expected value'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch request with id parameter
|
||||
*
|
||||
* @param int $id
|
||||
* @return void
|
||||
*/
|
||||
private function dispatchWithIdParam(int $id): void
|
||||
{
|
||||
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
|
||||
$this->getRequest()->setParams(['id' => $id]);
|
||||
$this->dispatch('backend/review/customer/productReviews');
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Controller\Adminhtml\Product;
|
||||
|
||||
use Magento\Review\Model\Review;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
use Magento\Framework\Acl\Builder;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Review\Model\ResourceModel\Review\CollectionFactory;
|
||||
|
||||
/**
|
||||
* Test Edit action.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class EditTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
private $aclBuilder;
|
||||
|
||||
/**
|
||||
* @var UrlInterface
|
||||
*/
|
||||
private $urlBuilder;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->aclBuilder = $this->objectManager->get(Builder::class);
|
||||
$this->urlBuilder = $this->objectManager->get(UrlInterface::class);
|
||||
$this->collectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
$this->aclBuilder->resetRuntimeAcl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Edit action without reviews_all resource when manipulating Pending review.
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Review/_files/reviews.php
|
||||
*/
|
||||
public function testAclHasAccess(): void
|
||||
{
|
||||
$collection = $this->collectionFactory->create();
|
||||
$collection->addFilter('detail.nickname', 'Nickname');
|
||||
/** @var Review $review */
|
||||
$review = $collection->getItemByColumnValue('status_id', Review::STATUS_PENDING);
|
||||
|
||||
// Exclude resource from ACL.
|
||||
$this->aclBuilder->getAcl()->deny(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_ROLE_ID,
|
||||
'Magento_Review::reviews_all'
|
||||
);
|
||||
$this->uri = 'backend/review/product/edit/id/' . $review->getId();
|
||||
|
||||
parent::testAclHasAccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Edit action without pending and reviews_all resources.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAclNoAccess(): void
|
||||
{
|
||||
// Exclude resource from ACL.
|
||||
$this->resource = ['Magento_Review::reviews_all', 'Magento_Review::pending'];
|
||||
$this->uri = 'backend/review/product/edit/id/' . 'doesn\'t matter';
|
||||
|
||||
parent::testAclNoAccess();
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Controller\Adminhtml\Product;
|
||||
|
||||
use Magento\Review\Model\Review;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
use Magento\Framework\Acl\Builder;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Review\Model\ResourceModel\Review\CollectionFactory;
|
||||
use Laminas\Http\Request;
|
||||
|
||||
/**
|
||||
* Test Mass Update action.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class MassUpdateTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var Builder
|
||||
*/
|
||||
private $aclBuilder;
|
||||
|
||||
/**
|
||||
* @var UrlInterface
|
||||
*/
|
||||
private $urlBuilder;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->aclBuilder = $this->objectManager->get(Builder::class);
|
||||
$this->urlBuilder = $this->objectManager->get(UrlInterface::class);
|
||||
$this->collectionFactory = $this->objectManager->get(CollectionFactory::class);
|
||||
$this->aclBuilder->resetRuntimeAcl();
|
||||
$this->httpMethod = Request::METHOD_POST;
|
||||
$this->uri = 'backend/review/product/massUpdateStatus';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Mass Update action without reviews_all resource when manipulating Pending reviews.
|
||||
*
|
||||
* @return void
|
||||
* @magentoDataFixture Magento/Review/_files/reviews.php
|
||||
*/
|
||||
public function testAclHasAccess(): void
|
||||
{
|
||||
$collection = $this->collectionFactory->create();
|
||||
$collection->addFilter('detail.nickname', 'Nickname');
|
||||
/** @var Review $review */
|
||||
$review = $collection->getItemByColumnValue('status_id', Review::STATUS_PENDING);
|
||||
|
||||
// Exclude resource from ACL.
|
||||
$this->aclBuilder->getAcl()->deny(
|
||||
\Magento\TestFramework\Bootstrap::ADMIN_ROLE_ID,
|
||||
'Magento_Review::reviews_all'
|
||||
);
|
||||
$this->getRequest()->setPostValue(['reviews' => $review->getId()]);
|
||||
|
||||
parent::testAclHasAccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests Mass Update action without pending and reviews_all resources.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAclNoAccess(): void
|
||||
{
|
||||
// Exclude resource from ACL.
|
||||
$this->resource = ['Magento_Review::reviews_all', 'Magento_Review::pending'];
|
||||
|
||||
parent::testAclNoAccess();
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Controller;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\TestFramework\Request;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Test review product controller behavior
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class CaseCheckAddingProductReviewTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Test adding a review for allowed guests with incomplete data by a not logged in user
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Review/_files/config.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
*/
|
||||
public function testAttemptForGuestToAddReviewsWithIncompleteData()
|
||||
{
|
||||
$product = $this->getProduct();
|
||||
/** @var FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(FormKey::class);
|
||||
$post = [
|
||||
'nickname' => 'Test nick',
|
||||
'title' => 'Summary',
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
$this->prepareRequestData($post);
|
||||
$this->dispatch('review/product/post/id/' . $product->getId());
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['Please enter a review.']),
|
||||
MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test adding a review for not allowed guests by a guest
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Review/_files/disable_config.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
*/
|
||||
public function testAttemptForGuestToAddReview()
|
||||
{
|
||||
$product = $this->getProduct();
|
||||
/** @var FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(FormKey::class);
|
||||
$post = [
|
||||
'nickname' => 'Test nick',
|
||||
'title' => 'Summary',
|
||||
'detail' => 'Test Details',
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
|
||||
$this->prepareRequestData($post);
|
||||
$this->dispatch('review/product/post/id/' . $product->getId());
|
||||
|
||||
$this->assertRedirect($this->stringContains('customer/account/login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successfully adding a product review by a guest
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Review/_files/config.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
*/
|
||||
public function testSuccessfullyAddingProductReviewForGuest()
|
||||
{
|
||||
$product = $this->getProduct();
|
||||
/** @var FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(FormKey::class);
|
||||
$post = [
|
||||
'nickname' => 'Test nick',
|
||||
'title' => 'Summary',
|
||||
'detail' => 'Test Details',
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
|
||||
$this->prepareRequestData($post);
|
||||
$this->dispatch('review/product/post/id/' . $product->getId());
|
||||
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['You submitted your review for moderation.']),
|
||||
MessageInterface::TYPE_SUCCESS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ProductInterface
|
||||
*/
|
||||
private function getProduct()
|
||||
{
|
||||
return $this->_objectManager->get(ProductRepositoryInterface::class)->get('custom-design-simple-product');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $postData
|
||||
* @return void
|
||||
*/
|
||||
private function prepareRequestData($postData)
|
||||
{
|
||||
$this->getRequest()->setMethod(Request::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Controller;
|
||||
|
||||
class ProductTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Catalog/_files/products.php
|
||||
*/
|
||||
public function testListActionDesign()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$product = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class)
|
||||
->get('custom-design-simple-product');
|
||||
$this->getRequest()->setParam('id', $product->getId());
|
||||
$this->dispatch('review/product/listAction');
|
||||
$result = $this->getResponse()->getBody();
|
||||
$this->assertStringNotContainsString("/frontend/Magento/luma/en_US/", $result);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Model\ResourceModel\Rating;
|
||||
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Review\Model\ResourceModel\Rating\Collection
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\ResourceModel\Rating\Collection::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
|
||||
*/
|
||||
public function testAddEntitySummaryToItem()
|
||||
{
|
||||
$ratingData = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Framework\Registry::class)
|
||||
->registry('rating_data');
|
||||
|
||||
$result = $this->collection->addEntitySummaryToItem($ratingData->getEntityId(), $ratingData->getStoreId());
|
||||
$this->assertEquals($this->collection, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testAddEntitySummaryToItemEmpty()
|
||||
{
|
||||
foreach ($this->collection->getItems() as $item) {
|
||||
$item->delete();
|
||||
}
|
||||
$this->collection->clear();
|
||||
$result = $this->collection->addEntitySummaryToItem(1, 1);
|
||||
$this->assertEquals($this->collection, $result);
|
||||
}
|
||||
|
||||
public function testAddStoreData()
|
||||
{
|
||||
$this->collection->addStoreData();
|
||||
}
|
||||
|
||||
public function testSetStoreFilter()
|
||||
{
|
||||
$this->collection->setStoreFilter(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Model\ResourceModel;
|
||||
|
||||
/**
|
||||
* Class RatingTest
|
||||
*/
|
||||
class RatingTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Store\Model\StoreManagerInterface::class)
|
||||
->getStore()->getId();
|
||||
|
||||
$rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
);
|
||||
$rating->setData([
|
||||
'rating_code' => 'Test Rating',
|
||||
'position' => 0,
|
||||
'is_active' => true,
|
||||
'entity_id' => 1
|
||||
]);
|
||||
$rating->setRatingCodes([$storeId => 'Test Rating']);
|
||||
$rating->setStores([$storeId]);
|
||||
$rating->save();
|
||||
$this->id = $rating->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testRatingLoad()
|
||||
{
|
||||
$rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
);
|
||||
$rating->load($this->id);
|
||||
$this->assertEquals('Test Rating', $rating->getRatingCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testRatingEdit()
|
||||
{
|
||||
$rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
);
|
||||
$rating->load($this->id);
|
||||
$this->assertEquals('Test Rating', $rating->getRatingCode());
|
||||
$storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->get(\Magento\Store\Model\StoreManagerInterface::class)
|
||||
->getStore()->getId();
|
||||
$rating->setRatingCode('Test Rating Edited');
|
||||
$rating->setRatingCodes([$storeId => 'Test Rating Edited']);
|
||||
$rating->save();
|
||||
|
||||
$this->assertEquals('Test Rating Edited', $rating->getRatingCode());
|
||||
$this->assertEquals([$storeId => 'Test Rating Edited'], $rating->getRatingCodes());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
public function testRatingSaveWithError()
|
||||
{
|
||||
$this->expectException('Exception');
|
||||
$this->expectExceptionMessage('Rolled back transaction has not been completed correctly');
|
||||
$rating = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
);
|
||||
$rating->load($this->id);
|
||||
$rating->setRatingCodes([222 => 'Test Rating Edited']);
|
||||
$rating->save();
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Model\ResourceModel\Review\Product;
|
||||
|
||||
/**
|
||||
* Tests some functionality of the Product Review collection
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @param string $status
|
||||
* @param int $expectedCount
|
||||
* @param string $sortAttribute
|
||||
* @param string $dir
|
||||
* @param callable $assertion
|
||||
* @dataProvider sortOrderAssertionsDataProvider
|
||||
* @magentoDataFixture Magento/Review/_files/different_reviews.php
|
||||
*/
|
||||
public function testGetResultingIds(
|
||||
?int $status,
|
||||
int $expectedCount,
|
||||
string $sortAttribute,
|
||||
string $dir,
|
||||
callable $assertion
|
||||
) {
|
||||
/**
|
||||
* @var $collection \Magento\Review\Model\ResourceModel\Review\Product\Collection
|
||||
*/
|
||||
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\ResourceModel\Review\Product\Collection::class
|
||||
);
|
||||
if ($status) {
|
||||
$collection->addStatusFilter($status);
|
||||
}
|
||||
$collection->setOrder($sortAttribute, $dir);
|
||||
$actual = $collection->getResultingIds();
|
||||
$this->assertCount($expectedCount, $actual);
|
||||
$assertion($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function sortOrderAssertionsDataProvider() :array
|
||||
{
|
||||
return [
|
||||
[
|
||||
\Magento\Review\Model\Review::STATUS_APPROVED,
|
||||
2,
|
||||
'rt.review_id',
|
||||
'DESC',
|
||||
function (array $actual) :void {
|
||||
$this->assertLessThan($actual[0], $actual[1]);
|
||||
}
|
||||
],
|
||||
[
|
||||
\Magento\Review\Model\Review::STATUS_APPROVED,
|
||||
2,
|
||||
'rt.review_id',
|
||||
'ASC',
|
||||
function (array $actual) :void {
|
||||
$this->assertLessThan($actual[1], $actual[0]);
|
||||
}
|
||||
],
|
||||
[
|
||||
\Magento\Review\Model\Review::STATUS_APPROVED,
|
||||
2,
|
||||
'rt.created_at',
|
||||
'ASC',
|
||||
function (array $actual) :void {
|
||||
$this->assertLessThan($actual[1], $actual[0]);
|
||||
}
|
||||
],
|
||||
[
|
||||
null,
|
||||
3,
|
||||
'rt.review_id',
|
||||
'ASC',
|
||||
function (array $actual) :void {
|
||||
$this->assertLessThan($actual[1], $actual[0]);
|
||||
}
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Review\Model\ResourceModel\Review;
|
||||
|
||||
use Magento\Framework\App\ResourceConnection;
|
||||
|
||||
/**
|
||||
* Class ReviewTest
|
||||
*/
|
||||
class ReviewTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Review\Model\ResourceModel\Review
|
||||
*/
|
||||
protected $reviewResource;
|
||||
|
||||
/**
|
||||
* @var \Magento\Review\Model\ResourceModel\Review\Collection
|
||||
*/
|
||||
protected $reviewCollection;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ResourceConnection
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\DB\Adapter\AdapterInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->resource = $this->objectManager->get(\Magento\Framework\App\ResourceConnection::class);
|
||||
$this->connection = $this->resource->getConnection();
|
||||
$this->reviewCollection = $this->objectManager->create(
|
||||
\Magento\Review\Model\ResourceModel\Review\Collection::class
|
||||
);
|
||||
$this->reviewResource = $this->objectManager->create(\Magento\Review\Model\ResourceModel\Review::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review_with_rating.php
|
||||
*/
|
||||
public function testAggregate()
|
||||
{
|
||||
$rating = $this->reviewCollection->getFirstItem();
|
||||
$this->reviewResource->aggregate($rating);
|
||||
|
||||
$select = $this->connection->select()->from($this->resource->getTableName('review_entity_summary'));
|
||||
$result = $this->connection->fetchRow($select);
|
||||
|
||||
$this->assertEquals(1, $result['reviews_count']);
|
||||
$this->assertEquals(40, $result['rating_summary']);
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Model\ResourceModel\Review\Summary;
|
||||
|
||||
use Magento\Framework\Data\Collection\Db\FetchStrategy\Query;
|
||||
use Magento\Framework\Data\Collection\EntityFactory;
|
||||
use Magento\Framework\DB\Adapter\AdapterInterface;
|
||||
use Magento\Framework\DB\Adapter\Pdo\Mysql;
|
||||
use Magento\Framework\DB\Select;
|
||||
use Magento\Framework\DB\Select\SelectRenderer;
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
||||
use Magento\Review\Model\ResourceModel\Review\Summary\Collection;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Tests some functionality of the Review Summary collection
|
||||
*/
|
||||
class CollectionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
protected Collection $collection;
|
||||
|
||||
/**
|
||||
* @var Query
|
||||
*/
|
||||
protected Query $fetchStrategyMock;
|
||||
|
||||
/**
|
||||
* @var EntityFactory
|
||||
*/
|
||||
protected EntityFactory $entityFactoryMock;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected LoggerInterface $loggerMock;
|
||||
|
||||
/**
|
||||
* @var AbstractDb
|
||||
*/
|
||||
protected AbstractDb $resourceMock;
|
||||
|
||||
/**
|
||||
* @var AdapterInterface
|
||||
*/
|
||||
protected AdapterInterface $connectionMock;
|
||||
|
||||
/**
|
||||
* @var Select
|
||||
*/
|
||||
protected Select $selectMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->fetchStrategyMock = $this->createPartialMock(
|
||||
Query::class,
|
||||
['fetchAll']
|
||||
);
|
||||
$this->entityFactoryMock = $this->createPartialMock(
|
||||
EntityFactory::class,
|
||||
['create']
|
||||
);
|
||||
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
|
||||
$this->resourceMock = $this->getMockBuilder(AbstractDb::class)
|
||||
->setMethods(['getConnection', 'getMainTable', 'getTable'])
|
||||
->disableOriginalConstructor()
|
||||
->getMockForAbstractClass();
|
||||
$this->connectionMock = $this->createPartialMock(
|
||||
Mysql::class,
|
||||
['select', 'query']
|
||||
);
|
||||
$selectRenderer = $this->getMockBuilder(SelectRenderer::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->selectMock = $this->getMockBuilder(Select::class)
|
||||
->setMethods(['where'])
|
||||
->setConstructorArgs(['adapter' => $this->connectionMock, 'selectRenderer' => $selectRenderer])
|
||||
->getMock();
|
||||
$this->connectionMock->expects($this->once())
|
||||
->method('select')
|
||||
->willReturn($this->selectMock);
|
||||
$this->resourceMock->expects($this->once())
|
||||
->method('getConnection')
|
||||
->willReturn($this->connectionMock);
|
||||
$this->resourceMock->expects($this->once())
|
||||
->method('getMainTable')
|
||||
->willReturn('main_table_name');
|
||||
|
||||
$this->resourceMock->expects($this->once())
|
||||
->method('getTable')
|
||||
->willReturnArgument(0);
|
||||
$objectManager = new ObjectManager($this);
|
||||
$this->collection = $objectManager->getObject(
|
||||
Collection::class,
|
||||
[
|
||||
'entityFactory' => $this->entityFactoryMock,
|
||||
'logger' => $this->loggerMock,
|
||||
'fetchStrategy' => $this->fetchStrategyMock,
|
||||
'resource' => $this->resourceMock
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|int $storeId
|
||||
* @param string $expectedQuery
|
||||
* @dataProvider storeIdDataProvider
|
||||
*/
|
||||
public function testAddStoreFilter(array|int $storeId, string $expectedQuery)
|
||||
{
|
||||
$this->selectMock->expects($this->once())->method('where')->with($expectedQuery, $storeId);
|
||||
$this->collection->addStoreFilter($storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function storeIdDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[1, 'store_id = ?'],
|
||||
[[1,2], 'store_id IN (?)']
|
||||
];
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Observer;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;
|
||||
use Magento\Review\Model\ResourceModel\Review\CollectionFactory as ReviewCollectionFactory;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Test checks that product review is removed when the corresponding product is removed
|
||||
*/
|
||||
class ProcessProductAfterDeleteEventObserverTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoDataFixture Magento/Review/_files/customer_review.php
|
||||
*/
|
||||
public function testReviewIsRemovedWhenProductDeleted()
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
|
||||
/** @var ReviewCollection $reviewsCollection */
|
||||
$reviewsCollection = $objectManager->get(ReviewCollectionFactory::class)->create();
|
||||
$reviewsCollection->addEntityFilter('product', $product->getId());
|
||||
|
||||
self::assertEquals(1, $reviewsCollection->count());
|
||||
|
||||
/* Remove product and ensure that the product review is removed as well */
|
||||
$productRepository->delete($product);
|
||||
$reviewsCollection->clear();
|
||||
|
||||
self::assertEquals(0, $reviewsCollection->count());
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Review\Ui\DataProvider\Product;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Magento\Framework\Api\Filter;
|
||||
|
||||
/**
|
||||
* Test for \Magento\Review\Ui\DataProvider\Product\ReviewDataProvider.
|
||||
*/
|
||||
class ReviewDataProviderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $modelParams = [
|
||||
'name' => 'review_listing_data_source',
|
||||
'primaryFieldName' => 'review_id',
|
||||
'requestFieldName' => 'entity_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorting dataProvider test
|
||||
*
|
||||
* @magentoDataFixture Magento/Review/_files/different_reviews.php
|
||||
* @dataProvider sortingDataProvider
|
||||
*
|
||||
* @param string $field
|
||||
* @param string $direction
|
||||
* @param array $expectedSortedTitles
|
||||
* @return void
|
||||
*/
|
||||
public function testSorting(string $field, string $direction, array $expectedSortedTitles): void
|
||||
{
|
||||
$request = $this->objectManager->create(RequestInterface::class);
|
||||
$request->setParam('current_product_id', 1);
|
||||
|
||||
$dataProvider = $this->objectManager->create(
|
||||
ReviewDataProvider::class,
|
||||
array_merge($this->modelParams, ['request' => $request])
|
||||
);
|
||||
$dataProvider->addOrder($field, $direction);
|
||||
$result = $dataProvider->getData();
|
||||
|
||||
$this->assertEquals($this->getItemsField($result, 'title'), $expectedSortedTitles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return items field data
|
||||
*
|
||||
* @param array $arrItems
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
private function getItemsField(array $arrItems, string $field): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($arrItems['items'] as $review) {
|
||||
$data[] = $review[$field];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* DataProvider for testSorting
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sortingDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'sort by title field ascending' => [
|
||||
'title',
|
||||
'asc',
|
||||
['1 filter second review', '2 filter first review', 'Review Summary'],
|
||||
],
|
||||
'sort by title field descending' => [
|
||||
'title',
|
||||
'desc',
|
||||
['Review Summary', '2 filter first review', '1 filter second review'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter dataProvider test
|
||||
*
|
||||
* @magentoDataFixture Magento/Review/_files/different_reviews.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testFilter(): void
|
||||
{
|
||||
$searchTitle = '2 filter first review';
|
||||
|
||||
$request = $this->objectManager->create(RequestInterface::class);
|
||||
$request->setParam('current_product_id', 1);
|
||||
|
||||
/** @var ReviewDataProvider $dataProvider */
|
||||
$dataProvider = $this->objectManager->create(
|
||||
ReviewDataProvider::class,
|
||||
array_merge($this->modelParams, ['request' => $request])
|
||||
);
|
||||
|
||||
/** @var Filter $filter */
|
||||
$filter = $this->objectManager->create(Filter::class);
|
||||
$filter->setField('title')
|
||||
->setValue($searchTitle);
|
||||
|
||||
$dataProvider->addFilter($filter);
|
||||
$result = $dataProvider->getData();
|
||||
|
||||
$this->assertEquals($this->getItemsField($result, 'title'), [$searchTitle]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Framework\App\Config\Value;
|
||||
use Magento\TestFramework\App\Config as AppConfig;
|
||||
|
||||
/** @var Value $config */
|
||||
$config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(Value::class);
|
||||
$config->setPath('catalog/review/allow_guest');
|
||||
$config->setScope('default');
|
||||
$config->setScopeId(0);
|
||||
$config->setValue(1);
|
||||
$config->save();
|
||||
|
||||
/** @var AppConfig $appConfig */
|
||||
$appConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(AppConfig::class);
|
||||
$appConfig->clean();
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
Bootstrap::getInstance()->loadArea(
|
||||
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
|
||||
);
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = $objectManager->create(CustomerRegistry::class);
|
||||
$customer = $customerRegistry->retrieve(1);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
$review = $objectManager->create(
|
||||
\Magento\Review\Model\Review::class,
|
||||
['data' => [
|
||||
'customer_id' => $customer->getId(),
|
||||
'title' => 'Review Summary',
|
||||
'detail' => 'Review text',
|
||||
'nickname' => 'Nickname',
|
||||
]]
|
||||
);
|
||||
|
||||
$review
|
||||
->setEntityId($review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE))
|
||||
->setEntityPkValue($product->getId())
|
||||
->setStatusId(\Magento\Review\Model\Review::STATUS_PENDING)
|
||||
->setStoreId(
|
||||
$objectManager->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
)
|
||||
->setStores([
|
||||
$objectManager->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
])
|
||||
->save();
|
||||
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register(
|
||||
'review_data',
|
||||
$review
|
||||
);
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(
|
||||
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
|
||||
);
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = $objectManager->create(CustomerRegistry::class);
|
||||
$customer = $customerRegistry->retrieve(1);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
$storeId = $objectManager->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId();
|
||||
|
||||
$review = $objectManager->create(
|
||||
\Magento\Review\Model\Review::class,
|
||||
['data' => [
|
||||
'customer_id' => $customer->getId(),
|
||||
'title' => 'Review Summary',
|
||||
'detail' => 'Review text',
|
||||
'nickname' => 'Nickname',
|
||||
]]
|
||||
);
|
||||
|
||||
$review
|
||||
->setEntityId($review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE))
|
||||
->setEntityPkValue($product->getId())
|
||||
->setStatusId(\Magento\Review\Model\Review::STATUS_APPROVED)
|
||||
->setStoreId($storeId)
|
||||
->setStores([$storeId])
|
||||
->save();
|
||||
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register(
|
||||
'review_data',
|
||||
$review
|
||||
);
|
||||
|
||||
/** @var \Magento\Review\Model\ResourceModel\Review\Collection $ratingCollection */
|
||||
$ratingCollection = $objectManager->create(
|
||||
\Magento\Review\Model\Rating::class
|
||||
)->getCollection()
|
||||
->setPageSize(2)
|
||||
->setCurPage(1);
|
||||
|
||||
foreach ($ratingCollection as $rating) {
|
||||
$rating->setStores([$storeId])->setIsActive(1)->save();
|
||||
}
|
||||
|
||||
foreach ($ratingCollection as $rating) {
|
||||
$ratingOption = $objectManager
|
||||
->create(\Magento\Review\Model\Rating\Option::class)
|
||||
->getCollection()
|
||||
->setPageSize(1)
|
||||
->setCurPage(2)
|
||||
->addRatingFilter($rating->getId())
|
||||
->getFirstItem();
|
||||
$rating->setReviewId($review->getId())
|
||||
->addOptionVote($ratingOption->getId(), $product->getId());
|
||||
}
|
||||
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->register(
|
||||
'rating_data',
|
||||
$ratingCollection->getFirstItem()
|
||||
);
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_rollback.php');
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
$review = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Review::class,
|
||||
['data' => ['nickname' => 'Nickname', 'title' => 'Review Summary', 'detail' => 'Review text']]
|
||||
);
|
||||
$review->setEntityId(
|
||||
$review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE)
|
||||
)->setEntityPkValue(
|
||||
1
|
||||
)->setStatusId(
|
||||
\Magento\Review\Model\Review::STATUS_PENDING
|
||||
)->setStoreId(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
)->setStores(
|
||||
[
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
]
|
||||
)->save();
|
||||
|
||||
/*
|
||||
* Added a sleep because in a few tests the sql query orders by created at. Without the sleep the reviews
|
||||
* have sometimes the same created at timestamp, that causes this tests randomly to fail.
|
||||
*/
|
||||
sleep(1);
|
||||
|
||||
$review = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Review::class,
|
||||
['data' => ['nickname' => 'Nickname', 'title' => '2 filter first review', 'detail' => 'Review text']]
|
||||
);
|
||||
$review->setEntityId(
|
||||
$review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE)
|
||||
)->setEntityPkValue(
|
||||
1
|
||||
)->setStatusId(
|
||||
\Magento\Review\Model\Review::STATUS_APPROVED
|
||||
)->setStoreId(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
)->setStores(
|
||||
[
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
]
|
||||
)->save();
|
||||
|
||||
/*
|
||||
* Added a sleep because in a few tests the sql query orders by created at. Without the sleep the reviews
|
||||
* have sometimes the same created at timestamp, that causes this tests randomly to fail.
|
||||
*/
|
||||
sleep(1);
|
||||
|
||||
$review = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Review\Model\Review::class,
|
||||
['data' => ['nickname' => 'Nickname', 'title' => '1 filter second review', 'detail' => 'Review text']]
|
||||
);
|
||||
$review->setEntityId(
|
||||
$review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE)
|
||||
)->setEntityPkValue(
|
||||
1
|
||||
)->setStatusId(
|
||||
\Magento\Review\Model\Review::STATUS_APPROVED
|
||||
)->setStoreId(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
)->setStores(
|
||||
[
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
]
|
||||
)->save();
|
||||
$review->aggregate();
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_rollback.php');
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/** @var Value $config */
|
||||
use Magento\Framework\App\Config\Value;
|
||||
use Magento\TestFramework\App\Config as AppConfig;
|
||||
|
||||
$config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(Value::class);
|
||||
$config->setPath('catalog/review/allow_guest');
|
||||
$config->setScope('default');
|
||||
$config->setScopeId(0);
|
||||
$config->setValue(0);
|
||||
$config->save();
|
||||
|
||||
/** @var AppConfig $appConfig */
|
||||
$appConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(AppConfig::class);
|
||||
$appConfig->clean();
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Backend\App\Area\FrontNameResolver;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Review\Model\Rating;
|
||||
use Magento\Review\Model\Rating\Option;
|
||||
use Magento\Review\Model\ResourceModel\Review\Collection;
|
||||
use Magento\Review\Model\Review;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Bootstrap::getInstance()->loadArea(
|
||||
FrontNameResolver::AREA_CODE
|
||||
);
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var CustomerRegistry $customerRegistry */
|
||||
$customerRegistry = $objectManager->create(CustomerRegistry::class);
|
||||
$customer = $customerRegistry->retrieve(1);
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple');
|
||||
$storeId = $objectManager->get(
|
||||
StoreManagerInterface::class
|
||||
)->getStore()->getId();
|
||||
|
||||
$review = $objectManager->create(
|
||||
Review::class,
|
||||
['data' => [
|
||||
'customer_id' => $customer->getId(),
|
||||
'title' => 'Review Summary',
|
||||
'detail' => 'Review text',
|
||||
'nickname' => 'Nickname',
|
||||
]]
|
||||
);
|
||||
|
||||
$review
|
||||
->setEntityId($review->getEntityIdByCode(Review::ENTITY_PRODUCT_CODE))
|
||||
->setEntityPkValue($product->getId())
|
||||
->setStatusId(Review::STATUS_APPROVED)
|
||||
->setStoreId($storeId)
|
||||
->setStores([$storeId])
|
||||
->save();
|
||||
|
||||
$objectManager->get(Registry::class)->register(
|
||||
'review_data',
|
||||
$review
|
||||
);
|
||||
|
||||
/** @var Collection $ratingCollection */
|
||||
$ratingCollection = $objectManager->create(
|
||||
Rating::class
|
||||
)->getCollection()
|
||||
->setPageSize(2)
|
||||
->setCurPage(1);
|
||||
|
||||
foreach ($ratingCollection as $rating) {
|
||||
$rating->setStores([$storeId])->setIsActive(1)->save();
|
||||
}
|
||||
|
||||
foreach ($ratingCollection as $rating) {
|
||||
$ratingOption = $objectManager
|
||||
->create(Option::class)
|
||||
->getCollection()
|
||||
->setPageSize(1)
|
||||
->setCurPage(2)
|
||||
->addRatingFilter($rating->getId())
|
||||
->getFirstItem();
|
||||
$rating->setReviewId($review->getId())
|
||||
->addOptionVote($ratingOption->getId(), $product->getId());
|
||||
}
|
||||
|
||||
$objectManager->get(Registry::class)->register(
|
||||
'rating_data',
|
||||
$ratingCollection->getFirstItem()
|
||||
);
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_rollback.php');
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/product_simple_xss.php');
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('product-with-xss');
|
||||
|
||||
$review = $objectManager->create(\Magento\Review\Model\Review::class);
|
||||
$review->setEntityId(
|
||||
$review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE)
|
||||
)->setEntityPkValue(
|
||||
$product->getId()
|
||||
)->setStatusId(
|
||||
\Magento\Review\Model\Review::STATUS_PENDING
|
||||
)->setStoreId(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
)->setStores(
|
||||
[
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
]
|
||||
)->setNickname(
|
||||
'Nickname'
|
||||
)->setTitle(
|
||||
'Review Summary'
|
||||
)->setDetail(
|
||||
'Review text'
|
||||
)->save();
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/multiple_products.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ProductRepositoryInterface $productRepository */
|
||||
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
|
||||
$product = $productRepository->get('simple1');
|
||||
$review = $objectManager->create(
|
||||
\Magento\Review\Model\Review::class,
|
||||
['data' => ['nickname' => 'Nickname', 'title' => 'Review Summary', 'detail' => 'Review text']]
|
||||
);
|
||||
$review->setEntityId(
|
||||
$review->getEntityIdByCode(\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE)
|
||||
)->setEntityPkValue(
|
||||
$product->getId()
|
||||
)->setStatusId(
|
||||
\Magento\Review\Model\Review::STATUS_PENDING
|
||||
)->setStoreId(
|
||||
$objectManager->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
)->setStores(
|
||||
[
|
||||
$objectManager->get(
|
||||
\Magento\Store\Model\StoreManagerInterface::class
|
||||
)->getStore()->getId()
|
||||
]
|
||||
)->save();
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Review\Model\ResourceModel\Rating\Collection as RatingCollection;
|
||||
use Magento\Review\Model\ResourceModel\Rating as RatingResourceModel;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId();
|
||||
|
||||
/** @var RatingResourceModel $ratingResourceModel */
|
||||
$ratingResourceModel = $objectManager->create(RatingResourceModel::class);
|
||||
|
||||
/** @var RatingCollection $ratingCollection */
|
||||
$ratingCollection = $objectManager->create(RatingCollection::class)->setOrder('rating_code', 'ASC');
|
||||
$position = 0;
|
||||
|
||||
foreach ($ratingCollection as $rating) {
|
||||
$rating->setStores([$storeId])->setPosition($position++);
|
||||
$ratingResourceModel->save($rating);
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Review\Model\ResourceModel\Rating\Collection as RatingCollection;
|
||||
use Magento\Review\Model\ResourceModel\Rating as RatingResourceModel;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
|
||||
$storeId = Bootstrap::getObjectManager()->get(StoreManagerInterface::class)->getStore()->getId();
|
||||
|
||||
/** @var RatingResourceModel $ratingResourceModel */
|
||||
$ratingResourceModel = $objectManager->create(RatingResourceModel::class);
|
||||
|
||||
/** @var RatingCollection $ratingCollection */
|
||||
$ratingCollection = Bootstrap::getObjectManager()->create(RatingCollection::class);
|
||||
|
||||
foreach ($ratingCollection as $rating) {
|
||||
$rating->setStores([])->setPosition(0);
|
||||
$ratingResourceModel->save($rating);
|
||||
}
|
||||
Reference in New Issue
Block a user