Skip to content

Commit

Permalink
Move tab parameter getter to UIRequest class
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Fedurtsya <[email protected]>
  • Loading branch information
Sieg committed Jan 8, 2024
1 parent 0e0ea9c commit 3c691ae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Application/Controller/Admin/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public function init()
*/
public function render()
{
$request = Registry::getRequest();

$uiRequest = $this->getService(UIRequestInterface::class);
$mediaRepository = $this->getService(MediaRepositoryInterface::class);
$this->addTplParam('iFileCount', $mediaRepository->getFolderMediaCount($uiRequest->getFolderId()));
Expand All @@ -62,7 +60,7 @@ public function render()
$this->addTplParam('sThumbsUrl', $this->imageResource->getThumbnailUrl());
$this->addTplParam('sFolderId', $uiRequest->getFolderId());
$this->addTplParam('sFoldername', $this->imageResource->getFolderName());
$this->addTplParam('sTab', $request->getRequestEscapedParameter('tab'));
$this->addTplParam('sTab', $uiRequest->getTabName());

$this->addTplParam('request', $uiRequest);

Expand Down
6 changes: 6 additions & 0 deletions src/Transput/RequestData/UIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UIRequest implements UIRequestInterface
public const REQUEST_PARAM_OVERLAY = 'overlay';
public const REQUEST_PARAM_POPUP = 'popout';
public const REQUEST_PARAM_MEDIA_LIST_START_INDEX = 'start';
public const REQUEST_PARAM_TAB = 'tab';

public function __construct(protected RequestInterface $request)
{
Expand All @@ -41,4 +42,9 @@ public function getMediaListStartIndex(): int
{
return $this->request->getIntRequestParameter(self::REQUEST_PARAM_MEDIA_LIST_START_INDEX);
}

public function getTabName(): string
{
return $this->request->getStringRequestParameter(self::REQUEST_PARAM_TAB);
}
}
2 changes: 2 additions & 0 deletions src/Transput/RequestData/UIRequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public function isPopout(): bool;
public function getFolderId(): string;

public function getMediaListStartIndex(): int;

public function getTabName(): string;
}
13 changes: 13 additions & 0 deletions tests/Unit/Transput/RequestData/UIRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ public function testGetFolderId(): void
$this->assertSame($requestExampleValue, $sut->getFolderId());
}

public function testGetTabName(): void
{
$requestExampleValue = uniqid();

$requestMock = $this->createMock(RequestInterface::class);
$requestMock->method('getStringRequestParameter')->willReturnMap([
[UIRequest::REQUEST_PARAM_TAB, '', $requestExampleValue]
]);

$sut = new UIRequest($requestMock);
$this->assertSame($requestExampleValue, $sut->getTabName());
}

public function testGetMediaListStartIndex(): void
{
$requestExampleValue = rand(0, 1000);
Expand Down

0 comments on commit 3c691ae

Please sign in to comment.