Skip to content

Commit

Permalink
[TASK] Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Jul 7, 2024
1 parent 85f3803 commit 4ebec1a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Classes/Controller/AddressController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function showAction(?Address $address = null)

$this->view->assignMultiple([
'address' => $address,
'contentObjectData' => $this->configurationManager->getContentObject()->data,
'contentObjectData' => $this->request->getAttribute('currentContentObject', []),
]);
return $this->htmlResponse();
}
Expand All @@ -71,7 +71,7 @@ public function showAction(?Address $address = null)
*/
public function listAction(?array $override = [])
{
$contentData = $this->configurationManager->getContentObject()->data;
$contentData = $this->request->getAttribute('currentContentObject', []);
$demand = $this->createDemandFromSettings();

if (isset($contentData['first_name'], $contentData['birthday']) && (int) ($this->settings['insertRecord'] ?? 0) === 1) {
Expand Down
11 changes: 2 additions & 9 deletions Tests/Unit/Controller/AddressControllerPaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
use FriendsOfTYPO3\TtAddress\Domain\Repository\AddressRepository;
use TYPO3\CMS\Core\Pagination\PaginatorInterface;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Fluid\View\TemplateView;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\TestingFramework\Core\BaseTestCase;

Expand Down Expand Up @@ -64,18 +62,14 @@ public function listActionUsesNewPaginationWithArrayRecords()

$mockedRepository->expects(self::once())->method('getAddressesByCustomSorting')->willReturn($rows);

$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument', 'getAttribute'], [], '', false);
$mockedRequest->expects(self::once())->method('hasArgument')->with('currentPage')->willReturn(true);
$mockedRequest->expects(self::once())->method('getArgument')->with('currentPage')->willReturn(2);
$mockedRequest->expects(self::any())->method('getAttribute')->willReturn([]);

$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple', 'assign'], [], '', false);
$mockedView->expects(self::once())->method('assignMultiple')->with($assignments);

$mockContentObject = $this->createMock(ContentObjectRenderer::class);
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
$mockConfigurationManager->method('getContentObject')
->willReturn($mockContentObject);

$subject = $this->getAccessibleMock(AddressController::class, ['createDemandFromSettings', 'htmlResponse'], [], '', false);
$subject->expects(self::once())->method('createDemandFromSettings')->willReturn($demand);
$subject->expects(self::once())->method('htmlResponse');
Expand All @@ -84,7 +78,6 @@ public function listActionUsesNewPaginationWithArrayRecords()
$subject->_set('request', $mockedRequest);
$subject->_set('addressRepository', $mockedRepository);
$subject->_set('extensionConfiguration', $this->getMockedSettings());
$subject->_set('configurationManager', $mockConfigurationManager);

$subject->listAction();
}
Expand Down
40 changes: 19 additions & 21 deletions Tests/Unit/Controller/AddressControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,15 @@ public function showActionFillsView()
$address->setLastName('Doe');
$assigned = [
'address' => $address,
'contentObjectData' => [],
'contentObjectData' => null,
];
$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple'], [], '', false);
$mockedView->expects(self::once())->method('assignMultiple')->with($assigned);
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
$mockConfigurationManager->method('getContentObject')
->willReturn($mockContentObject);

$subject = $this->getAccessibleMock(AddressController::class, ['redirectToUri', 'htmlResponse'], [], '', false);
$subject->_set('view', $mockedView);
$subject->_set('configurationManager', $mockConfigurationManager);
$request = $this->getAccessibleMock(Request::class, ['getAttribute'], [], '', false);
$subject->_set('request', $request);
$subject->expects(self::once())->method('htmlResponse');

$subject->showAction($address);
Expand Down Expand Up @@ -248,11 +245,8 @@ public function listActionFillsViewForSingleRecords()

$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple', 'assign'], [], '', false);
$mockedView->expects(self::once())->method('assignMultiple')->with($assignments);
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
$mockConfigurationManager->method('getContentObject')
->willReturn($mockContentObject);
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument', 'getAttribute'], [], '', false);
$mockedRequest->expects(self::any())->method('getAttribute')->willReturn([]);

$subject = $this->getAccessibleMock(AddressController::class, ['createDemandFromSettings', 'htmlResponse'], [], '', false);
$subject->expects(self::once())->method('createDemandFromSettings')->willReturn($demand);
Expand All @@ -262,7 +256,6 @@ public function listActionFillsViewForSingleRecords()
$subject->_set('request', $mockedRequest);
$subject->_set('addressRepository', $mockedRepository);
$subject->_set('extensionConfiguration', $this->getMockedSettings());
$subject->_set('configurationManager', $mockConfigurationManager);

$subject->listAction();
}
Expand All @@ -281,16 +274,14 @@ public function listActionFillsViewForDemand()
$mockedRepository = $this->getAccessibleMock(AddressRepository::class, ['findByDemand'], [], '', false);
$mockedRepository->expects(self::once())->method('findByDemand')->willReturn(['dummy return']);
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
$mockConfigurationManager->method('getContentObject')
->willReturn($mockContentObject);
$assignments = [
'demand' => $demand,
'addresses' => ['dummy return'],
'contentObjectData' => [],
];

$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument', 'getAttribute'], [], '', false);
$mockedRequest->expects(self::any())->method('getAttribute')->willReturn([]);

$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple', 'assign'], [], '', false);
$mockedView->expects(self::once())->method('assignMultiple')->with($assignments);
Expand All @@ -303,7 +294,6 @@ public function listActionFillsViewForDemand()
$subject->_set('request', $mockedRequest);
$subject->_set('addressRepository', $mockedRepository);
$subject->_set('extensionConfiguration', $this->getMockedSettings());
$subject->_set('configurationManager', $mockConfigurationManager);

$subject->listAction();
}
Expand All @@ -313,19 +303,27 @@ public function listActionFillsViewForDemand()
*/
public function overrideDemandMethodIsCalledIfEnabled()
{
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument'], [], '', false);
$mockedRequest = $this->getAccessibleMock(Request::class, ['hasArgument', 'getArgument', 'getAttribute'], [], '', false);
$mockedRepository = $this->getAccessibleMock(AddressRepository::class, ['getAddressesByCustomSorting', 'findByDemand'], [], '', false);
$mockedRepository->expects(self::any())->method('findByDemand')->willReturn([]);
$mockedView = $this->getAccessibleMock(TemplateView::class, ['assignMultiple', 'assign'], [], '', false);
$mockedView->expects(self::once())->method('assignMultiple');
$mockContentObject = $this->createMock(ContentObjectRenderer::class);
$mockConfigurationManager = $this->createMock(ConfigurationManager::class);
$mockConfigurationManager->method('getContentObject')
->willReturn($mockContentObject);

$mockedRequest->expects(self::any())->method('getAttribute')->willReturn([]);

$mockedExtbaseRequest = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->getMock();
$mockedExtbaseRequest
->method('getAttribute')
->willReturn([]);

$subject = $this->getAccessibleMock(AddressController::class, ['overrideDemand', 'createDemandFromSettings', 'htmlResponse'], [], '', false);
$subject->_set('extensionConfiguration', $this->getMockedSettings());
$subject->_set('configurationManager', $mockConfigurationManager);
$subject->_set('request', $mockedExtbaseRequest);
// $subject->_set('configurationManager', $mockConfigurationManager);
$subject->expects(self::any())->method('overrideDemand');
$subject->expects(self::any())->method('htmlResponse');

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"license": "GPL-2.0-or-later",
"require": {
"typo3/cms-core": "^12.4 || ^13.2",
"typo3/cms-core": "^12.4.16 || ^13.2",
"php": ">=8.1",
"doctrine/dbal": "^3.8.1 || ^4.0.2",
"symfony/console": "^5.4 || ^6.0 || ^7.0"
Expand Down

0 comments on commit 4ebec1a

Please sign in to comment.