public function testAppend() { $tempFile = new File(FileUtil::getTempFileName()); $this->assertTrue($tempFile->append('foobar')); $this->assertSame('foobar', $tempFile->getContent()); $this->assertTrue($tempFile->append('bazfoobar')); $this->assertSame('foobarbazfoobar', $tempFile->getContent()); }
/** * Tests whether getTempFileName() works correctly. * * @dataProvider dataProviderTestGetTempFileName */ public function testGetTempFileName($subDirectory, $filePrefix, $fileName, $fileExtension, $expectedFileNameRegExp) { // replace temp dir placeholder with temp dir path $expectedFileNameRegExp = str_replace('{TEMP_DIR}', preg_quote(ABLERON_TEMP_DIR, '#'), $expectedFileNameRegExp); // execute test $this->assertRegExp($expectedFileNameRegExp, FileUtil::getTempFileName($subDirectory, $filePrefix, $fileName, $fileExtension)); }
/** * Returns the file where to save the compiled version of the given source template. * * @param string $sourceTemplateFile The source template file for which to get the file of the compiled version * @throws \Ableron\Core\Exception\SystemException * @return string */ public function getCompiledTemplateFile($sourceTemplateFile) { // make sure "./" and "../" are handled correctly $sourceTemplateFile = StringUtil::contains($sourceTemplateFile, './') ? FileUtil::normalizePath(realpath($sourceTemplateFile)) : $sourceTemplateFile; // extract template information from path (module, area and template name) if (!preg_match('#/Modules/(?<module>[^/]+)(?<path>(/[^/]+)+?)/(?<name>[^/]+)\\.tpl$#', $sourceTemplateFile, $templateInfo)) { throw new SystemException(sprintf('Template file has invalid path: %s (Pattern of valid template file: .../<module>/**/<name>.tpl, e.g. **/app/Modules/Core/Pages/Backend/Templates/IndexPage.tpl)', $sourceTemplateFile), 0, E_USER_ERROR, __FILE__, __LINE__); } // build and return file name of the compiled template return FileUtil::getTempFileName(sprintf('tpl/%s/%s/%s', $templateInfo['module'], $templateInfo['path'], Application::getI18nHandler()->getLocale()->getLocaleCode()), '', $templateInfo['name'], 'php'); }
/** * Checks whether isCompiled works as expected. * * @return void */ public function testIsCompiled() { // get template handler, template file and compiled template file $templateHandler = $this->getTemplateHandler(); $templateFile = FileUtil::getTempFileName(); $templateFileCompiled = FileUtil::getTempFileName(); // no compiled file exists $this->assertFalse($templateHandler->isCompiled($templateFile, $templateFileCompiled)); // compiled file is older than template file touch($templateFile, time()); touch($templateFileCompiled, time() - 1000); $this->assertFalse($templateHandler->isCompiled($templateFile, $templateFileCompiled)); // compiled file is valid touch($templateFileCompiled, time() + 1000); $this->assertTrue($templateHandler->isCompiled($templateFile, $templateFileCompiled)); // compiled file and template have the same modification time touch($templateFile, 1); touch($templateFileCompiled, 1); $this->assertTrue($templateHandler->isCompiled($templateFile, $templateFileCompiled)); }