-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of direct shop Utils usages Signed-off-by: Anton Fedurtsya <[email protected]>
- Loading branch information
Showing
7 changed files
with
110 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 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 was deleted.
Oops, something went wrong.
This file contains 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,29 @@ | ||
<?php | ||
|
||
namespace OxidEsales\MediaLibrary\Transition\Core; | ||
|
||
use OxidEsales\MediaLibrary\Core\Utils; | ||
|
||
class Response implements ResponseInterface | ||
{ | ||
/** @var Utils $language */ | ||
private $utils; | ||
|
||
public function __construct(\OxidEsales\Eshop\Core\Utils $utils) | ||
{ | ||
/** @var Utils $utils */ | ||
$this->utils = $utils; | ||
} | ||
|
||
public function responseAsJson(array $valueArray): void | ||
{ | ||
$this->utils->setHeader('Content-Type: application/json'); | ||
$this->utils->showMessageAndExit(json_encode($valueArray)); | ||
} | ||
|
||
public function responseAsJavaScript(string $value): void | ||
{ | ||
$this->utils->setHeader('Content-Type: application/javascript'); | ||
$this->utils->showMessageAndExit($value); | ||
} | ||
} |
This file contains 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,10 @@ | ||
<?php | ||
|
||
namespace OxidEsales\MediaLibrary\Transition\Core; | ||
|
||
interface ResponseInterface | ||
{ | ||
public function responseAsJson(array $valueArray): void; | ||
|
||
public function responseAsJavaScript(string $value): void; | ||
} |
This file contains 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 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,62 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\MediaLibrary\Tests\Integration\Transition\Core; | ||
|
||
use OxidEsales\Eshop\Core\Utils; | ||
use OxidEsales\MediaLibrary\Transition\Core\Response; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ResponseTest extends TestCase | ||
{ | ||
public function testRespondAsJson(): void | ||
{ | ||
$exampleData = ['somekey' => 'someValue']; | ||
$jsonValue = json_encode($exampleData); | ||
|
||
$utilsMock = $this->createPartialMock(Utils::class, ['setHeader', 'showMessageAndExit']); | ||
$utilsMock->expects($this->once()) | ||
->method('showMessageAndExit') | ||
->with($jsonValue); | ||
|
||
$correctHeaderSet = false; | ||
$utilsMock->method('setHeader')->willReturnCallback(function ($value) use (&$correctHeaderSet){ | ||
if (preg_match("@Content-Type:\s?application/json@i", $value)) { | ||
$correctHeaderSet = true; | ||
} | ||
}); | ||
|
||
$sut = new Response($utilsMock); | ||
$sut->responseAsJson($exampleData); | ||
|
||
$this->assertTrue($correctHeaderSet); | ||
} | ||
|
||
public function testRespondAsJavaScript(): void | ||
{ | ||
$exampleData = 'someJavaScriptCodeExample'; | ||
|
||
$utilsMock = $this->createPartialMock(Utils::class, ['setHeader', 'showMessageAndExit']); | ||
$utilsMock->expects($this->once()) | ||
->method('showMessageAndExit') | ||
->with($exampleData); | ||
|
||
$correctHeaderSet = false; | ||
$utilsMock->method('setHeader')->willReturnCallback(function ($value) use (&$correctHeaderSet){ | ||
if (preg_match("@Content-Type:\s?application/javascript@i", $value)) { | ||
$correctHeaderSet = true; | ||
} | ||
}); | ||
|
||
$sut = new Response($utilsMock); | ||
$sut->responseAsJavaScript($exampleData); | ||
|
||
$this->assertTrue($correctHeaderSet); | ||
} | ||
} |