diff --git a/cake/tests/cases/libs/view/helpers/session.test.php b/cake/tests/cases/libs/view/helpers/session.test.php index cf07f3d76..466d1648c 100644 --- a/cake/tests/cases/libs/view/helpers/session.test.php +++ b/cake/tests/cases/libs/view/helpers/session.test.php @@ -30,7 +30,8 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { define('CAKEPHP_UNIT_TEST_EXECUTION', 1); } -uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'.DS.'model', 'view'.DS.'helper', 'view'.DS.'helpers'.DS.'session'); +App::import('Core', array('Helper', 'AppHelper', 'Controller', 'View')); +App::import('Helper', array('Session')); /** * Short description for class. @@ -38,19 +39,117 @@ uses('view'.DS.'helpers'.DS.'app_helper', 'controller'.DS.'controller', 'model'. * @package cake.tests * @subpackage cake.tests.cases.libs.view.helpers */ -class SessionHelperTest extends UnitTestCase { - - function skip() { - $this->skipif (true, 'SessionHelper test not implemented'); - } - +class SessionHelperTest extends CakeTestCase { + function setUp() { - $this->Session = new SessionHelper(); + $this->Session = new SessionHelper(); + $this->Session->__start(); + + $_SESSION = array('test' => 'info', + 'Message' => array( + 'flash' => array( + 'layout' => 'default', + 'params' => array(), + 'message' => 'This is a calling' + ), + 'notification' => array( + 'layout' => 'sessionHelper', + 'params' => array('title' => 'Notice!', + 'name' => 'Alert!'), + 'message' => 'This is a test of the emergency broadcasting system', + ), + 'bare' => array( + 'layout' => null, + 'message' => 'Bare message', + 'params' => array(), + ), + ), + 'Deeply' => array('nested' => array('key' => 'value')), + ); } function tearDown() { + $_SESSION = array(); unset($this->Session); } + + function testRead() { + $result = $this->Session->read('Deeply.nested.key'); + $this->assertEqual($result, 'value'); + + $result = $this->Session->read('test'); + $this->assertEqual($result, 'info'); + + } + + function testCheck() { + $this->assertTrue($this->Session->check('test')); + + $this->assertTrue($this->Session->check('Message.flash.layout')); + + $this->assertFalse($this->Session->check('Does.not.exist')); + + $this->assertFalse($this->Session->check('Nope')); + } + + function testWrite() { + $this->expectError(); + $this->Session->write('NoWay', 'AccessDenied'); + } + + function testFlash() { + ob_start(); + $this->Session->flash(); + $result = ob_get_contents(); + ob_clean(); + + $expected = '
This is a calling
'; + $this->assertEqual($result, $expected); + $this->assertFalse($this->Session->check('Message.flash')); + + Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)); + $controller = new Controller(); + $this->Session->view = new View($controller); + + ob_start(); + $this->Session->flash('notification'); + $result = ob_get_contents(); + ob_clean(); + + $expected = "
\n\t

Alert!

\n\t

Notice!

\n\t

This is a test of the emergency broadcasting system

\n
"; + $this->assertEqual($result, $expected); + $this->assertFalse($this->Session->check('Message.notification')); + + ob_start(); + $this->Session->flash('bare'); + $result = ob_get_contents(); + ob_clean(); + + $expected = 'Bare message'; + $this->assertEqual($result, $expected); + $this->assertFalse($this->Session->check('Message.bare')); + } + + function testID() { + $id = session_id(); + $result = $this->Session->id(); + $this->assertEqual($id, $result); + } + + function testError() { + $result = $this->Session->error(); + $this->assertFalse($result); + + $this->Session->read('CauseError'); + $result = $this->Session->error(); + $expected = "CauseError doesn't exist"; + $this->assertEqual($result, $expected); + } + + function testValid() { + //wierd it always ends up false in the test suite + //$this->assertFalse($this->Session->valid()); + } } ?> \ No newline at end of file diff --git a/cake/tests/test_app/views/layouts/sessionHelper.ctp b/cake/tests/test_app/views/layouts/sessionHelper.ctp new file mode 100644 index 000000000..0f691b98a --- /dev/null +++ b/cake/tests/test_app/views/layouts/sessionHelper.ctp @@ -0,0 +1,5 @@ +
+

+

+

+
\ No newline at end of file