* @license PHP License * @package WB * @subpackage unittest */ WBClass::load('WBEvent_Handler_UnitTest'); /** * Unit Test * * @version 0.1.0 * @package WB * @subpackage unittest */ class TestCaseITSBase extends UnitTestCase { /** * Backend * @var WBITS */ private $its; /** * Current ticket * @var WBITS_Ticket */ private $ticket; const TICKET_OID = 'UNDD1'; public function __construct() { $this->its = WBClass::create('WBITS'); WBClass::load('WBUnitTest_SQLUte'); WBUnitTest_SQLUte::source(__FILE__,'construct'); } public function __destruct() { WBUnitTest_SQLUte::source(__FILE__, 'destruct'); } /** * simply set parameter * */ public function testInit() { $this->assertTrue(class_exists('WBITS', false)); $this->assertIsA($this->its, 'WBITS'); } public function TestLoadByObscureDoesNotExist() { $this->ticket = $this->its->loadByObscureId('DOES NOT EXIST'); $this->assertTrue(class_exists('WBITS_Ticket', false)); $this->assertIsA($this->ticket, 'WBITS_Ticket'); $this->assertTrue(empty($this->ticket->getId())); $this->assertTrue(empty($this->ticket->getObscureId())); $this->assertTrue(empty($this->ticket->getData())); } public function TestLoadByObscureKnown() { $this->ticket = $this->its->loadByObscureId(self::TICKET_OID); $this->assertIsA($this->ticket, 'WBITS_Ticket'); $id = $this->ticket->getId(); $obscure = $this->ticket->getObscureId(); $data = $this->ticket->getData(); $this->assertEqual($id, 1); $this->assertEqual($obscure, self::TICKET_OID); $this->assertFalse(empty($data)); $this->assertEqual($data['title'], 'Unittest Ticket #1'); $this->assertEqual($data['status'], 'new'); $this->assertEqual($data['blurb'], '
This is the description of the first unittest ticket.
'); $this->assertEqual(count($data['ticketmedia']), 2); } public function TestCreateNewTicket() { $events = 0; $this->ticket = $this->its->loadByObscureId(); $this->ticket->save(array( 'title' => 'Unittest Ticket #2', 'blurb' => 'Lots of description goes here
' )); $id = $this->ticket->getId(); $obscure = $this->ticket->getObscureId(); $data = $this->ticket->getData(); $this->assertEqual($data['title'], 'Unittest Ticket #2'); $this->assertEqual($data['status'], 'new'); $this->assertEqual($data['blurb'], 'Lots of description goes here
'); $this->assertEqual(count($data['ticketmedia']), 0); $this->verifyEventProc(1, 'its:ticket:new'); } public function TestAddMediaFile() { $this->ticket = $this->its->loadByObscureId(); $this->ticket->save(array( 'title' => 'Unittest Ticket #3', 'blurb' => 'Lots of description goes here
', 'ticketmedia' => array( '12', '13', '14' ) )); $this->verifyEventProc(1, 'its:ticket:new'); $data = $this->ticket->getData(); $this->assertEqual($data['title'], 'Unittest Ticket #3'); $this->assertEqual($data['status'], 'new'); $this->assertEqual($data['blurb'], 'Lots of description goes here
'); $this->assertEqual(count($data['ticketmedia']), 3); $this->ticket->save(array( 'ticketmedia' => array( '12', '13', '14', '15' ) )); $data = $this->ticket->getData(); $this->assertEqual(count($data['ticketmedia']), 4); $this->verifyEventProc(1, 'its:ticket:saved'); } protected function verifyEventProc($count, $name) { $list = WBEvent_Handler_UnitTest::getProclist('any'); WBEvent_Handler_UnitTest::flushList('any'); $this->assertEqual($count, count($list)); foreach ($list as $event) { $this->assertEqual($name, $event); } } }