-
Notifications
You must be signed in to change notification settings - Fork 9.4k
added config for catalog review in frontend #18895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
magento-engcom-team
merged 3 commits into
magento:2.3-develop
from
torhoehn:feature/review-config
Dec 21, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/code/Magento/Review/Observer/PredispatchReviewObserver.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types = 1); | ||
|
||
namespace Magento\Review\Observer; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Review\Block\Product\ReviewRenderer; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Class PredispatchReviewObserver | ||
*/ | ||
class PredispatchReviewObserver implements ObserverInterface | ||
{ | ||
/** | ||
* Configuration path to review active setting | ||
*/ | ||
const XML_PATH_REVIEW_ACTIVE = 'catalog/review/active'; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var UrlInterface | ||
*/ | ||
private $url; | ||
|
||
/** | ||
* PredispatchReviewObserver constructor. | ||
* | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param UrlInterface $url | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
UrlInterface $url | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
$this->url = $url; | ||
} | ||
/** | ||
* Redirect review routes to 404 when review module is disabled. | ||
* | ||
* @param Observer $observer | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
if (!$this->scopeConfig->getValue( | ||
self::XML_PATH_REVIEW_ACTIVE, | ||
ScopeInterface::SCOPE_STORE | ||
) | ||
) { | ||
$defaultNoRouteUrl = $this->scopeConfig->getValue( | ||
'web/default/no_route', | ||
ScopeInterface::SCOPE_STORE | ||
); | ||
$redirectUrl = $this->url->getUrl($defaultNoRouteUrl); | ||
$observer->getControllerAction() | ||
->getResponse() | ||
->setRedirect($redirectUrl); | ||
} | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
app/code/Magento/Review/Test/Unit/Observer/PredispatchReviewObserverTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types = 1); | ||
|
||
namespace Magento\Review\Test\Unit\Observer; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\Response\RedirectInterface; | ||
use Magento\Framework\App\ResponseInterface; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Review\Observer\PredispatchReviewObserver; | ||
use Magento\Store\Model\ScopeInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test class for \Magento\Review\Observer\PredispatchReviewObserver | ||
*/ | ||
class PredispatchReviewObserverTest extends TestCase | ||
{ | ||
/** | ||
* @var Observer|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $mockObject; | ||
|
||
/** | ||
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $configMock; | ||
|
||
/** | ||
* @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $urlMock; | ||
|
||
/** | ||
* @var \Magento\Framework\App\Response\RedirectInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $redirectMock; | ||
|
||
/** | ||
* @var ResponseInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $responseMock; | ||
|
||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() : void | ||
{ | ||
$this->configMock = $this->getMockBuilder(ScopeConfigInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->urlMock = $this->getMockBuilder(UrlInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->responseMock = $this->getMockBuilder(ResponseInterface::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['setRedirect']) | ||
->getMockForAbstractClass(); | ||
$this->redirectMock = $this->getMockBuilder(RedirectInterface::class) | ||
->getMock(); | ||
$this->objectManager = new ObjectManager($this); | ||
$this->mockObject = $this->objectManager->getObject( | ||
PredispatchReviewObserver::class, | ||
[ | ||
'scopeConfig' => $this->configMock, | ||
'url' => $this->urlMock | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test with enabled review active config. | ||
*/ | ||
public function testReviewEnabled() : void | ||
{ | ||
$observerMock = $this->getMockBuilder(Observer::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getResponse', 'getData', 'setRedirect']) | ||
->getMockForAbstractClass(); | ||
|
||
$this->configMock->method('getValue') | ||
->with(PredispatchReviewObserver::XML_PATH_REVIEW_ACTIVE, ScopeInterface::SCOPE_STORE) | ||
->willReturn(true); | ||
$observerMock->expects($this->never()) | ||
->method('getData') | ||
->with('controller_action') | ||
->willReturnSelf(); | ||
|
||
$observerMock->expects($this->never()) | ||
->method('getResponse') | ||
->willReturnSelf(); | ||
|
||
$this->assertNull($this->mockObject->execute($observerMock)); | ||
} | ||
|
||
/** | ||
* Test with disabled review active config. | ||
*/ | ||
public function testReviewDisabled() : void | ||
{ | ||
$observerMock = $this->getMockBuilder(Observer::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getControllerAction', 'getResponse']) | ||
->getMockForAbstractClass(); | ||
|
||
$this->configMock->expects($this->at(0)) | ||
->method('getValue') | ||
->with(PredispatchReviewObserver::XML_PATH_REVIEW_ACTIVE, ScopeInterface::SCOPE_STORE) | ||
->willReturn(false); | ||
|
||
$expectedRedirectUrl = 'https://test.com/index'; | ||
|
||
$this->configMock->expects($this->at(1)) | ||
->method('getValue') | ||
->with('web/default/no_route', ScopeInterface::SCOPE_STORE) | ||
->willReturn($expectedRedirectUrl); | ||
|
||
$this->urlMock->expects($this->once()) | ||
->method('getUrl') | ||
->willReturn($expectedRedirectUrl); | ||
|
||
$observerMock->expects($this->once()) | ||
->method('getControllerAction') | ||
->willReturnSelf(); | ||
|
||
$observerMock->expects($this->once()) | ||
->method('getResponse') | ||
->willReturn($this->responseMock); | ||
|
||
$this->responseMock->expects($this->once()) | ||
->method('setRedirect') | ||
->with($expectedRedirectUrl); | ||
|
||
$this->assertNull($this->mockObject->execute($observerMock)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
<default> | ||
<catalog> | ||
<review> | ||
<active>1</active> | ||
<allow_guest>1</allow_guest> | ||
</review> | ||
</catalog> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.