Ejemplo n.º 1
0
 /**
  * We want to use our own little helper so that everything is shorter to write and
  * so we can use fancier messages with JavaScript.
  *
  * @param $options
  * @return HTML String
  */
 public function flash($options = array())
 {
     $defaults = array('key' => 'default', 'options' => array('type' => 'growl', 'fade_delay' => '8000', 'pnotify_opacity' => '.8'));
     $options += $defaults;
     $message = '';
     $flash = FlashMessage::read($options['key']);
     if (!empty($flash)) {
         $message = $flash['message'];
         FlashMessage::clear($options['key']);
     }
     $view = new View(array('paths' => array('template' => '{:library}/views/elements/{:template}.{:type}.php', 'layout' => '{:library}/views/layouts/{:layout}.{:type}.php')));
     return $view->render('all', array('options' => $options['options'], 'message' => $message), array('library' => 'li3b_core', 'template' => 'flash_message', 'type' => 'html', 'layout' => 'blank'));
 }
Ejemplo n.º 2
0
 public function testRead()
 {
     FlashMessage::write('Foo');
     $expected = array('message' => 'Foo', 'attrs' => array());
     $result = FlashMessage::read();
     $this->assertEqual($expected, $result);
     FlashMessage::write(array('Foo 2', 'type' => 'notice'));
     $expected = array('message' => 'Foo 2', 'attrs' => array('type' => 'notice'));
     $result = FlashMessage::read();
     $this->assertEqual($expected, $result);
     FlashMessage::write('Foo 3', 'foobar');
     $expected = array('message' => 'Foo 3', 'attrs' => array());
     $result = FlashMessage::read('foobar');
     $this->assertEqual($expected, $result);
 }
    public function testMessageTranslation()
    {
        $testApp = Libraries::get(true, 'resources') . '/tmp/tests/test_app';
        mkdir($testApp . '/config', 0777, true);
        $body = <<<EOD
<?php
return array(
\t'hello' => 'Hello World.',
\t'advice' => 'Whatever advice you give, be short.',
\t'error' => 'To err is human, but for a real disaster you need a computer.'
);
?>
EOD;
        $filepath = $testApp . '/config/messages.php';
        file_put_contents($filepath, $body);
        Libraries::add('test_app', array('path' => $testApp));
        FlashMessage::config(array('library' => 'test_app'));
        $messages = array('hello', 'advice', 'error');
        FlashMessage::write($messages);
        $expected = array('message' => array('Hello World.', 'Whatever advice you give, be short.', 'To err is human, but for a real disaster you need a computer.'), 'attrs' => array());
        $result = FlashMessage::read('flash_message');
        $this->assertEqual($expected, $result);
        $message = 'hello';
        FlashMessage::write($message);
        $expected = array('message' => 'Hello World.', 'attrs' => array());
        $result = FlashMessage::read('flash_message');
        $this->assertEqual($expected, $result);
        $this->_cleanUp();
    }