/** * @test */ public function getOutputContainsErrorReason() { $expected = 'Reason ' . uniqid(); /** @var \R3H6\Error404page\Domain\Model\Error $errorFixture */ $errorFixture = new Error(); $errorFixture->setReason($expected); $this->assertContains($expected, $this->subject->getOutput($errorFixture)); }
/** * @inherit */ public function getOutput(\R3H6\Error404page\Domain\Model\Error $error) { $title = 'Page not found'; $message = 'The page did not exist or was inaccessible.' . ($error->getReason() ? ' Reason: ' . htmlspecialchars($error->getReason()) : ''); /** @var \TYPO3\CMS\Core\Messaging\ErrorpageMessage $messagePage */ $messagePage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\ErrorpageMessage', $message, $title); return $messagePage->render(); }
/** * @test */ public function calculateCacheIdentifierRespectsCurrentUrlForForbiddenErrors() { /** @var \R3H6\Error404page\Domain\Model\Error $errorFixture */ $errorFixture = new Error(); $errorFixture->setStatusCode(Error::STATUS_CODE_FORBIDDEN); $cacheIdentifier1 = $this->subject->calculateCacheIdentifier($errorFixture); $errorFixture->setCurrentUrl('page/not/found.html'); $cacheIdentifier2 = $this->subject->calculateCacheIdentifier($errorFixture); $this->assertNotEquals($cacheIdentifier1, $cacheIdentifier2); }
/** * @inherit */ public function handleError(\R3H6\Error404page\Domain\Model\Error $error) { if ($error->getStatusCode() !== Error::STATUS_CODE_FORBIDDEN) { return false; } if (!$error->getPid()) { return false; } if ($this->frontendUser->isLoggedIn()) { return false; } /** @var \R3H6\Error404page\Configuration\PageTsConfig $pageTsConfig */ $pageTsConfig = $this->pageTsConfigManager->getPageTsConfig($error->getPid()); $parameter = (string) $pageTsConfig->get('redirectError403To'); if ($parameter === 'auto') { $loginPage = $this->pageRepository->findLoginPageForError($error); if ($loginPage !== null) { $parameter = (string) $loginPage->getUid(); } else { $parameter = null; } } if (MathUtility::canBeInterpretedAsInteger($parameter)) { $this->cacheTags[] = 'pageId_' . $parameter; if ($this->frontendController->isDefaultType() === false) { $parameter .= ',' . $this->frontendController->getType(); } if ($this->frontendController->isDefaultLanguage() === false || $this->frontendController->isDefaultGetVar('L') === true) { $parameter .= ' - - - &L=' . $this->frontendController->getSystemLanguageUid(); } } $this->getLogger()->debug(sprintf('Redirect parameter "%s"', $parameter)); if ($parameter) { $this->redirect = ''; $this->redirect .= $this->frontendController->typoLink(array('parameter' => $parameter, 'forceAbsoluteUrl' => true)); $this->redirect .= strpos($this->redirect, '?') === false ? '?' : '&'; $this->redirect .= 'redirect_url=' . $error->getUrl(); return true; } return false; }
/** * Calculates the cache identifier for a given error. * * @param Error $error * @return string sha1 */ public function calculateCacheIdentifier(Error $error) { $parts = array(); $parts[] = $error->getHost(); $parts[] = $error->getLanguage(); $parts[] = $error->getStatusCode(); $parts[] = join(',', (array) $this->frontendUser->getUserGroups()); if ($error->getStatusCode() === Error::STATUS_CODE_FORBIDDEN) { $parts[] = $error->getCurrentUrl(); } return sha1(join('---', $parts)); }
/** * @inherit */ public function getOutput(\R3H6\Error404page\Domain\Model\Error $error) { $replaceMap = array('###CURRENT_URL###' => $error->getCurrentUrl(), '###REASON###' => $error->getReasonText(), '###ERROR_STATUS_CODE###' => $error->getStatusCode()); return str_replace(array_keys($replaceMap), array_values($replaceMap), $this->output); }
/** * @test */ public function getOutputSubstituesMarkers() { /** @var \R3H6\Error404page\Domain\Model\Error $errorFixture */ $errorFixture = new Error(); $errorFixture->setCurrentUrl('http://www.typo3.org/page/not/found/'); $errorFixture->setReasonText('Test reason text'); $this->subject->setCachingData(' <h1>Page "###CURRENT_URL###" not found</h1> <p>###REASON###</p> '); $output = $this->subject->getOutput($errorFixture); $this->assertContains($errorFixture->getCurrentUrl(), $output); $this->assertContains($errorFixture->getReasonText(), $output); }
/** * [getErrorFixture description] * @return \R3H6\Error404page\Domain\Model\Error */ protected function getErrorFixture() { /** @var \R3H6\Error404page\Domain\Model\Error $errorFixture */ $errorFixture = new Error(); $errorFixture->setStatusCode(Error::STATUS_CODE_FORBIDDEN); $errorFixture->setPid(123); $errorFixture->setUrl('http://www.typo3.org/not/found/'); return $errorFixture; }
/** * Log error. * * @param \R3H6\Error404page\Domain\Model\Error $error */ public function log(Error $error) { $values = $error->toArray(); $this->getDatabaseConnection()->debugOutput = false; $count = $this->getDatabaseConnection()->exec_SELECTcountRows('*', self::$table); if ($count < self::MAX_ENTRIES) { $this->getDatabaseConnection()->exec_INSERTquery(self::$table, $values); if ($this->getDatabaseConnection()->sql_errno()) { unset($values['url_hash']); $this->getDatabaseConnection()->exec_INSERTquery(self::$table, $values); } } else { $row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid', self::$table, '1=1', '', 'tstamp ASC'); $this->getDatabaseConnection()->exec_UPDATEquery(self::$table, 'uid=' . $row['uid'], $values); if ($this->getDatabaseConnection()->sql_errno()) { unset($values['url_hash']); $this->getDatabaseConnection()->exec_UPDATEquery(self::$table, 'uid=' . $row['uid'], $values); } } }
/** * @return R3H6\Error404page\Domain\Model\Error */ protected function createError($host = 'www.typo3.org', $statusCode = Error::STATUS_CODE_NOT_FOUND, $pid = null) { /** @var \R3H6\Error404page\Domain\Model\Error $error */ $error = new Error(); $error->setStatusCode($statusCode); $error->setPid($pid); $error->setHost($host); return $error; }
/** * @test */ public function setUserAgentForStringSetsUserAgent() { $this->subject->setUserAgent('Conceived at T3CON10'); $this->assertAttributeEquals('Conceived at T3CON10', 'userAgent', $this->subject); }
/** * [find404PageForError description] * @param Error $error [description] * @return \R3H6\Error404page\Domain\Model\Page|null */ public function find404PageForError(Error $error) { $doktype = (int) $this->extensionConfiguration->get('doktypeError404page'); $page = $this->findFirstByHostAndDoktype($error->getHost(), $doktype); if ($page === null) { $page = $this->findFirstWithoutHostByDoktype($doktype); } return $page; }