-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[Theme] Covered Unit Test for \Magento\Theme\Controller\Result\JsFooterPlugin #26820
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 4 commits into
magento:2.4-develop
from
srsathish92:2.4-unit-test/theme-controller-result-jsfooterplugin
Feb 13, 2020
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6220474
[Theme] Covered Unit Test for \Magento\Theme\controller\Result\JsFoot…
srsathish92 a208226
Test case updated with if content NULL & fixed health check issue
srsathish92 6a82bf7
Data Provider keys added with description
srsathish92 c9dcd27
Fixed static test
srsathish92 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
164 changes: 164 additions & 0 deletions
164
app/code/Magento/Theme/Test/Unit/Controller/Result/JsFooterPluginTest.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,164 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Magento\Theme\Test\Unit\Controller\Result; | ||
|
|
||
| use Magento\Theme\Controller\Result\JsFooterPlugin; | ||
| use Magento\Framework\App\Response\Http; | ||
| use PHPUnit\Framework\TestCase; | ||
| use PHPUnit\Framework\MockObject\MockObject; | ||
| use Magento\Framework\App\Config\ScopeConfigInterface; | ||
| use Magento\Store\Model\ScopeInterface; | ||
| use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; | ||
|
|
||
| /** | ||
| * Unit test for Magento\Theme\Test\Unit\Controller\Result\JsFooterPlugin. | ||
| */ | ||
| class JsFooterPluginTest extends TestCase | ||
| { | ||
| const STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM = 'dev/js/move_script_to_bottom'; | ||
|
|
||
| /** | ||
| * @var JsFooterPlugin | ||
| */ | ||
| private $plugin; | ||
|
|
||
| /** | ||
| * @var ScopeConfigInterface|MockObject | ||
| */ | ||
| private $scopeConfigMock; | ||
|
|
||
| /** | ||
| * @var Http|MockObject | ||
| */ | ||
| private $httpMock; | ||
|
|
||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| protected function setUp(): void | ||
| { | ||
| $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) | ||
| ->setMethods(['isSetFlag']) | ||
| ->disableOriginalConstructor() | ||
| ->getMockForAbstractClass(); | ||
|
|
||
| $this->httpMock = $this->createMock(Http::class); | ||
|
|
||
| $objectManager = new ObjectManagerHelper($this); | ||
| $this->plugin = $objectManager->getObject( | ||
| JsFooterPlugin::class, | ||
| [ | ||
| 'scopeConfig' => $this->scopeConfigMock | ||
| ] | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Data Provider for testBeforeSendResponse() | ||
| * | ||
| * @return array | ||
| */ | ||
| public function sendResponseDataProvider(): array | ||
| { | ||
| return [ | ||
| [ | ||
| "content" => "<body><h1>Test Title</h1>" . | ||
| "<script type=\"text/x-magento-init\">test</script>" . | ||
| "<script type=\"text/x-magento-template\">test</script>" . | ||
| "<p>Test Content</p></body>", | ||
| "flag" => true, | ||
| "result" => "<body><h1>Test Title</h1>" . | ||
| "<script type=\"text/x-magento-template\">test</script>" . | ||
| "<p>Test Content</p>" . | ||
| "<script type=\"text/x-magento-init\">test</script>" . | ||
| "\n</body>" | ||
| ], | ||
| [ | ||
| "content" => "<body><p>Test Content</p></body>", | ||
| "flag" => false, | ||
| "result" => "<body><p>Test Content</p></body>" | ||
| ], | ||
| [ | ||
| "content" => "<body><p>Test Content</p></body>", | ||
| "flag" => true, | ||
| "result" => "<body><p>Test Content</p>\n</body>" | ||
| ] | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Test beforeSendResponse | ||
| * | ||
| * @param string $content | ||
| * @param bool $isSetFlag | ||
| * @param string $result | ||
| * @return void | ||
| * @dataProvider sendResponseDataProvider | ||
| */ | ||
| public function testBeforeSendResponse($content, $isSetFlag, $result): void | ||
| { | ||
| $this->httpMock->expects($this->once()) | ||
| ->method('getContent') | ||
| ->willReturn($content); | ||
|
|
||
| $this->scopeConfigMock->expects($this->once()) | ||
| ->method('isSetFlag') | ||
| ->with( | ||
| self::STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM, | ||
| ScopeInterface::SCOPE_STORE | ||
| ) | ||
| ->willReturn($isSetFlag); | ||
|
|
||
| $this->httpMock->expects($this->any()) | ||
| ->method('setContent') | ||
| ->with($result); | ||
|
|
||
| $this->plugin->beforeSendResponse($this->httpMock); | ||
| } | ||
|
|
||
| /** | ||
| * Data Provider for testBeforeSendResponseIfGetContentIsNotAString() | ||
| * | ||
| * @return array | ||
| */ | ||
| public function ifGetContentIsNotAStringDataProvider(): array | ||
| { | ||
| return [ | ||
| [ | ||
| 'content' => [] | ||
| ], | ||
| [ | ||
| 'content' => NULL | ||
| ] | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Test BeforeSendResponse if content is not a string | ||
| * | ||
| * @param string $content | ||
| * @return void | ||
| * @dataProvider ifGetContentIsNotAStringDataProvider | ||
| */ | ||
| public function testBeforeSendResponseIfGetContentIsNotAString($content): void | ||
| { | ||
| $this->httpMock->expects($this->once()) | ||
| ->method('getContent') | ||
| ->willReturn($content); | ||
|
|
||
| $this->scopeConfigMock->expects($this->never()) | ||
| ->method('isSetFlag') | ||
| ->with( | ||
| self::STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM, | ||
| ScopeInterface::SCOPE_STORE | ||
| ) | ||
| ->willReturn(false); | ||
|
|
||
| $this->plugin->beforeSendResponse($this->httpMock); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can replace this with:
As a result - when one of them fail - You'll know on which data set it failed (key of dataProvider is added to error message (Test failed with: X))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lbajsarowicz Thanks for the feedback, I have updated the keys.