diff --git a/tests/Aauth/Libraries/Aauth/InfosTest.php b/tests/Aauth/Libraries/Aauth/InfosTest.php new file mode 100644 index 0000000..8c95789 --- /dev/null +++ b/tests/Aauth/Libraries/Aauth/InfosTest.php @@ -0,0 +1,116 @@ + 'CodeIgniter\Session\Handlers\FileHandler', + 'sessionCookieName' => 'ci_session', + 'sessionExpiration' => 7200, + 'sessionSavePath' => 'null', + 'sessionMatchIP' => false, + 'sessionTimeToUpdate' => 300, + 'sessionRegenerateDestroy' => false, + 'cookieDomain' => '', + 'cookiePrefix' => '', + 'cookiePath' => '/', + 'cookieSecure' => false, + ]; + + $config = (object)$defaults; + + $session = new MockSession(new FileHandler($config, Services::request()->getIPAddress()), $config); + $session->setLogger(new TestLogger(new Logger())); + $session->start(); + + return $session; + } + + //-------------------------------------------------------------------- + + public function testInfos() + { + $this->library = new Aauth(NULL, TRUE); + $this->assertCount(0, $this->library->getInfosArray()); + $this->library->info('test message 1'); + $this->assertEquals(['test message 1'], $this->library->getInfosArray()); + } + + public function testInfosArray() + { + $this->library = new Aauth(NULL, TRUE); + $this->assertCount(0, $this->library->getInfosArray()); + $this->library->info(['test message 1','test message 2']); + $this->assertEquals(['test message 1','test message 2'], $this->library->getInfosArray()); + } + + public function testPrintInfosReturn() + { + $this->library = new Aauth(NULL, TRUE); + $this->library->info('test message 1'); + $this->assertEquals('test message 1', $this->library->printInfos('
', true)); + $this->library->info('test message 2'); + $this->assertEquals('test message 1
test message 2', $this->library->printInfos('
', true)); + } + + public function testPrintInfosEcho() + { + $this->library = new Aauth(NULL, TRUE); + $this->library->info('test message 1'); + $this->library->printInfos('
'); + $this->expectOutputString('test message 1'); + } + + public function testClearInfos() + { + $session = $this->getInstance(); + $this->library = new Aauth(NULL, $session); + $this->library->info('test message 1', true); + $this->assertEquals(['test message 1'], $session->get('infos')); + $this->library->clearInfos(); + $this->assertNull($session->get('infos')); + } + + public function testInfosFlash() + { + $session = $this->getInstance(); + $this->library = new Aauth(NULL, $session); + $this->assertNull($session->get('infos')); + $this->library->info('test message 1', true); + $this->assertEquals(['test message 1'], $session->get('infos')); + } + + public function testInfosFlashArray() + { + $session = $this->getInstance(); + $this->library = new Aauth(NULL, $session); + $this->assertNull($session->get('infos')); + $this->library->info(['test message 1','test message 2'], true); + $this->assertEquals(['test message 1','test message 2'], $session->get('infos')); + } +}