Browse Source

And added some more

Belle Aerni 2 years ago
parent
commit
2acfc2d50d
5 changed files with 121 additions and 1 deletions
  1. 1 0
      readme.md
  2. 60 0
      tests/CMSTest.php
  3. 29 0
      tests/ConfigTest.php
  4. 1 1
      tests/Includes/config.yaml
  5. 30 0
      tests/PagesTest.php

+ 1 - 0
readme.md

@@ -1,6 +1,7 @@
 # AntCMS
 # AntCMS
 
 
 [![PHPStan](https://github.com/BelleNottelling/AntCMS/actions/workflows/phpstan.yml/badge.svg)](https://github.com/BelleNottelling/AntCMS/actions/workflows/phpstan.yml)
 [![PHPStan](https://github.com/BelleNottelling/AntCMS/actions/workflows/phpstan.yml/badge.svg)](https://github.com/BelleNottelling/AntCMS/actions/workflows/phpstan.yml)
+[![Unit Tests](https://github.com/AntCMS-org/AntCMS/actions/workflows/unittests.yml/badge.svg)](https://github.com/AntCMS-org/AntCMS/actions/workflows/unittests.yml)
 
 
 A tiny and fast CMS system for static websites.
 A tiny and fast CMS system for static websites.
 
 

+ 60 - 0
tests/CMSTest.php

@@ -0,0 +1,60 @@
+<?php
+
+use AntCMS\AntCMS;
+use PHPUnit\Framework\TestCase;
+
+include_once 'Includes' . DIRECTORY_SEPARATOR . 'Include.php';
+
+class CMSTest extends TestCase
+{
+    public function testgetSiteInfo()
+    {
+        $siteInfo = AntCMS::getSiteInfo();
+
+        $this->assertIsArray($siteInfo);
+        $this->assertArrayHasKey('siteTitle', $siteInfo);
+        $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';
+        $result = $antCMS->renderPage($pagePath);
+
+        $this->assertNotEmpty($result);
+        $this->assertIsString($result);
+    }*/
+
+    public function testGetPageLayout()
+    {
+        $antCMS = new AntCMS;
+        $result = $antCMS->getPageLayout();
+
+        $this->assertNotEmpty($result);
+        $this->assertIsString($result);
+    }
+
+    public function testGetPage()
+    {
+        $antCMS = new AntCMS;
+        $result = $antCMS->getPage('/index.md');
+
+        $this->assertNotEmpty($result);
+        $this->assertIsArray($result);
+        $this->assertArrayHasKey('content', $result);
+        $this->assertArrayHasKey('title', $result);
+        $this->assertArrayHasKey('author', $result);
+        $this->assertArrayHasKey('description', $result);
+        $this->assertArrayHasKey('keywords', $result);
+    }
+
+    public function testGetThemeTemplate()
+    {
+        $antCMS = new AntCMS;
+        $result = $antCMS->getThemeTemplate();
+
+        $this->assertNotEmpty($result);
+        $this->assertIsString($result);
+    }
+}

+ 29 - 0
tests/ConfigTest.php

@@ -0,0 +1,29 @@
+<?php
+
+use AntCMS\AntConfig;
+use PHPUnit\Framework\TestCase;
+
+include_once 'Includes' . DIRECTORY_SEPARATOR . 'Include.php';
+
+class ConfigTest extends TestCase
+{
+    public function testGetConfig()
+    {
+        $config = AntConfig::currentConfig();
+
+        $expectedKeys = array(
+            'SiteInfo',
+            'forceHTTPS',
+            'activeTheme',
+            'generateKeywords',
+            'enableCache',
+            'admin',
+            'debug',
+            'baseURL'
+        );
+
+        foreach ($expectedKeys as $key) {
+            $this->assertArrayHasKey($key, $config, "Expected key '$key' not found in config array");
+        }
+    }
+}

+ 1 - 1
tests/Includes/config.yaml

@@ -1,7 +1,7 @@
 SiteInfo:
 SiteInfo:
     siteTitle: 'AntCMS'
     siteTitle: 'AntCMS'
 forceHTTPS: true
 forceHTTPS: true
-activeTheme: Tailwind
+activeTheme: Default
 generateKeywords: true
 generateKeywords: true
 enableCache: true
 enableCache: true
 admin:
 admin:

+ 30 - 0
tests/PagesTest.php

@@ -0,0 +1,30 @@
+<?php
+
+use AntCMS\AntPages;
+use AntCMS\AntCMS;
+use PHPUnit\Framework\TestCase;
+
+include_once 'Includes' . DIRECTORY_SEPARATOR . 'Include.php';
+
+class PagesTest extends TestCase
+{
+    public function testGetGenerateAndGetPages()
+    {
+        AntPages::generatePages();
+        $result = AntPages::getPages();
+
+        $this->assertNotEmpty($result);
+        $this->assertIsArray($result);
+    }
+
+    public function testGetNavigation(){
+        $antCMS = new AntCMS;
+        $pageTemplate = $antCMS->getThemeTemplate();
+        $navLayout = $antCMS->getThemeTemplate('nav_layout');
+
+        $result = AntPages::generateNavigation($navLayout, $pageTemplate);
+
+        $this->assertNotEmpty($result);
+        $this->assertIsString($result);
+    }
+}