Test, tests, baby (insert sounds from ice, ice, baby)
This commit is contained in:
Belle Aerni 2023-01-09 10:47:55 -08:00
parent 37a0f2ffcd
commit b60439a9a9
4 changed files with 74 additions and 36 deletions

View file

@ -37,8 +37,7 @@ class AntCMS
$pageTemplate = str_replace('<!--AntCMS-Debug-->', '<p>Took ' . $elapsed_time . ' seconds to render the page. </p>', $pageTemplate);
}
echo $pageTemplate;
exit;
return $pageTemplate;
}
public function getPageLayout($theme = null)
@ -108,26 +107,36 @@ class AntCMS
$templates = AntTools::getFileList($templatePath, 'html');
if (in_array($layout . '.html', $templates)) {
$template = file_get_contents(AntTools::repairFilePath($templatePath . '/' . $layout . '.html'));
} else {
$template = file_get_contents(AntTools::repairFilePath($defaultTemplates . '/' . $layout . '.html'));
try {
if (in_array($layout . '.html', $templates)) {
$template = file_get_contents(AntTools::repairFilePath($templatePath . '/' . $layout . '.html'));
} else {
$template = file_get_contents(AntTools::repairFilePath($defaultTemplates . '/' . $layout . '.html'));
}
} catch (\Exception $e) {
}
if ($layout == 'default_layout' && !$template) {
$template = '
<!DOCTYPE html>
<html>
<head>
<title><!--AntCMS-Title--></title>
<meta name="description" content="<!--AntCMS-Description-->">
<meta name="author" content="<!--AntCMS-Author-->">
<meta name="keywords" content="<!--AntCMS-Keywords-->">
</head>
<body>
<!--AntCMS-Body-->
</body>
</html>';
if (empty($template)) {
if ($layout == 'default_layout') {
$template = '
<!DOCTYPE html>
<html>
<head>
<title><!--AntCMS-Title--></title>
<meta name="description" content="<!--AntCMS-Description-->">
<meta name="author" content="<!--AntCMS-Author-->">
<meta name="keywords" content="<!--AntCMS-Keywords-->">
</head>
<body>
<p>AntCMS had an error when fetching the page template, please contact the site administrator.</p>
<!--AntCMS-Body-->
</body>
</html>';
} else {
$template = '
<h1>There was an error</h1>
<p>AntCMS had an error when fetching the page template, please contact the site administrator.</p>';
}
}
return $template;

View file

@ -78,9 +78,9 @@ if ($segments[0] === 'plugin') {
$indexes = ['/', '/index.php', '/index.html'];
if (in_array($segments[0], $indexes)) {
$antCms->renderPage('/');
echo $antCms->renderPage('/');
exit;
} else {
$antCms->renderPage($requestedPage);
echo $antCms->renderPage($requestedPage);
exit;
}

View file

@ -17,7 +17,6 @@ class CMSTest extends TestCase
$this->assertEquals('AntCMS', $siteInfo['siteTitle']);
}
/* Since this function echos the page and exists processing, we don't get the chance to test the return. Will revist.
public function testRenderPage(){
$antCMS = new AntCMS;
$pagePath = '/index.md';
@ -25,7 +24,7 @@ class CMSTest extends TestCase
$this->assertNotEmpty($result);
$this->assertIsString($result);
}*/
}
public function testGetPageLayout()
{
@ -70,4 +69,13 @@ class CMSTest extends TestCase
$this->assertNotEmpty($result);
$this->assertIsString($result);
}
public function testGetThemeTemplateFallback()
{
$antCMS = new AntCMS;
$result = $antCMS->getThemeTemplate('atemplatethatjusdoesntexist');
$this->assertNotEmpty($result);
$this->assertIsString($result);
}
}

View file

@ -1,6 +1,7 @@
<?php
use AntCMS\AntMarkdown;
use AntCMS\AntConfig;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Constraint\Callback;
@ -26,7 +27,7 @@ class MarkdownTest extends TestCase
$totalTime += $end - $start;
}
$averageTime = $totalTime / 5;
$averageTime = $totalTime / 10;
$constraint = new Callback(function ($averageTime) {
return $averageTime < 0.015;
@ -36,20 +37,40 @@ class MarkdownTest extends TestCase
}
/*public function testMarkdownCacheWorks()
public function testMarkdownCacheWorks()
{
$markdown = file_get_contents(antContentPath . DIRECTORY_SEPARATOR . 'index.md');
$currentConfig = AntConfig::currentConfig();
$start = microtime(true);
AntMarkdown::renderMarkdown($markdown);
$end = microtime(true);
$firstTime = $end - $start;
//Disable cache
$currentConfig['enableCache'] = false;
AntConfig::saveConfig($currentConfig);
$start = microtime(true);
AntMarkdown::renderMarkdown($markdown);
$end = microtime(true);
$secondTime = $end - $start;
$totalTime = 0;
for ($i = 0; $i < 10; $i++) {
$start = microtime(true);
AntMarkdown::renderMarkdown($markdown);
$end = microtime(true);
$totalTime += $end - $start;
}
$this->assertLessThan($secondTime, $firstTime, 'Cache didn\'t speed up rendering!');
}*/
$withoutCache = $totalTime / 10;
//Enable cache
$currentConfig['enableCache'] = true;
AntConfig::saveConfig($currentConfig);
$totalTime = 0;
for ($i = 0; $i < 10; $i++) {
$start = microtime(true);
AntMarkdown::renderMarkdown($markdown);
$end = microtime(true);
$totalTime += $end - $start;
}
$withCache = $totalTime / 10;
echo "\n Markdown rendering speed with cache: $withCache VS without: $withoutCache \n\n";
$this->assertLessThan($withoutCache, $withCache, 'Cache didn\'t speed up rendering!');
}
}