From 1282190e63ae8199e47e12a47830b348edc70610 Mon Sep 17 00:00:00 2001 From: Christian Keuerleber Date: Mon, 25 Jul 2022 10:39:10 +0200 Subject: [PATCH] TASK: fix wget and git stuff after TYPO3 10 update --- Classes/Domain/Model/Page.php | 22 + Classes/Domain/Repository/PageRepository.php | 60 +- Classes/Utility/RealUrl.php | 120 ---- Classes/Utility/RealUrl/UrlDecoder.php | 54 -- Classes/Utility/Wget/WgetCommand.php | 628 ------------------ Classes/Utility/Wget/WgetLog.php | 103 --- Classes/Utility/Wget/WgetLogEntry.php | 186 ------ Classes/Utility/Wget/WgetLogParser.php | 202 ------ Tests/Functional/Utility/Wget/WgetTest.php | 134 ---- Tests/Unit/Utility/RealUrlTest_.php | 88 --- Tests/Unit/Utility/Wget/TestData/WgetTest.log | 57 -- Tests/Unit/Utility/Wget/WgetCommandTest.php | 77 --- Tests/Unit/Utility/Wget/WgetLogEntryTest.php | 57 -- Tests/Unit/Utility/Wget/WgetLogParsertest.php | 269 -------- Tests/Unit/Utility/Wget/WgetLogTest.php | 105 --- 15 files changed, 60 insertions(+), 2102 deletions(-) delete mode 100644 Classes/Utility/RealUrl.php delete mode 100644 Classes/Utility/RealUrl/UrlDecoder.php delete mode 100644 Classes/Utility/Wget/WgetCommand.php delete mode 100644 Classes/Utility/Wget/WgetLog.php delete mode 100644 Classes/Utility/Wget/WgetLogEntry.php delete mode 100644 Classes/Utility/Wget/WgetLogParser.php delete mode 100755 Tests/Functional/Utility/Wget/WgetTest.php delete mode 100755 Tests/Unit/Utility/RealUrlTest_.php delete mode 100644 Tests/Unit/Utility/Wget/TestData/WgetTest.log delete mode 100755 Tests/Unit/Utility/Wget/WgetCommandTest.php delete mode 100644 Tests/Unit/Utility/Wget/WgetLogEntryTest.php delete mode 100644 Tests/Unit/Utility/Wget/WgetLogParsertest.php delete mode 100644 Tests/Unit/Utility/Wget/WgetLogTest.php diff --git a/Classes/Domain/Model/Page.php b/Classes/Domain/Model/Page.php index 9932be4a..9b5efb6e 100644 --- a/Classes/Domain/Model/Page.php +++ b/Classes/Domain/Model/Page.php @@ -57,6 +57,11 @@ class Page extends AbstractEntity */ protected $doktype; + /** + * @var string + */ + protected $slug; + /** * @param string $module */ @@ -119,4 +124,21 @@ public function getDoktype() { return $this->doktype; } + + /** + * @return string + */ + public function getSlug(): string + { + return $this->slug; + } + + /** + * @param string $slug + * @return Page + */ + public function setSlug(string $slug) + { + $this->slug = $slug; + } } diff --git a/Classes/Domain/Repository/PageRepository.php b/Classes/Domain/Repository/PageRepository.php index 8bb34fd1..f94124ec 100755 --- a/Classes/Domain/Repository/PageRepository.php +++ b/Classes/Domain/Repository/PageRepository.php @@ -1,30 +1,32 @@ -* All rights reserved -* -* This script is part of the TYPO3 project. The TYPO3 project is -* free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* The GNU General Public License can be found at -* http://www.gnu.org/copyleft/gpl.html. -* -* This script is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* This copyright notice MUST APPEAR in all copies of the script! -***************************************************************/ + * Copyright notice + * + * (c) 2010-2012 Daniel Lienert + * All rights reserved + * + * This script is part of the TYPO3 project. The TYPO3 project is + * free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * The GNU General Public License can be found at + * http://www.gnu.org/copyleft/gpl.html. + * + * This script is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This copyright notice MUST APPEAR in all copies of the script! + ***************************************************************/ /** * Repository for Pages @@ -61,7 +63,7 @@ public function findPagesInPid($pid) $pages = $query->matching( $query->equals('pid', $pid) ) - ->execute(); + ->execute(); return $pages; } @@ -124,4 +126,18 @@ protected function getSubpagesOfUid($uid, $respectEnableFields, $respectDeletedF return $returnArray; } + + /** + * @param string $slug + * @return array|null + */ + public function findOneBySlug(string $slug): ?Page + { + $query = $this->createQuery(); + return $query->matching( + $query->equals('slug', $slug) + ) + ->execute() + ->getFirst(); + } } diff --git a/Classes/Utility/RealUrl.php b/Classes/Utility/RealUrl.php deleted file mode 100644 index 918ef048..00000000 --- a/Classes/Utility/RealUrl.php +++ /dev/null @@ -1,120 +0,0 @@ - - * - * This script is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use PunktDe\PtExtbase\Utility\RealUrl\UrlDecoder; -use TYPO3\CMS\Core\SingletonInterface; -use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; -use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; - -/** - * Real URL - * - * @package PunktDe\PtExtbase\Utility - */ -class RealUrl implements SingletonInterface -{ - - /** - * @var UrlDecoder - */ - protected $urlDecoder; - - /** - * @var ObjectManagerInterface - */ - protected $objectManager; - - /** - * @param ObjectManagerInterface $objectManager - */ - public function injectObjectManager(ObjectManagerInterface $objectManager): void - { - $this->objectManager = $objectManager; - } - - - /** - * Map path to page ID - * - * Path is the URL - * - without domain - * - without file suffix - * - separated by slash - * - * E.g.: - * - URL: http://www.kubrick.co.uk/film/aclockworkorange.html - * - Path: film/aclockworkorange - * - * @param string $path - * @return integer - */ - public function mapPathToPageId($path) - { - $this->initializeFrontendToMakeRealUrlWork(); - - $this->urlDecoder = $this->objectManager->get(UrlDecoder::class); - - $pageId = $this->urlDecoder->decodePathAndReturnPageId($path); - - return $pageId; - } - - - - /** - * @return void - */ - protected function initializeFrontendToMakeRealUrlWork() - { - $GLOBALS['TSFE'] = $this->objectManager->get(TypoScriptFrontendController::class, $GLOBALS['TYPO3_CONF_VARS'], 0, 0); - } - - - - /** - * Map URL to page ID - * - * URL can be - * 1. with scheme: http://www.kubrick.co.uk/film/aclockworkorange.html - * 2. without scheme: www.kubrick.co.uk/film/aclockworkorange.html - * - * @param string $url - * @return integer - */ - public function mapUrlToPageId($url) - { - return $this->mapPathToPageId($this->filterPathFromUrl($url)); - } - - - - /** - * @param string $url - * @return string - */ - public function filterPathFromUrl($url) - { - preg_match('|^(?:[a-z][a-z0-9+\-.]*:(?://[^/?#]+)?)?(?:[^/]+)?([a-z0-9\-._~!$&()*+,;=:@/]*?)\.html?|', $url, $matches); - return ltrim($matches[1], "/"); - } -} diff --git a/Classes/Utility/RealUrl/UrlDecoder.php b/Classes/Utility/RealUrl/UrlDecoder.php deleted file mode 100644 index 646062ba..00000000 --- a/Classes/Utility/RealUrl/UrlDecoder.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * This script is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -class UrlDecoder extends RealUrlDecoder -{ - - public function __construct() - { - parent::__construct(); - unset($this->siteScript); - - if ($this->tsfe === null) { - $this->tsfe = $GLOBALS['TSFE']; - } - if ($this->emptySegmentValue === null) { - $this->initialize(); - } - } - - /** - * @param string $path - * @return integer - */ - public function decodePathAndReturnPageId($path) - { - $result = $this->doDecoding($path); - - return $result->getPageId(); - } - -} \ No newline at end of file diff --git a/Classes/Utility/Wget/WgetCommand.php b/Classes/Utility/Wget/WgetCommand.php deleted file mode 100644 index 9b790021..00000000 --- a/Classes/Utility/Wget/WgetCommand.php +++ /dev/null @@ -1,628 +0,0 @@ - - * - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - - -class WgetCommand -{ - /** - * A list of allowed wget command arguments - * - * @var array - */ - protected $argumentMap = [ - 'noCheckCertificate' => '--no-check-certificate', - 'convertLinks' => '--convert-links', - 'saveCookies' => '--save-cookies=\'%s\'', - 'loadCookies' => '--load-cookies=\'%s\'', - 'keepSessionCookies' => '--keep-session-cookies', - 'execute' => '--execute \'%s\'', - 'tries' => '--tries=\'%s\'', - 'retryConnRefused' => '--retry-connrefused', - 'serverResponse' => '--server-response', - 'directoryPrefix' => '--directory-prefix=\'%s\'', - 'domains' => '--domains=\'%s\'', - 'pageRequisites' => '--page-requisites', - 'outputFile' => '--output-file=\'%s\'', - 'quiet' => '--quiet', - 'outputDocument' => '--output-document=\'%s\'', - 'postData' => '--post-data=\'%s\'', - 'postFile' => '--post-file=\'%s\'', - 'noVerbose' => '--no-verbose', - 'recursive' => '--recursive', - 'noParent' => '--no-parent', - 'noProxy' => '--no-proxy', - 'useProxy' => '-e use_proxy=\'%s\'', - 'httpProxy' => '-e http_proxy=\'%s\'', - 'httpsProxy' => '-e https_proxy=\'%s\'', - ]; - - /** - * @var string - */ - protected $wgetBinaryPath = 'wget'; - - - /** - * @var string - */ - protected $url; - - - /** - * @var Boolean - */ - protected $noCheckCertificate; - - - /** - * @var Boolean - */ - protected $convertLinks; - - - /** - * Save cookies to file before exiting. This will not save cookies that have expired - * or that have no expiry time (so-called “session cookies”), but also see ‘--keep-session-cookies’. - * - * @var string - */ - protected $saveCookies; - - - /** - * Load cookies from file before the first HTTP retrieval. - * - * @var string - */ - protected $loadCookies; - - - /** - * When specified, causes ‘--save-cookies’ to also save session cookies. - * Session cookies are normally not saved because they are meant to be kept in memory - * and forgotten when you exit the browser. - * - * @var Boolean - */ - protected $keepSessionCookies; - - - /** - * @var Integer - */ - protected $tries; - - - /** - * Execute command as if it were a part of .wgetrc - * - * @var string - */ - protected $execute; - - - /** - * Consider “connection refused” a transient error and try again. - * Normally Wget gives up on a URL when it is unable to connect to the site because - * failure to connect is taken as a sign that the server is not running at all and that retries would not help. - * This option is for mirroring unreliable sites whose servers tend to disappear for short periods of time. - * - * @var Boolean - */ - protected $retryConnRefused; - - - /** - * Print the headers sent by HTTP servers and responses sent by FTP servers. - * - * @var Boolean - */ - protected $serverResponse; - - - /** - * @var String - */ - protected $directoryPrefix; - - - /** - * @var String - */ - protected $domains; - - - /** - * This option causes Wget to download all the files that are necessary to properly display a given HTML page. - * This includes such things as inlined images, sounds, and referenced stylesheets. - * - * @var String - */ - protected $pageRequisites; - - - /** - * The log File Path - * - * @var string - */ - protected $outputFile; - - - /** - * The documents will not be written to the appropriate files, - * but all will be concatenated together and written to file. - * - * @var string - */ - protected $outputDocument; - - /** - * @var Boolean - */ - protected $quiet; - - - /** - * @var string - */ - protected $postData; - - - /** - * @var string - */ - protected $postFile; - - - /** - * Turn off verbose without being completely quiet (use ‘-q’ for that), - * which means that error messages and basic information still get printed. - * - * @var Boolean - */ - protected $noVerbose = true; - - /** - * @var boolean - */ - protected $recursive; - - - /** - * @var boolean - */ - protected $noParent; - - - /** - * @var boolean - */ - protected $noProxy; - - - /** - * @var boolean - */ - protected $useProxy; - - - /** - * @var string - */ - protected $httpProxy; - - - /** - * @var string - */ - protected $httpsProxy; - - - /** - * @var Logger - */ - protected $logger; - - /** - * @param Logger $logger - */ - public function injectLogger(Logger $logger): void - { - $this->logger = $logger; - } - - /** - * @param string $wgetBinaryPath - * @return $this - */ - public function setWgetBinaryPath($wgetBinaryPath) - { - $this->wgetBinaryPath = $wgetBinaryPath; - return $this; - } - - /** - * @param string $url - * @return $this - */ - public function setUrl($url) - { - $this->url = $url; - return $this; - } - - - /** - * @param String $directoryPrefix - * @return $this - */ - public function setDirectoryPrefix($directoryPrefix) - { - $this->directoryPrefix = $directoryPrefix; - return $this; - } - - - /** - * @param boolean $convertLinks - * @return $this - */ - public function setConvertLinks($convertLinks) - { - $this->convertLinks = $convertLinks; - return $this; - } - - - /** - * @param string $outputFile - * @return $this - */ - public function setOutputFile($outputFile) - { - $this->outputFile = $outputFile; - return $this; - } - - - /** - * @param String $domains - * @return $this - */ - public function setDomains($domains) - { - $this->domains = $domains; - return $this; - } - - - /** - * @param string $execute - * @return $this - */ - public function setExecute($execute) - { - $this->execute = $execute; - return $this; - } - - - /** - * @param Boolean $keepSessionCookies - * @return $this - */ - public function setKeepSessionCookies($keepSessionCookies) - { - $this->keepSessionCookies = $keepSessionCookies; - return $this; - } - - - /** - * @param boolean $noCheckCertificate - * @return $this - */ - public function setNoCheckCertificate($noCheckCertificate) - { - $this->noCheckCertificate = $noCheckCertificate; - return $this; - } - - - /** - * @param Boolean $pageRequisites - * @return $this - */ - public function setPageRequisites($pageRequisites) - { - $this->pageRequisites = $pageRequisites; - return $this; - } - - - /** - * @param boolean $retryConnRefused - * @return $this - */ - public function setRetryConnRefused($retryConnRefused) - { - $this->retryConnRefused = $retryConnRefused; - return $this; - } - - - /** - * @param string $saveCookies - * @return $this - */ - public function setSaveCookies($saveCookies) - { - $this->saveCookies = $saveCookies; - return $this; - } - - - - /** - * @param boolean $serverResponse - * @return $this - */ - public function setServerResponse($serverResponse) - { - $this->serverResponse = $serverResponse; - return $this; - } - - - /** - * @param int $tries - * @return $this - */ - public function setTries($tries) - { - $this->tries = $tries; - return $this; - } - - - /** - * @param String $loadCookies - * @return $this - */ - public function setLoadCookies($loadCookies) - { - $this->loadCookies = $loadCookies; - return $this; - } - - /** - * @param Boolean $quiet - * @return $this - */ - public function setQuiet($quiet) - { - $this->quiet = $quiet; - return $this; - } - - /** - * @param string $outputDocument - * @return $this - */ - public function setOutputDocument($outputDocument) - { - $this->outputDocument = $outputDocument; - return $this; - } - - - /** - * @param string $postData - * @return $this - */ - public function setPostData($postData) - { - $this->postData = $postData; - return $this; - } - - - /** - * Set The post data from a key-value array - * - * @param array $postData - * @return $this - */ - public function setPostDataAsArray(array $postData) - { - $keyValues = []; - - foreach ($postData as $key => $value) { - $keyValues[] = "$key=$value"; - } - - $this->setPostData(implode('&', $keyValues)); - - return $this; - } - - - /** - * @param string $postFile - * @return $this - */ - public function setPostFile($postFile) - { - $this->postFile = $postFile; - return $this; - } - - - /** - * @param boolean $noVerbose - * @return $this - */ - public function setNoVerbose($noVerbose) - { - $this->noVerbose = $noVerbose; - return $this; - } - - /** - * @return boolean - */ - public function isNoVerbose() - { - return $this->noVerbose; - } - - - /** - * @return string - */ - public function getOutputFile() - { - return $this->outputFile; - } - - - /** - * @param boolean $recursive - * @return $this - */ - public function setRecursive($recursive) - { - $this->recursive = $recursive; - return $this; - } - - /** - * @param boolean $noParent - * @return $this - */ - public function setNoParent($noParent) - { - $this->noParent = $noParent; - return $this; - } - - /** - * @param boolean $noProxy - * @return $this - */ - public function setNoProxy($noProxy) - { - $this->noProxy = $noProxy; - return $this; - } - - /** - * @param boolean $useProxy - * @return $this - */ - public function setUseProxy($useProxy) - { - $this->useProxy = $useProxy; - return $this; - } - - /** - * @param string $httpProxy - * @return $this - */ - public function setHttpProxy($httpProxy) - { - $this->httpProxy = $httpProxy; - return $this; - } - - /** - * @param string $httpsProxy - * @return $this - */ - public function setHttpsProxy($httpsProxy) - { - $this->httpsProxy = $httpsProxy; - return $this; - } - - - - /** - * @return string - */ - protected function buildCommand() - { - $arguments = []; - - foreach ($this->argumentMap as $propertyName => $argumentTemplate) { - if (property_exists($this, $propertyName) && !empty($this->$propertyName) && $this->$propertyName !== false) { - if (stristr($argumentTemplate, '%s') === false) { - $arguments[] = $argumentTemplate; - } else { - $arguments[] = sprintf($argumentTemplate, $this->$propertyName); - } - } - } - - return sprintf('%s %s %s', $this->wgetBinaryPath, implode(' ', $arguments), escapeshellarg($this->url)); - - } - - /** - * @return string - */ - public function getCommand() - { - return $this->buildCommand(); - } - - - /** - * Executes the wget command - * - * @return string - */ - public function execute() - { - $command = $this->buildCommand(); - TimeTracker::start($command); - - $this->logger->debug('Executing WGet command ' . $command, __CLASS__); - - exec($command, $outputLines, $returnVar); - - $this->logger->debug('Called WGet command returned status ' . $returnVar, __CLASS__, ['time' => TimeTracker::stop($command)]); - - return implode('\n', $outputLines); - } -} diff --git a/Classes/Utility/Wget/WgetLog.php b/Classes/Utility/Wget/WgetLog.php deleted file mode 100644 index 1860c6bd..00000000 --- a/Classes/Utility/Wget/WgetLog.php +++ /dev/null @@ -1,103 +0,0 @@ - - * - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -namespace PunktDe\PtExtbase\Utility\Wget; - -class WgetLog extends \PunktDe\PtExtbase\Collection\ObjectCollection -{ - /** - * @var string - */ - protected $restrictedClassName = '\PunktDe\PtExtbase\Utility\Wget\WgetLogEntry'; - - - /** - * @param WgetLogEntry $wgetLogEntry - * @throws \PunktDe\PtExtbase\Exception\InternalException - */ - public function addLogEntry(WgetLogEntry $wgetLogEntry) - { - $this->addItem($wgetLogEntry); - } - - - /** - * @return bool - */ - public function hasErrors() - { - return $this->getErrors()->count() > 0 ?: false; - } - - - /** - * @return WgetLog - */ - public function getErrors() - { - $errorEntries = new WgetLog(); - - foreach ($this->itemsArr as $wgetLogEntry) { /** @var \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry $wgetLogEntry */ - if ($wgetLogEntry->isError()) { - $errorEntries->addLogEntry($wgetLogEntry); - } - } - - return $errorEntries; - } - - - /** - * @return WgetLog - */ - public function getSuccessful() - { - $sucessfulEntries = new WgetLog(); - - foreach ($this->itemsArr as $wgetLogEntry) { /** @var \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry $wgetLogEntry */ - if (!$wgetLogEntry->isError()) { - $sucessfulEntries->addLogEntry($wgetLogEntry); - } - } - - return $sucessfulEntries; - } - - - /** - * @return array - */ - public function toArray() - { - $logArray = []; - - foreach ($this->itemsArr as $logEntry) { /** @var \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry $logEntry */ - $logArray[] = $logEntry->toArray(); - } - - return $logArray; - } -} diff --git a/Classes/Utility/Wget/WgetLogEntry.php b/Classes/Utility/Wget/WgetLogEntry.php deleted file mode 100644 index d493f7d2..00000000 --- a/Classes/Utility/Wget/WgetLogEntry.php +++ /dev/null @@ -1,186 +0,0 @@ - - * - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -namespace PunktDe\PtExtbase\Utility\Wget; - -class WgetLogEntry -{ - /** - * Defines which status codes are errors - * - * @var array - */ - protected $errorStatusPattern = '[4,5]..'; - - - /** - * @var \DateTime - */ - protected $fetchDate; - - - /** - * @var string - */ - protected $url; - - - /** - * @var integer - */ - protected $status; - - - /** - * @var string - */ - protected $contentType; - - - /** - * @var integer - */ - protected $contentLength; - - /** - * @return int - */ - public function getContentLength() - { - return $this->contentLength; - } - - /** - * @param int $contentLength - */ - public function setContentLength($contentLength) - { - $this->contentLength = $contentLength; - } - - /** - * @return string - */ - public function getContentType() - { - return $this->contentType; - } - - /** - * @param string $contentType - */ - public function setContentType($contentType) - { - $this->contentType = $contentType; - } - - /** - * @return \DateTime - */ - public function getFetchDate() - { - return $this->fetchDate; - } - - /** - * @param \DateTime $fetchDate - */ - public function setFetchDate($fetchDate) - { - $this->fetchDate = $fetchDate; - } - - /** - * @return string - */ - public function getStatus() - { - return $this->status; - } - - /** - * @param string $status - */ - public function setStatus($status) - { - $this->status = $status; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - */ - public function setUrl($url) - { - $this->url = $url; - } - - /** - * @return array - */ - public function getErrorStatusPattern() - { - return $this->errorStatusPattern; - } - - /** - * @param array $errorStatusPatterns - */ - public function setErrorStatusPattern($errorStatusPatterns) - { - $this->errorStatusPattern = $errorStatusPatterns; - } - - - /** - * @return bool - */ - public function isError() - { - return preg_match(sprintf('/%s/', $this->errorStatusPattern), (string) $this->status) != 0 ?: false; - } - - - /** - * @return array - */ - public function toArray() - { - return [ - 'date' => $this->getFetchDate(), - 'url' => $this->getUrl(), - 'status' => $this->getStatus(), - 'length' => $this->getContentLength() - ]; - } -} diff --git a/Classes/Utility/Wget/WgetLogParser.php b/Classes/Utility/Wget/WgetLogParser.php deleted file mode 100644 index e731c805..00000000 --- a/Classes/Utility/Wget/WgetLogParser.php +++ /dev/null @@ -1,202 +0,0 @@ - - * - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -namespace PunktDe\PtExtbase\Utility\Wget; - -use TYPO3\CMS\Extbase\Object\ObjectManager; - -class WgetLogParser -{ - /** - * @var WgetCommand - */ - protected $wgetCommand; - - /** - * @var ObjectManager - */ - protected $objectManager; - - /** - * @param ObjectManager $objectManager - */ - public function injectObjectManager(ObjectManager $objectManager): void - { - $this->objectManager = $objectManager; - } - - - public function parseLog(WgetCommand $wgetCommand) - { - $this->checkAndSetWgetCommand($wgetCommand); - - return $this->buildLogFileEntryArray($this->readLogFileContent()); - } - - - - /** - * @param WgetCommand $wgetCommand - * @throws \Exception - */ - protected function checkAndSetWgetCommand(WgetCommand $wgetCommand) - { - if ($wgetCommand->isNoVerbose() === false) { - throw new \Exception('The wget command was not set to no-verbose, which is needed to parse the log file.', 1422353522); - } - - if ($wgetCommand->getOutputFile() === '') { - throw new \Exception('The output file was not set for the wget command which is needed to parse the log file.', 1422353523); - } - - $this->wgetCommand = $wgetCommand; - } - - - /** - * @return string - * @throws \Exception - */ - protected function readLogFileContent() - { - if (!file_exists($this->wgetCommand->getOutputFile()) || !is_readable($this->wgetCommand->getOutputFile())) { - throw new \Exception(sprintf('The log file %s could not be read.', $this->wgetCommand->getOutputFile()), 1422438059); - } - - $content = trim(file_get_contents($this->wgetCommand->getOutputFile())); - - if ($content == '') { - throw new \Exception(sprintf('No content could be read from logfile %s.', $this->wgetCommand->getOutputFile()), 1423154366); - } - - return $content; - } - - - /** - * @param $logFileContent - * @return WgetLog - */ - protected function buildLogFileEntryArray($logFileContent) - { - $logFileContent = $this->removeLeadingWarnings($logFileContent); - - $structuredLogFileEntries = $this->splitLogFileEntries($logFileContent); - - $wgetLog = $this->objectManager->get('PunktDe\PtExtbase\Utility\Wget\WgetLog'); /** @var \PunktDe\PtExtbase\Utility\Wget\WgetLog $wgetLog */ - - foreach ($structuredLogFileEntries as $structuredLogFileEntry) { - $wgetLog->addLogEntry($this->buildLogFileEntry($structuredLogFileEntry)); - } - - return $wgetLog; - } - - - /** - * @param $structuredLogEntry - * @throws \Exception - * @return WgetLogEntry - */ - protected function buildLogFileEntry($structuredLogEntry) - { - $wgetLogEntry = $this->objectManager->get('PunktDe\PtExtbase\Utility\Wget\WgetLogEntry'); /** @var WgetLogEntry $wgetLogEntry */ - - preg_match('/([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})\s(URL|ERROR)/', $structuredLogEntry['body'], $matches); - $wgetLogEntry->setFetchDate(\DateTime::createFromFormat('Y-m-d H:i:s', $matches[1])); - - - preg_match('/(?https?:\/\/\S+)/', $structuredLogEntry['body'], $matches); - - if ($matches['url'] == '') { - throw new \Exception('The url could not be found in the log entry: ' . print_r($structuredLogEntry, 1), 1423154556); - } - - $wgetLogEntry->setUrl(rtrim($matches['url'], ':')); - - preg_match('/HTTP\/[0-9,\.]+\s(?\d+).*/', $structuredLogEntry['status'], $matches); - $wgetLogEntry->setStatus((int) $matches['status']); - - preg_match('/Content-Type:\s(?.*)/', $structuredLogEntry['body'], $matches); - $wgetLogEntry->setContentType($matches['contentType']); - - preg_match('/Content-Length:\s(?.*)/', $structuredLogEntry['body'], $matches); - $wgetLogEntry->setContentLength((int) $matches['contentLength']); - - return $wgetLogEntry; - } - - - /** - * Checks - * @param $structuredLogEntry - * @return bool - */ - protected function isSummary($structuredLogEntry) - { - if (preg_match('/FINISHED --[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}--/', $structuredLogEntry['body']) === 1) { - return true; - } else { - return false; - } - } - - - /** - * @param $logFileContent - * @return array - */ - protected function splitLogFileEntries($logFileContent) - { - $logEntryArray = preg_split('/(HTTP\/[1|2]\.[1|0]\s\d{3}\s\w*)/', trim($logFileContent), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - - $structuredLogEntryArray = []; - - foreach ($logEntryArray as $key => $entry) { - if ($key % 2 === 0) { - $structuredLogEntryArray[$key]['status'] = trim($entry); - } else { - $structuredLogEntryArray[$key-1]['body'] = trim($entry); - } - } - - return $structuredLogEntryArray; - } - - /** - * For the log parser to work, the very first line has to start with ' HTTP/' - * - * @param $logFileContent - * - * @return string - */ - protected function removeLeadingWarnings($logFileContent) - { - $logFileContent = substr($logFileContent, strpos($logFileContent, 'HTTP')); - - return $logFileContent; - } -} diff --git a/Tests/Functional/Utility/Wget/WgetTest.php b/Tests/Functional/Utility/Wget/WgetTest.php deleted file mode 100755 index 08f1bb08..00000000 --- a/Tests/Functional/Utility/Wget/WgetTest.php +++ /dev/null @@ -1,134 +0,0 @@ - - * - * This script is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use PunktDe\PtExtbase\Exception\InternalException; -use PunktDe\PtExtbase\Logger\Logger; -use PunktDe\PtExtbase\Testing\Unit\AbstractBaseTestcase; -use Neos\Utility\Files; -use PunktDe\PtExtbase\Utility\Wget\WgetCommand; -use PunktDe\PtExtbase\Utility\Wget\WgetLogEntry; -use PunktDe\PtExtbase\Utility\Wget\WgetLogParser; -use TYPO3\CMS\Core\Core\Environment; -use TYPO3\CMS\Core\Log\LogManager; -use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Object\Container\Container as ExtbaseContainer; -use TYPO3\CMS\Extbase\Object\ObjectManager; -use TYPO3\TestingFramework\Core\Testbase; - -class WgetTest extends AbstractBaseTestcase -{ - /** - * @var string - */ - protected $workingDirectory = ''; - - - /** - * @var WgetCommand - */ - protected $wgetCommand; - - - /** - * @var WgetLogParser - */ - protected $wgetLogParser; - - - /** - * @throws \Exception - */ - public function setUp(): void - { - $instancePath = Environment::getCurrentScript(); - - $testbase = new Testbase(); - $container = $testbase->setUpBasicTypo3Bootstrap($instancePath); - $extbaseContainer = GeneralUtility::getContainer()->get(ExtbaseContainer::class); - - $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class, $container, $extbaseContainer); - - $this->workingDirectory = Files::concatenatePaths([__DIR__, 'WorkingDirectory']); - Files::createDirectoryRecursively($this->workingDirectory); - - $this->wgetCommand = GeneralUtility::makeInstance(WgetCommand::class); - - $logger = GeneralUtility::makeInstance(Logger::class); - $logger->injectLoggerManager(GeneralUtility::makeInstance(LogManager::class)); - $this->wgetCommand->injectLogger($logger); - - $this->wgetLogParser = $this->objectManager->get(WgetLogParser::class); - } - - - /** - * @throws \Exception - */ - public function tearDown(): void - { - Files::removeDirectoryRecursively($this->workingDirectory); - } - - - /** - * @test - * @throws InternalException - */ - public function downloadNotExistingPageAndDetectErrors() - { - $this->wgetCommand->setOutputFile(Files::concatenatePaths([$this->workingDirectory, 'wget.log'])) - ->setDirectoryPrefix($this->workingDirectory) - ->setNoVerbose(true) - ->setServerResponse(true) - ->setUrl('http://localhost/not-existing-file.html') - ->execute(); - - $log = $this->wgetLogParser->parseLog($this->wgetCommand); - - $this->assertTrue($log->hasErrors()); - $this->assertCount(1, $log); - - $logEntry = $log->getItemByIndex(0); /** @var WgetLogEntry $logEntry */ - - $this->assertEquals(404, $logEntry->getStatus()); - $this->assertEquals('http://localhost/not-existing-file.html', $logEntry->getUrl()); - } - - /** - * @test - */ - public function downloadExistingPage() - { - $this->wgetCommand->setOutputFile(Files::concatenatePaths([$this->workingDirectory, 'wget.log'])) - ->setDirectoryPrefix($this->workingDirectory) - ->setNoVerbose(true) - ->setServerResponse(true) - ->setUrl('http://example.com/') - ->execute(); - - $log = $this->wgetLogParser->parseLog($this->wgetCommand); - - $this->assertFalse($log->hasErrors()); - $this->assertFileExists(Files::concatenatePaths([$this->workingDirectory, 'index.html'])); - } -} diff --git a/Tests/Unit/Utility/RealUrlTest_.php b/Tests/Unit/Utility/RealUrlTest_.php deleted file mode 100755 index 69dc9624..00000000 --- a/Tests/Unit/Utility/RealUrlTest_.php +++ /dev/null @@ -1,88 +0,0 @@ - - * - * This script is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -use \TYPO3\TestingFramework\Core\Unit\UnitTestCase; - -/** - * Real URL Test Case - * - * @package pt_extbase - * @subpackage PunktDe\PtExtbase\Tests\Unit\Utility - */ -class RealUrlTest extends UnitTestCase -{ - /** - * @var \PunktDe\PtExtbase\Utility\RealUrl - */ - protected $proxy; - - - - /** - * @return void - */ - public function setUp() - { - $proxyClass = $this->buildAccessibleProxy('PunktDe\PtExtbase\Utility\RealUrl'); - $this->proxy = new $proxyClass(); - } - - - - /** - * @return array - */ - public function filterPathFromUrlReturnsValidPathDataProvider() - { - return [ - 'urlWithSchemeAndDomain' => [ - 'url' => 'http://www.kubrick.co.uk/a/clockwork/orange.html', - 'expected' => 'a/clockwork/orange' - ], - 'urlWithoutSchemeAndWithDomain' => [ - 'url' => 'www.kubrick.co.uk/a/clockwork/orange.html', - 'expected' => 'a/clockwork/orange' - ], - 'urlWithoutSchemeWithDomainWithHtmSuffix' => [ - 'url' => 'www.kubrick.co.uk/a/clockwork/orange.htm', - 'expected' => 'a/clockwork/orange' - ], - ]; - } - - - - /** - * @test - * @dataProvider filterPathFromUrlReturnsValidPathDataProvider - * - * @param string $url - * @param string $expected - */ - public function filterPathFromUrlReturnsValidPath($url, $expected) - { - - $actual = $this->proxy->filterPathFromUrl($url); - $this->assertSame($expected, $actual); - } -} diff --git a/Tests/Unit/Utility/Wget/TestData/WgetTest.log b/Tests/Unit/Utility/Wget/TestData/WgetTest.log deleted file mode 100644 index 20a3532d..00000000 --- a/Tests/Unit/Utility/Wget/TestData/WgetTest.log +++ /dev/null @@ -1,57 +0,0 @@ - HTTP/1.1 200 OK - Server: Apache/2.4.6 (Red Hat) - Last-Modified: Wed, 09 Jul 2014 09:08:45 GMT - X-Page-is-cacheable: 1 - Vary: Accept-Encoding,User-Agent - Content-Type: text/html; charset=utf-8 - Content-Length: 3951 - Date: Thu, 26 Feb 2015 10:50:40 GMT - X-Varnish: 800975658 - Age: 0 - Via: 1.1 varnish - Connection: close - Cache-Control: no-cache, no-store, must-revalidate - Expires: 0 - Pragma: no-cache -2015-02-26 11:50:40 URL:https://test.de/data-ok.html [18845] -> "/var/www/html/htdocs/fileadmin/Archive/Data/test.de/data-ok.html" [1] - HTTP/1.1 404 Not Found - Server: Apache/2.4.6 (Red Hat) - Content-Type: text/html; charset=iso-8859-1 - Content-Length: 275 - Accept-Ranges: bytes - Date: Thu, 26 Feb 2015 10:50:57 GMT - X-Varnish: 800975747 - Age: 0 - Via: 1.1 varnish - Connection: keep-alive -https://test.de/typo3conf/jquery.selectBox-arrow.gif: -2015-02-26 11:50:57 ERROR 404: Not Found. - HTTP/1.1 200 OK - Server: Apache/2.4.6 (Red Hat) - Last-Modified: Wed, 09 Jul 2014 09:08:46 GMT - X-Page-is-cacheable: 1 - Vary: Accept-Encoding,User-Agent - Content-Type: text/html; charset=utf-8 - Content-Length: 1000 - Date: Thu, 26 Feb 2015 10:50:58 GMT - X-Varnish: 800975658 - Age: 0 - Via: 1.1 varnish - Connection: close - Cache-Control: no-cache, no-store, must-revalidate - Expires: 0 - Pragma: no-cache -2015-02-26 11:50:40 URL:https://test.de/data-ok2.html [18845] -> "/var/www/html/htdocs/fileadmin/Archive/Data/test.de/data-ok2.html" [1] - HTTP/1.1 404 Not Found - Date: Fri, 27 Feb 2015 11:07:49 GMT - Server: Apache - Vary: Accept-Encoding - Content-Length: 275 - Keep-Alive: timeout=5, max=39 - Connection: Keep-Alive - Content-Type: text/html; charset=iso-8859-1 -http://partnerportal.dpppa.dev.punkt.de/typo3conf/ext/pt_dppp_base/Resources/Public/Styles/jquery.selectBox-arrow.gif: -2015-02-27 12:07:49 ERROR 404: Not Found. -FINISHED --2015-02-27 12:07:49-- -Total wall clock time: 6.1s -Downloaded: 61 files, 935K in 0.009s (99.5 MB/s) \ No newline at end of file diff --git a/Tests/Unit/Utility/Wget/WgetCommandTest.php b/Tests/Unit/Utility/Wget/WgetCommandTest.php deleted file mode 100755 index 5785fabf..00000000 --- a/Tests/Unit/Utility/Wget/WgetCommandTest.php +++ /dev/null @@ -1,77 +0,0 @@ -wgetCommand = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('PunktDe\PtExtbase\Utility\Wget\WgetCommand'); - } - - public function tearDown(): void - { - } - - - /** - * @test - */ - public function buildUrl() - { - $expected = 'wget --no-check-certificate --convert-links --load-cookies=cookies.txt --execute robots=off --tries=30 --retry-connrefused --server-response --directory-prefix=2014-11-28-0958 --domains=test.punkt.de --page-requisites --output-file="2014-11-28-0958.log" --no-verbose "http://test.punkt.de/page/"'; - - $this->wgetCommand - ->setWgetBinaryPath('wget') - ->setNoCheckCertificate(true) - ->setExecute('robots=off') - ->setConvertLinks(true) - ->setLoadCookies('cookies.txt') - ->setTries(30) - ->setDomains('test.punkt.de') - ->setRetryConnRefused(true) - ->setServerResponse(true) - ->setDirectoryPrefix('2014-11-28-0958') - ->setPageRequisites(true) - ->setOutputFile('2014-11-28-0958.log') - ->setUrl('http://test.punkt.de/page/'); - - $actual = $this->wgetCommand->getCommand(); - - $this->assertEquals($expected, $actual); - } -} diff --git a/Tests/Unit/Utility/Wget/WgetLogEntryTest.php b/Tests/Unit/Utility/Wget/WgetLogEntryTest.php deleted file mode 100644 index aca97d74..00000000 --- a/Tests/Unit/Utility/Wget/WgetLogEntryTest.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -namespace PunktDe\PtExtbase\Tests\Utility\Wget; - -class WgetLogEntryTest extends \PunktDe\PtExtbase\Testing\Unit\AbstractBaseTestcase -{ - /** - * @var \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry - */ - protected $wgetLogEntry; - - - public function setUp(): void - { - $wgetLogEntryProxyClass = $this->buildAccessibleProxy(\PunktDe\PtExtbase\Utility\Wget\WgetLogEntry::class); - $this->wgetLogEntry = new $wgetLogEntryProxyClass(); - } - - - public function tearDown(): void - { - } - - - /** - * @test - */ - public function wgetLogEntryCanBeIdentifiedAsError() - { - $this->wgetLogEntry->setStatus(500); - $this->assertTrue($this->wgetLogEntry->isError()); - } -} diff --git a/Tests/Unit/Utility/Wget/WgetLogParsertest.php b/Tests/Unit/Utility/Wget/WgetLogParsertest.php deleted file mode 100644 index f56e42e5..00000000 --- a/Tests/Unit/Utility/Wget/WgetLogParsertest.php +++ /dev/null @@ -1,269 +0,0 @@ - - * - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -namespace PunktDe\PtExtbase\Tests\Utility\Wget; - -use Neos\Utility\Files; -use PunktDe\PtExtbase\Utility\Wget\WgetLog; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -class WgetLogParsertest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase -{ - /** - * @var \PunktDe\PtExtbase\Utility\Wget\WgetLogParser - */ - protected $wgetLogParser; - - - /** - * @var string - */ - protected $logOutPutFile; - - - public function setUp() - { - $wgetLogParserProxyClass = $this->buildAccessibleProxy('\PunktDe\PtExtbase\Utility\Wget\WgetLogParser'); - $this->wgetLogParser = new $wgetLogParserProxyClass(); - - $this->logOutPutFile = __DIR__ . '/testLogFile.log'; - } - - - public function tearDown() - { - if (file_exists($this->logOutPutFile)) { - Files::unlink($this->logOutPutFile); - } - } - - - protected $testWgetLogEntry1 = <<<'EOD' - HTTP/1.1 200 OK - Server: Apache/2.4.6 (Red Hat) - Last-Modified: Mon, 14 Apr 2014 13:44:20 GMT - Vary: Accept-Encoding,User-Agent - Cache-Control: max-age=86400 - Expires: Tue, 27 Jan 2015 16:46:42 GMT - Content-Type: image/x-icon - Content-Length: 1406 - Date: Mon, 26 Jan 2015 16:50:43 GMT - X-Varnish: 938681105 938680885 - Age: 241 - Via: 1.1 varnish - Connection: keep-alive - 2015-01-26 17:50:43 URL:https://test.de/index.php?id=login&logintype=logout [6285/6285] -> "2014-11-28-0958/test.de/login/hdl/helpdesklogin/4092341/23589310/a9dc685506e98630/104" [1] -EOD; - - protected $testWgetLogEntry2 = <<<'EOD' -WARNUNG: Kann das Zertifikat von »das-partnerportal.deutschepost.de« nicht prüfen, ausgestellt von »»/C=DE/ST=Nordrhein-Westfalen/L=Bonn/O=Deutsche Post/CN=DPDHL TLS SHA2 CA I3««:. - Ein selbst-signiertes Zertifikat gefunden. - HTTP/1.1 200 OK - Server: Apache/2.4.6 (Red Hat) - Last-Modified: Fri, 09 Jan 2015 09:04:44 GMT - Vary: Accept-Encoding,User-Agent - Cache-Control: max-age=86400 - Expires: Tue, 27 Jan 2015 16:46:42 GMT - Content-Type: text/css - Content-Length: 0360 - Date: Mon, 26 Jan 2015 16:50:43 GMT - X-Varnish: 938681107 938680887 - Age: 241 - Via: 1.1 varnish - Connection: keep-alive - 2015-01-26 17:50:43 URL:https://test.de/typo3temp/stylesheet_c89de9523c.1422025907.css [9169/9169] -> "2014-11-28-0958/test.de/typo3temp/stylesheet_c89de9523c.1422025907.css" [1] -EOD; - - /** - * @var array - */ - protected $testWgetLogEntrySplitted1 = ['status' => 'HTTP/1.1 200 OK', - 'body' => 'Server: Apache/2.4.6 (Red Hat) - Last-Modified: Mon, 14 Apr 2014 13:44:20 GMT - Vary: Accept-Encoding,User-Agent - Cache-Control: max-age=86400 - Expires: Tue, 27 Jan 2015 16:46:42 GMT - Content-Type: image/x-icon - Content-Length: 1406 - Date: Mon, 26 Jan 2015 16:50:43 GMT - X-Varnish: 938681105 938680885 - Age: 241 - Via: 1.1 varnish - Connection: keep-alive - 2015-01-26 17:50:43 URL:https://test.de/index.php?id=login&logintype=logout [6285/6285] -> "2014-11-28-0958/test.de/login/hdl/helpdesklogin/4092341/23589310/a9dc685506e98630/104" [1] -WARNUNG: Kann das Zertifikat von »das-partnerportal.deutschepost.de« nicht prüfen, ausgestellt von »»/C=DE/ST=Nordrhein-Westfalen/L=Bonn/O=Deutsche Post/CN=DPDHL TLS SHA2 CA I3««:. - Ein selbst-signiertes Zertifikat gefunden.']; - - - /** - * @test - */ - public function splitLogFileEntries() - { - $logInput = $this->testWgetLogEntry1 . "\n" . $this->testWgetLogEntry2; - $actualLogEntryArray = $this->wgetLogParser->_call('splitLogFileEntries', $logInput); - - $expectedLogEntryArray = [ - 0 => $this->testWgetLogEntrySplitted1, - 2 => ['status' => 'HTTP/1.1 200 OK', - 'body' =>'Server: Apache/2.4.6 (Red Hat) - Last-Modified: Fri, 09 Jan 2015 09:04:44 GMT - Vary: Accept-Encoding,User-Agent - Cache-Control: max-age=86400 - Expires: Tue, 27 Jan 2015 16:46:42 GMT - Content-Type: text/css - Content-Length: 0360 - Date: Mon, 26 Jan 2015 16:50:43 GMT - X-Varnish: 938681107 938680887 - Age: 241 - Via: 1.1 varnish - Connection: keep-alive - 2015-01-26 17:50:43 URL:https://test.de/typo3temp/stylesheet_c89de9523c.1422025907.css [9169/9169] -> "2014-11-28-0958/test.de/typo3temp/stylesheet_c89de9523c.1422025907.css" [1]' - ] - ]; - - $this->assertEquals($expectedLogEntryArray[0], $actualLogEntryArray[0], 'First log entry differs'); - $this->assertEquals($expectedLogEntryArray[2], $actualLogEntryArray[2], 'Second log entry differs'); - $this->assertEquals($expectedLogEntryArray, $actualLogEntryArray); - } - - - /** - * @test - */ - public function buildLogFileEntry() - { - $logEntryObject = $this->wgetLogParser->_call('buildLogFileEntry', $this->testWgetLogEntrySplitted1); /** @var $logEntryObject \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry */ - - $this->assertInstanceOf('\PunktDe\PtExtbase\Utility\Wget\WgetLogEntry', $logEntryObject); - - $this->assertInstanceOf('\DateTime', $logEntryObject->getFetchDate()); - $this->assertEquals('2015-01-26 17:50:43', $logEntryObject->getFetchDate()->format('Y-m-d H:i:s')); - $this->assertEquals('https://test.de/index.php?id=login&logintype=logout', $logEntryObject->getUrl()); - $this->assertEquals(200, $logEntryObject->getStatus()); - $this->assertEquals('image/x-icon', $logEntryObject->getContentType()); - $this->assertEquals(1406, $logEntryObject->getContentLength()); - } - - - /** - * @test - */ - public function parseLog() - { - $wgetCommand = new \PunktDe\PtExtbase\Utility\Wget\WgetCommand(); - $wgetCommand->setNoVerbose(true)->setOutputFile($this->logOutPutFile); - - file_put_contents($this->logOutPutFile, $this->testWgetLogEntry1 . "\n" . $this->testWgetLogEntry2); - - $logFileEntries = $this->wgetLogParser->parseLog($wgetCommand); - - $this->assertCount(2, $logFileEntries); - $this->assertInstanceOf('\PunktDe\PtExtbase\Utility\Wget\WgetLogEntry', $logFileEntries[0]); - $this->assertInstanceOf('\PunktDe\PtExtbase\Utility\Wget\WgetLogEntry', $logFileEntries[1]); - } - - - /** - * @test - * @throws \PunktDe\PtExtbase\Exception\InternalException - */ - public function parseLogWithErrors() - { - $logOutPutFile = Files::concatenatePaths([__DIR__, 'TestData/WgetTest.log']); - - $wgetCommand = new \PunktDe\PtExtbase\Utility\Wget\WgetCommand(); - $wgetCommand->setNoVerbose(true)->setOutputFile($logOutPutFile); - - $logFileEntries = $this->wgetLogParser->parseLog($wgetCommand); - - $this->assertCount(4, $logFileEntries); - - // Case 200 - - $logFileEntry1 = [ - 'date' => date_create_from_format('Y-m-d H:i:s', '2015-02-26 11:50:40'), - 'url' => 'https://test.de/data-ok.html', - 'status' => 200, - 'length' => 3951 - ]; - - $this->assertEquals($logFileEntry1, $logFileEntries->getItemByIndex(0)->toArray()); - - - // Case 404 - - $logFileEntry2 = [ - 'date' => date_create_from_format('Y-m-d H:i:s', '2015-02-26 11:50:57'), - 'url' => 'https://test.de/typo3conf/jquery.selectBox-arrow.gif', - 'status' => 404, - 'length' => 275 - ]; - - $this->assertEquals($logFileEntry2, $logFileEntries->getItemByIndex(1)->toArray()); - - // Case 200 after 404 - - $logFileEntry3 = [ - 'date' => date_create_from_format('Y-m-d H:i:s', '2015-02-26 11:50:40'), - 'url' => 'https://test.de/data-ok2.html', - 'status' => 200, - 'length' => 1000 - ]; - - $this->assertEquals($logFileEntry3, $logFileEntries->getItemByIndex(2)->toArray()); - - // Case 404 on last line - - $logFileEntry4 = [ - 'date' => date_create_from_format('Y-m-d H:i:s', '2015-02-27 12:07:49'), - 'url' => 'http://partnerportal.dpppa.dev.punkt.de/typo3conf/ext/pt_dppp_base/Resources/Public/Styles/jquery.selectBox-arrow.gif', - 'status' => 404, - 'length' => 275 - ]; - - $this->assertEquals($logFileEntry4, $logFileEntries->getItemByIndex(3)->toArray()); - } - - - /** - * @test - */ - public function buildLogFileEntryArrayTest() - { - $wgetLog = $this->wgetLogParser->_call('buildLogFileEntryArray', $this->testWgetLogEntry2); /** @var $wgetLog WgetLog */ - - $expected = [ - 'date' => date_create_from_format('Y-m-d H:i:s', '2015-01-26 17:50:43'), - 'url' => 'https://test.de/typo3temp/stylesheet_c89de9523c.1422025907.css', - 'status' => 200, - 'length' => 360 - ]; - - $this->assertEquals(1, $wgetLog->count()); - $this->assertEquals($expected, $wgetLog->getItemByIndex(0)->toArray()); - } -} diff --git a/Tests/Unit/Utility/Wget/WgetLogTest.php b/Tests/Unit/Utility/Wget/WgetLogTest.php deleted file mode 100644 index 9e128966..00000000 --- a/Tests/Unit/Utility/Wget/WgetLogTest.php +++ /dev/null @@ -1,105 +0,0 @@ - - * - * - * All rights reserved - * - * This script is part of the TYPO3 project. The TYPO3 project is - * free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The GNU General Public License can be found at - * http://www.gnu.org/copyleft/gpl.html. - * - * This script is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * This copyright notice MUST APPEAR in all copies of the script! - ***************************************************************/ - -namespace PunktDe\PtExtbase\Tests\Utility\Wget; - -use Neos\Utility\Files; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -class WgetLogTest extends \PunktDe\PtExtbase\Testing\Unit\AbstractBaseTestcase -{ - /** - * @var \PunktDe\PtExtbase\Utility\Wget\WgetLog - */ - protected $wgetLog; - - - public function setUp(): void - { - $wgetLogProxyClass = $this->buildAccessibleProxy('PunktDe\PtExtbase\Utility\Wget\WgetLog'); - $this->wgetLog = new $wgetLogProxyClass(); - } - - - public function tearDown(): void - { - } - - - public function logEntryDataProvider() - { - return [ - 'sandwich400' => ['codes' => [200,404,200], 'hasError' => true, 'countErrors' => 1], - 'sandwich500' => ['codes' => [200,503,200], 'hasError' => true, 'countErrors' => 1], - 'twoErrors' => ['codes' => [200,503,400], 'hasError' => true, 'countErrors' => 2], - 'noErrors' => ['codes' => [200,200], 'hasError' => false, 'countErrors' => 0] - ]; - } - - - /** - * @test - * @dataProvider logEntryDataProvider - * - * @param $codes - * @param $hasErrors - */ - public function hasErrors($codes, $hasErrors, $countErrors) - { - foreach ($codes as $code) { - $logEntry = new \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry(); /** @var \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry $logEntry */ - $logEntry->setStatus($code); - $this->wgetLog->addLogEntry($logEntry); - } - - $this->assertEquals($hasErrors, $this->wgetLog->hasErrors()); - } - - - /** - * @test - * @dataProvider logEntryDataProvider - * - * @param $codes - * @param $hasErrors - */ - public function getErrors($codes, $hasErrors, $countErrors) - { - foreach ($codes as $code) { - $logEntry = new \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry(); /** @var \PunktDe\PtExtbase\Utility\Wget\WgetLogEntry $logEntry */ - $logEntry->setStatus($code); - $this->wgetLog->addLogEntry($logEntry); - } - - $logEntries = $this->wgetLog->getErrors(); - - $this->assertEquals($countErrors, count($logEntries)); - - foreach ($logEntries as $logEntry) { - $this->assertTrue($logEntry->isError()); - } - } -}