context = new Context(); $this->teaRepositoryMock = $this->createMock(TeaRepository::class); // We need to create an accessible mock in order to be able to set the protected `view`. $methodsToMock = ['htmlResponse', 'redirect', 'redirectToUri']; if ((new Typo3Version())->getMajorVersion() <= 11) { $methodsToMock[] = 'forward'; } $this->subject = $this->getAccessibleMock( FrontEndEditorController::class, $methodsToMock, [$this->context, $this->teaRepositoryMock] ); $this->viewMock = $this->createMock(TemplateView::class); $this->subject->_set('view', $this->viewMock); $responseStub = $this->createStub(HtmlResponse::class); $this->subject->method('htmlResponse')->willReturn($responseStub); } /** * @param int<0, max> $userUid */ private function setUidOfLoggedInUser(int $userUid): void { $userAspectMock = $this->createMock(UserAspect::class); $userAspectMock->method('get')->with('id')->willReturn($userUid); $this->context->setAspect('frontend.user', $userAspectMock); } /** * @test */ public function isActionController(): void { self::assertInstanceOf(ActionController::class, $this->subject); } /** * @test */ public function indexActionForNoLoggedInUserAssignsNothingToView(): void { $this->setUidOfLoggedInUser(0); $this->viewMock->expects(self::never())->method('assign'); $this->subject->indexAction(); } /** * @test */ public function indexActionForLoggedInUserAssignsTeasOwnedByTheLoggedInUserToView(): void { $userUid = 5; $this->setUidOfLoggedInUser($userUid); $teas = $this->createMock(QueryResultInterface::class); $this->teaRepositoryMock->method('findByOwnerUid')->with($userUid)->willReturn($teas); $this->viewMock->expects(self::once())->method('assign')->with('teas', $teas); $this->subject->indexAction(); } /** * @test */ public function indexActionReturnsHtmlResponse(): void { $result = $this->subject->indexAction(); self::assertInstanceOf(HtmlResponse::class, $result); } }