Skip to content

Commit

Permalink
Merge pull request #210 from WebFiori/dev
Browse files Browse the repository at this point in the history
test(ui): More Testing for Class `WebPage`
  • Loading branch information
usernane committed Mar 19, 2024
2 parents 8b748e0 + c3c9861 commit 553617d
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/langs/LangEN.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ class LangEN extends Lang {
public function __construct() {
parent::__construct('ltr', 'EN', true);
//TODO: Add the language "EN" labels.
$this->createAndSet('hello', [
'one' => [
'cool' => 'Cool'
],
'two' => '2'
]);
}
}
96 changes: 96 additions & 0 deletions tests/webfiori/framework/test/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
use Exception;
use PHPUnit\Framework\TestCase;
use themes\fioriTheme\NewFTestTheme;
use webfiori\framework\Access;
use webfiori\framework\App;
use webfiori\framework\Lang;
use webfiori\framework\session\SessionsManager;
use webfiori\framework\Theme;
use webfiori\framework\ui\WebPage;
use webfiori\framework\User;
use webfiori\ui\HTMLNode;
/**
* Description of PageTest
Expand Down Expand Up @@ -209,6 +212,98 @@ public function testCreateHtmlNode02() {
$el = $page->getChildByID('my-div');
$this->assertEquals('My Name Is Super Hero', $el->getChild(0)->getText());
}
/**
* @test
*/
public function testCreateHtmlNode03() {
$page = new WebPage();
$node = $page->createHTMLNode();
$node->setID('new-node');
$this->assertEquals('div', $node->getNodeName());
$this->assertEquals(0,$page->getChildByID('main-content-area')->childrenCount());
$el = $page->getChildByID('new-node');
$this->assertNull($el);
}
/**
* @test
*/
public function testHasPrivilege00() {
$page = new WebPage();
$this->assertFalse($page->hasPrivilege('A_TEST'));
}
/**
* @test
*/
public function testHasPrivilege01() {
$page = new WebPage();
SessionsManager::start('new');
$this->assertFalse($page->hasPrivilege('A_TEST'));
}
/**
* @test
*/
public function testHasPrivilege02() {
$page = new WebPage();
SessionsManager::start('new');
$user = new User();
$user->addPrivilege('A_TEST');
SessionsManager::getActiveSession()->setUser($user);
$this->assertFalse($page->hasPrivilege('A_TEST'));
Access::newGroup('Test');
Access::newPrivilege('Test', 'A_TEST');
$user->addPrivilege('A_TEST');
$this->assertTrue($page->hasPrivilege('A_TEST'));
}
/**
* @test
*/
public function testGetSession00() {
SessionsManager::destroy();
$page = new WebPage();
$this->assertNull($page->getActiveSession());
}
/**
* @test
*/
public function testGetSession01() {
SessionsManager::start('test-session-1');
$page = new WebPage();
$session = $page->getActiveSession();
$this->assertNotNull($session);
$this->assertEquals('test-session-1', $session->getName());
SessionsManager::destroy();
$this->assertNull($page->getActiveSession());
}
/**
* @test
*/
public function testGetSession02() {
SessionsManager::start('test-session-1');
SessionsManager::start('test-session-2');
$page = new WebPage();
$session = $page->getActiveSession();
$this->assertNotNull($session);
$this->assertEquals('test-session-2', $session->getName());
SessionsManager::destroy();
$this->assertNull($page->getActiveSession());
}
/**
* @test
*/
public function testGetLabel00() {
$page = new WebPage();
$this->assertEquals('a/b/c', $page->get('a/b/c'));
}
/**
* @test
*/
public function testGetLabel01() {
$page = new WebPage();
$this->assertEquals('2', $page->get('hello/two'));
$this->assertEquals([
'cool' => 'Cool'
], $page->get('hello/one'));
}
/**
* @test
*/
Expand All @@ -225,6 +320,7 @@ public function testDefaults00() {
$this->assertEquals('ltr',$page->getWritingDir());
$this->assertNotNull($page->getTranslation());
$this->assertEquals('https://127.0.0.1/',$page->getCanonical());
$this->assertEquals('http://127.0.0.1',$page->getBase());
}
/**
* @test
Expand Down

0 comments on commit 553617d

Please sign in to comment.