Source for file InvalidCompHandler.php

Documentation is available at InvalidCompHandler.php

  1. <?php
  2. /**
  3. * Test the InvalidCompHandler class
  4. *
  5. * This file is part of CompInaBox.
  6. * @package Tests
  7. * @subpackage InputControllers
  8. * @author Eric D. Nielsen <nielsene@alum.mit.edu>
  9. * @copyright CompInaBox Copyright 2005, Eric D. Nielsen. All Rights Reserved.
  10. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11. */
  12.  
  13. /** Load the to be tested class */
  14. (COMPINABOX.'include/classes/handlers/InvalidCompHandler.inc');
  15.  
  16. require_once(COMPINABOX.'include/classes/contexts/Context.inc');
  17. require_once(COMPINABOX.'include/classes/database/DB.inc');
  18. require_once(COMPINABOX.'include/classes/database/QueryResult.inc');
  19. require_once(COMPINABOX.'include/classes/phrasebook/PhraseBook.inc');
  20. Mock::generate("DB");
  21. Mock::generate("QueryResult");
  22. Mock::generate("PhraseBook");
  23. Mock::generate("Context");
  24. /**
  25. * TestInvalidCompHandler_canHandle
  26. * @package Tests
  27. * @subpackage InputControllers
  28. */
  29. class TestInvalidCompHandler_canHandle extends UnitTestCase {
  30. var $context;
  31. var $request;
  32. var $savedState;
  33. var $db;
  34. var $pb;
  35. var $qr;
  36. var $compName;
  37.  
  38. function TestInvalidCompHandler_canHandle() {
  39. $this->UnitTestCase('Test InvalidCompHandler -- canHandle');
  40. }
  41.  
  42. function setUp() {
  43. $this->context =& new MockContext($this);
  44. $this->db =& new MockDB($this);
  45. $this->pb =& new MockPhraseBook($this);
  46. $this->savedState=array("Get"=>$_GET,
  47. "Post"=>$_POST,
  48. "Cookie"=>$_COOKIE,
  49. "Server"=>$_SERVER);
  50. $_GET=array();
  51. $_POST=array();
  52. $_SERVER=array();
  53. $_COOKIE=array();
  54. $prefix="foo";
  55. $this->compName="bar";
  56. $scriptName="baz";
  57. $_SERVER["APP_REQUEST"]="$prefix/{$this->compName}/$scriptName";
  58. $this->request =& new SatelliteModuleRequest($prefix);
  59.  
  60. $the_query="Place Holder For Query";
  61. $this->context->expectOnce("getCentralDB");
  62. $this->context->setReturnReference("getCentralDB",$this->db);
  63. $this->context->expectOnce("getCorePhraseBook");
  64. $this->context->setReturnReference("getCorePhraseBook",$this->pb);
  65. $this->pb->setReturnValue("getQuery",$the_query);
  66. $this->qr =& new MockQueryResult($this);
  67. $this->qr->expectOnce("numrows");
  68. $this->db->expectOnce("query",array($the_query));
  69. $this->db->setReturnReference("query",$this->qr);
  70.  
  71.  
  72.  
  73.  
  74. }
  75. function tearDown() {
  76. $_GET=$this->savedState["Get"];
  77. $_POST=$this->savedState["Post"];
  78. $_COOKIE=$this->savedState["Cookie"];
  79. $_SERVER=$this->savedState["Server"];
  80. }
  81.  
  82. function testFailingCompName() {
  83. $this->pb->expectOnce("getQuery",array("Comp Exists?",
  84. array("CompName"=>$this->compName)));
  85. $this->qr->setReturnValue("numrows",0);
  86.  
  87. $handler =& new InvalidCompHandler();
  88. $this->assertTrue($handler->canHandle($this->context,$this->request));
  89.  
  90. $this->context->tally();
  91. $this->pb->tally();
  92. $this->db->tally();
  93. $this->qr->tally();
  94.  
  95. }
  96.  
  97. function testPassingCompName() {
  98. $this->pb->expectOnce("getQuery",array("Comp Exists?",
  99. array("CompName"=>$this->compName)));
  100. $this->qr->setReturnValue("numrows",1);
  101.  
  102. $handler =& new InvalidCompHandler();
  103. $this->assertFalse($handler->canHandle($this->context,$this->request));
  104.  
  105. $this->context->tally();
  106. $this->pb->tally();
  107. $this->db->tally();
  108. $this->qr->tally();
  109. }
  110.  
  111. function testPassingRequiredStatusOrAbove() {
  112. $status="OPEN";
  113. $this->pb->expectOnce("getQuery",array("Hosted Comp Exists?",
  114. array("CompName"=>$this->compName,
  115. "StatusThreshold"=>$status)));
  116. $this->qr->setReturnValue("numrows",1);
  117.  
  118. $handler =& new InvalidCompHandler($status);
  119. $this->assertFalse($handler->canHandle($this->context,$this->request));
  120.  
  121. $this->context->tally();
  122. $this->pb->tally();
  123. $this->db->tally();
  124. $this->qr->tally();
  125.  
  126. }
  127.  
  128. function testFailingRequiredStatusOrAbove() {
  129. $status="OPEN";
  130. $this->pb->expectOnce("getQuery",array("Hosted Comp Exists?",
  131. array("CompName"=>$this->compName,
  132. "StatusThreshold"=>$status)));
  133. $this->qr->setReturnValue("numrows",0);
  134.  
  135. $handler =& new InvalidCompHandler($status);
  136. $this->assertTrue($handler->canHandle($this->context,$this->request));
  137.  
  138. $this->context->tally();
  139. $this->pb->tally();
  140. $this->db->tally();
  141. $this->qr->tally();
  142. }
  143.  
  144. }
  145.  
  146. /**
  147. * TestInvalidCompHandler_execute
  148. * @package Tests
  149. * @subpackage InputControllers
  150. */
  151. class TestInvalidCompHandler_execute extends UnitTestCase {
  152. var $context;
  153. var $request;
  154. var $savedState;
  155. var $compName;
  156.  
  157. function TestInvalidCompHandler() {
  158. $this->UnitTestCase('Test InvalidCompHandler -- execute');
  159. }
  160.  
  161. function setUp() {
  162. $this->context =& new MockContext($this);
  163. $this->savedState=array("Get"=>$_GET,
  164. "Post"=>$_POST,
  165. "Cookie"=>$_COOKIE,
  166. "Server"=>$_SERVER);
  167. $_GET=array();
  168. $_POST=array();
  169. $_SERVER=array();
  170. $_COOKIE=array();
  171. $prefix="foo";
  172. $this->compName="bar";
  173. $scriptName="baz";
  174. $_SERVER["PHP_SELF"]="$prefix/{$this->compName}/$scriptName";
  175. $this->request =& new SatelliteModuleRequest($prefix);
  176. }
  177. function tearDown() {
  178. $_GET=$this->savedState["Get"];
  179. $_POST=$this->savedState["Post"];
  180. $_COOKIE=$this->savedState["Cookie"];
  181. $_SERVER=$this->savedState["Server"];
  182. }
  183.  
  184. function testExecute() {
  185. $handler =& new <a href="../InputControllers/Handlers/InvalidCompHandler.html">InvalidCompHandler</a>();
  186. $this->assertEqual($handler->execute($this->context, $this->request),
  187. "InvalidCompName");
  188. }
  189.  
  190. }
  191.  

Documentation generated on Tue, 25 Apr 2006 13:03:51 -0400 by phpDocumentor 1.3.0RC3