<?php /** * API addLabel Unit tests for HTML_Progress2 class. * * @version $Id: HTML_Progress2_TestCase_addLabel.php,v 1.2 2005/08/18 09:40:39 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @ignore */ class HTML_Progress2_TestCase_addLabel extends PHPUnit_TestCase { /** * HTML_Progress2 instance * * @var object */ var $progress; function HTML_Progress2_TestCase_addLabel($name) { $this->PHPUnit_TestCase($name); } function setUp() { error_reporting(E_ALL & ~E_NOTICE); $prefs= array('push_callback' => array(&$this, '_handleError')); $this->progress = new HTML_Progress2($prefs); } function tearDown() { unset($this->progress); } function _methodExists($name) { if (substr(PHP_VERSION,0,1) < '5') { $n = strtolower($name); } else { $n = $name; } if (in_array($n, get_class_methods($this->progress))) { return true; } $this->assertTrue(false, 'method '. $name . ' not implemented in ' . get_class($this->progress)); return false; } function _handleError($code, $level) { // don't die if the error is an exception (as default callback) return PEAR_ERROR_RETURN; } function _getResult() { if ($this->progress->hasErrors()) { $err = $this->progress->getError(); $msg = $err->getMessage() . ' >>'; $this->assertTrue(false, $msg); } else { $this->assertTrue(true); } } /** * TestCases for method addLabel(). */ function test_addLabel_fail_label_type_invalid() { if (!$this->_methodExists('addLabel')) { return; } $this->progress->addLabel('longtext', 'lng1'); $this->_getResult(); } function test_addLabel_fail_label_name_invalid() { if (!$this->_methodExists('addLabel')) { return; } $this->progress->addLabel('text', 1); $this->_getResult(); } function test_addLabel_fail_label_value_invalid() { if (!$this->_methodExists('addLabel')) { return; } $this->progress->addLabel(HTML_PROGRESS2_LABEL_TEXT, 'txt1', null); $this->_getResult(); } function test_addLabel_fail_label_exists() { if (!$this->_methodExists('addLabel')) { return; } $this->progress->addLabel(HTML_PROGRESS2_LABEL_PERCENT, 'pct1'); $this->_getResult(); } function test_addLabel() { if (!$this->_methodExists('addLabel')) { return; } $this->progress->addLabel(HTML_PROGRESS2_LABEL_BUTTON, 'btn1', 'OK'); $this->_getResult(); } } ?>