Documentation is available at InvalidCompHandler.php
- <?php
- /**
- * Test the InvalidCompHandler class
- *
- * This file is part of CompInaBox.
- * @package Tests
- * @subpackage InputControllers
- * @author Eric D. Nielsen <nielsene@alum.mit.edu>
- * @copyright CompInaBox Copyright 2005, Eric D. Nielsen. All Rights Reserved.
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- */
- /** Load the to be tested class */
- (COMPINABOX.'include/classes/handlers/InvalidCompHandler.inc');
- require_once(COMPINABOX.'include/classes/contexts/Context.inc');
- require_once(COMPINABOX.'include/classes/database/DB.inc');
- require_once(COMPINABOX.'include/classes/database/QueryResult.inc');
- require_once(COMPINABOX.'include/classes/phrasebook/PhraseBook.inc');
- Mock::generate("DB");
- Mock::generate("QueryResult");
- Mock::generate("PhraseBook");
- Mock::generate("Context");
- /**
- * TestInvalidCompHandler_canHandle
- * @package Tests
- * @subpackage InputControllers
- */
- class TestInvalidCompHandler_canHandle extends UnitTestCase {
- var $context;
- var $request;
- var $savedState;
- var $db;
- var $pb;
- var $qr;
- var $compName;
- function TestInvalidCompHandler_canHandle() {
- $this->UnitTestCase('Test InvalidCompHandler -- canHandle');
- }
- function setUp() {
- $this->context =& new MockContext($this);
- $this->db =& new MockDB($this);
- $this->pb =& new MockPhraseBook($this);
- $this->savedState=array("Get"=>$_GET,
- "Post"=>$_POST,
- "Cookie"=>$_COOKIE,
- "Server"=>$_SERVER);
- $_GET=array();
- $_POST=array();
- $_SERVER=array();
- $_COOKIE=array();
- $prefix="foo";
- $this->compName="bar";
- $scriptName="baz";
- $_SERVER["APP_REQUEST"]="$prefix/{$this->compName}/$scriptName";
- $this->request =& new SatelliteModuleRequest($prefix);
- $the_query="Place Holder For Query";
- $this->context->expectOnce("getCentralDB");
- $this->context->setReturnReference("getCentralDB",$this->db);
- $this->context->expectOnce("getCorePhraseBook");
- $this->context->setReturnReference("getCorePhraseBook",$this->pb);
- $this->pb->setReturnValue("getQuery",$the_query);
- $this->qr =& new MockQueryResult($this);
- $this->qr->expectOnce("numrows");
- $this->db->expectOnce("query",array($the_query));
- $this->db->setReturnReference("query",$this->qr);
- }
- function tearDown() {
- $_GET=$this->savedState["Get"];
- $_POST=$this->savedState["Post"];
- $_COOKIE=$this->savedState["Cookie"];
- $_SERVER=$this->savedState["Server"];
- }
- function testFailingCompName() {
- $this->pb->expectOnce("getQuery",array("Comp Exists?",
- array("CompName"=>$this->compName)));
- $this->qr->setReturnValue("numrows",0);
- $handler =& new InvalidCompHandler();
- $this->assertTrue($handler->canHandle($this->context,$this->request));
- $this->context->tally();
- $this->pb->tally();
- $this->db->tally();
- $this->qr->tally();
- }
- function testPassingCompName() {
- $this->pb->expectOnce("getQuery",array("Comp Exists?",
- array("CompName"=>$this->compName)));
- $this->qr->setReturnValue("numrows",1);
- $handler =& new InvalidCompHandler();
- $this->assertFalse($handler->canHandle($this->context,$this->request));
- $this->context->tally();
- $this->pb->tally();
- $this->db->tally();
- $this->qr->tally();
- }
- function testPassingRequiredStatusOrAbove() {
- $status="OPEN";
- $this->pb->expectOnce("getQuery",array("Hosted Comp Exists?",
- array("CompName"=>$this->compName,
- "StatusThreshold"=>$status)));
- $this->qr->setReturnValue("numrows",1);
- $handler =& new InvalidCompHandler($status);
- $this->assertFalse($handler->canHandle($this->context,$this->request));
- $this->context->tally();
- $this->pb->tally();
- $this->db->tally();
- $this->qr->tally();
- }
- function testFailingRequiredStatusOrAbove() {
- $status="OPEN";
- $this->pb->expectOnce("getQuery",array("Hosted Comp Exists?",
- array("CompName"=>$this->compName,
- "StatusThreshold"=>$status)));
- $this->qr->setReturnValue("numrows",0);
- $handler =& new InvalidCompHandler($status);
- $this->assertTrue($handler->canHandle($this->context,$this->request));
- $this->context->tally();
- $this->pb->tally();
- $this->db->tally();
- $this->qr->tally();
- }
- }
- /**
- * TestInvalidCompHandler_execute
- * @package Tests
- * @subpackage InputControllers
- */
- class TestInvalidCompHandler_execute extends UnitTestCase {
- var $context;
- var $request;
- var $savedState;
- var $compName;
- function TestInvalidCompHandler() {
- $this->UnitTestCase('Test InvalidCompHandler -- execute');
- }
- function setUp() {
- $this->context =& new MockContext($this);
- $this->savedState=array("Get"=>$_GET,
- "Post"=>$_POST,
- "Cookie"=>$_COOKIE,
- "Server"=>$_SERVER);
- $_GET=array();
- $_POST=array();
- $_SERVER=array();
- $_COOKIE=array();
- $prefix="foo";
- $this->compName="bar";
- $scriptName="baz";
- $_SERVER["PHP_SELF"]="$prefix/{$this->compName}/$scriptName";
- $this->request =& new SatelliteModuleRequest($prefix);
- }
- function tearDown() {
- $_GET=$this->savedState["Get"];
- $_POST=$this->savedState["Post"];
- $_COOKIE=$this->savedState["Cookie"];
- $_SERVER=$this->savedState["Server"];
- }
- function testExecute() {
- $handler =& new <a href="../InputControllers/Handlers/InvalidCompHandler.html">InvalidCompHandler</a>();
- $this->assertEqual($handler->execute($this->context, $this->request),
- "InvalidCompName");
- }
- }
Documentation generated on Tue, 25 Apr 2006 13:03:51 -0400 by phpDocumentor 1.3.0RC3