Created
June 20, 2011 09:22
-
-
Save luniki/1035357 to your computer and use it in GitHub Desktop.
AlertView4Stud.IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* AlertView.php - render an alert message to the user | |
* | |
* Copyright (c) 2011 mlunzena@uos.de | |
* | |
* This program is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU General Public License as | |
* published by the Free Software Foundation; either version 2 of | |
* the License, or (at your option) any later version. | |
*/ | |
class AlertView | |
{ | |
public $message, $buttons; | |
function __construct($message, $defaultButton, $alternateButton = null, | |
$otherButtons = null /*, ... */) | |
{ | |
$this->message = $message; | |
$this->buttons = array('default' => $defaultButton); | |
if ($alternateButton) { | |
$this->buttons['alternate'] = $alternateButton; | |
} | |
if ($otherButtons) { | |
$buttons = func_get_args(); | |
$this->buttons['others'] = array_slice($buttons, 3); | |
} | |
} | |
function addButton($button) | |
{ | |
} | |
function numberOfButtons() | |
{ | |
} | |
function render() | |
{ | |
global $template_factory; | |
return $template_factory->render('shared/alert', array('alert' => $this)); | |
} | |
function toString() | |
{ | |
return $this->render(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* alert_view_test.php - TODO | |
* | |
* Copyright (c) 2011 mlunzena | |
* | |
* This program is free software; you can redistribute it and/or | |
* modify it under the terms of the GNU General Public License as | |
* published by the Free Software Foundation; either version 2 of | |
* the License, or (at your option) any later version. | |
*/ | |
require_once 'lib/classes/AlertView.php'; | |
require_once 'lib/language.inc.php'; | |
class AlertViewTest extends UnitTestCase | |
{ | |
function setUp() | |
{ | |
$this->original_factory = $GLOBALS['template_factory']; | |
$GLOBALS['template_factory'] = new Flexi_TemplateFactory(dirname(__FILE__) . '/../../../templates'); | |
} | |
function tearDown() | |
{ | |
$GLOBALS['template_factory'] = $this->original_factory; | |
} | |
function makeButton($title, $action, $method) | |
{ | |
return (object) compact("title", "action", "method"); | |
} | |
function testTokenGeneration() | |
{ | |
$default = $this->makeButton("ok", "/button/ok", "post"); | |
$alternate = $this->makeButton("cancel", "/button/cancel", "post"); | |
$other1 = $this->makeButton("other 1", "/button/other1", "post"); | |
$other2 = $this->makeButton("other 2", "/button/other2", "post"); | |
$alert = new AlertView("my message", $default, $alternate, $other1, $other2); | |
var_dump($alert->render()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment