PageRenderTime 74ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/models/eimadmin/ProjectAdminGatewayTest.php

https://bitbucket.org/wildanm/orangehrm
PHP | 661 lines | 401 code | 126 blank | 134 comment | 4 complexity | e4919fdf9c21a9ca0dcc7f30f036a424 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, AGPL-3.0, BSD-3-Clause, AGPL-1.0, GPL-2.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
  4. * all the essential functionalities required for any enterprise.
  5. * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
  6. *
  7. * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
  8. * the GNU General Public License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program;
  16. * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA
  18. *
  19. */
  20. // Call ProjectAdminGatewayTest::main() if this source file is executed directly.
  21. if (!defined("PHPUnit_MAIN_METHOD")) {
  22. define("PHPUnit_MAIN_METHOD", "ProjectAdminGatewayTest::main");
  23. }
  24. require_once "PHPUnit/Framework/TestCase.php";
  25. require_once "PHPUnit/Framework/TestSuite.php";
  26. require_once "testConf.php";
  27. require_once ROOT_PATH."/lib/confs/Conf.php";
  28. require_once ROOT_PATH . '/lib/exception/ExceptionHandler.php';
  29. require_once ROOT_PATH . "/lib/models/eimadmin/Projects.php";
  30. require_once ROOT_PATH . "/lib/models/eimadmin/ProjectAdminGateway.php";
  31. /**
  32. * Test class for ProjectAdminGateway.
  33. * Generated by PHPUnit_Util_Skeleton on 2007-07-11 at 17:15:40.
  34. */
  35. class ProjectAdminGatewayTest extends PHPUnit_Framework_TestCase {
  36. private $errorLevel;
  37. private $errorStr;
  38. /**
  39. * Runs the test methods of this class.
  40. *
  41. * @access public
  42. * @static
  43. */
  44. public static function main() {
  45. require_once "PHPUnit/TextUI/TestRunner.php";
  46. $suite = new PHPUnit_Framework_TestSuite("ProjectAdminGatewayTest");
  47. $result = PHPUnit_TextUI_TestRunner::run($suite);
  48. }
  49. /**
  50. * Sets up the fixture, for example, open a network connection.
  51. * This method is called before a test is executed.
  52. *
  53. * @access protected
  54. */
  55. protected function setUp() {
  56. $conf = new Conf();
  57. $this->connection = mysql_connect($conf->dbhost.":".$conf->dbport, $conf->dbuser, $conf->dbpass);
  58. mysql_select_db($conf->dbname);
  59. mysql_query("TRUNCATE TABLE `hs_hr_project`", $this->connection);
  60. mysql_query("TRUNCATE TABLE `hs_hr_project_admin`", $this->connection);
  61. mysql_query("TRUNCATE TABLE `hs_hr_customer`", $this->connection);
  62. mysql_query("TRUNCATE TABLE `hs_hr_employee`", $this->connection);
  63. // Insert a project and customer and employees for use in the test
  64. mysql_query("INSERT INTO hs_hr_customer(customer_id, name, description, deleted) " .
  65. "VALUES(1, 'Test customer', 'description', 0)");
  66. mysql_query("INSERT INTO hs_hr_project(project_id, customer_id, name, description, deleted) " .
  67. "VALUES(1, 1, 'Test project 1', 'a test proj 1', 0)");
  68. mysql_query("INSERT INTO hs_hr_project(project_id, customer_id, name, description, deleted) " .
  69. "VALUES(2, 1, 'Test project 2', 'a test proj 2', 0)");
  70. mysql_query("INSERT INTO hs_hr_employee(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name) " .
  71. "VALUES(1, '0011', 'Rajasinghe', 'Saman', 'Marlon')");
  72. mysql_query("INSERT INTO hs_hr_employee(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name) " .
  73. "VALUES(2, '0022', 'Jayasinghe', 'Aruna', 'Shantha')");
  74. mysql_query("INSERT INTO hs_hr_employee(emp_number, employee_id, emp_lastname, emp_firstname, emp_middle_name) " .
  75. "VALUES(3, '0034', 'Ranasinghe', 'Nimal', 'Bandara')");
  76. }
  77. /**
  78. * Tears down the fixture, for example, close a network connection.
  79. * This method is called after a test is executed.
  80. *
  81. * @access protected
  82. */
  83. protected function tearDown() {
  84. mysql_query("TRUNCATE TABLE `hs_hr_project`", $this->connection);
  85. mysql_query("TRUNCATE TABLE `hs_hr_project_admin`", $this->connection);
  86. mysql_query("TRUNCATE TABLE `hs_hr_customer`", $this->connection);
  87. mysql_query("TRUNCATE TABLE `hs_hr_employee`", $this->connection);
  88. }
  89. /**
  90. * @todo Implement testAddAdmin().
  91. */
  92. public function testAddAdmin() {
  93. $gw = new ProjectAdminGateway();
  94. // Verify that invalid project id's emp numbers throw exceptions
  95. try {
  96. $gw->addAdmin($projectId = "", $empNumber = 12);
  97. $this->fail("Exception not thrown");
  98. } catch (ProjectAdminException $e) {
  99. $this->assertEquals(0, $this->_countAdmins(), "No rows should be inserted");
  100. }
  101. try {
  102. $gw->addAdmin($projectId = "test", $empNumber = 12);
  103. $this->fail("Exception not thrown");
  104. } catch (ProjectAdminException $e) {
  105. $this->assertEquals(0, $this->_countAdmins(), "No rows should be inserted");
  106. }
  107. try {
  108. $gw->addAdmin($projectId = 1, $empNumber = "");
  109. $this->fail("Exception not thrown");
  110. } catch (ProjectAdminException $e) {
  111. $this->assertEquals(0, $this->_countAdmins(), "No rows should be inserted");
  112. }
  113. try {
  114. $gw->addAdmin($projectId = 1, $empNumber = "xyz");
  115. $this->fail("Exception not thrown");
  116. } catch (ProjectAdminException $e) {
  117. $this->assertEquals(0, $this->_countAdmins(), "No rows should be inserted");
  118. }
  119. // Verify that add using non existent projects and employee id's throws an error
  120. $this->_clearError();
  121. set_error_handler(array($this, 'errorHandler'));
  122. $this->assertFalse($gw->addAdmin($projectId = 11, $empNumber = 12));
  123. restore_error_handler();
  124. $this->assertNotNull($this->errorLevel);
  125. $this->assertEquals(0, $this->_countAdmins());
  126. // valid project, invalid employee
  127. $this->_clearError();
  128. set_error_handler(array($this, 'errorHandler'));
  129. $this->assertFalse($gw->addAdmin($projectId = 1, $empNumber = 4));
  130. restore_error_handler();
  131. $this->assertNotNull($this->errorLevel);
  132. $this->assertEquals(0, $this->_countAdmins());
  133. // invalid project, valid employee
  134. $this->_clearError();
  135. set_error_handler(array($this, 'errorHandler'));
  136. $this->assertFalse($gw->addAdmin($projectId = 12, $empNumber = 1));
  137. restore_error_handler();
  138. $this->assertNotNull($this->errorLevel);
  139. $this->assertEquals(0, $this->_countAdmins());
  140. // valid admin
  141. $gw->addAdmin($projectId = 1, $empNumber = 2);
  142. $this->assertEquals(1, $this->_countAdmins());
  143. $this->assertEquals(1, $this->_countAdmins("project_id = 1 AND emp_number = 2"));
  144. // adding the same admin again should not change anything
  145. $gw->addAdmin($projectId = 1, $empNumber = 2);
  146. $this->assertEquals(1, $this->_countAdmins());
  147. $this->assertEquals(1, $this->_countAdmins("project_id = 1 AND emp_number = 2"));
  148. // Add the same employee as admin to a different project
  149. $gw->addAdmin($projectId = 2, $empNumber = 2);
  150. $this->assertEquals(2, $this->_countAdmins());
  151. $this->assertEquals(2, $this->_countAdmins("emp_number = 2"));
  152. $this->assertEquals(1, $this->_countAdmins("project_id = 2 AND emp_number = 2"));
  153. $this->assertEquals(1, $this->_countAdmins("project_id = 2 AND emp_number = 2"));
  154. }
  155. /**
  156. * Test removeAdmin() method
  157. */
  158. public function testRemoveAdmin() {
  159. $gw = new ProjectAdminGateway();
  160. $this->_insertAdmins();
  161. // Verify that invalid project id's emp numbers throw exceptions
  162. try {
  163. $gw->removeAdmin($projectId = "", $empNumber = 12);
  164. $this->fail("Exception not thrown");
  165. } catch (ProjectAdminException $e) {
  166. $this->assertEquals(3, $this->_countAdmins(), "No rows should be removed");
  167. }
  168. try {
  169. $gw->removeAdmin($projectId = "test", $empNumber = 12);
  170. $this->fail("Exception not thrown");
  171. } catch (ProjectAdminException $e) {
  172. $this->assertEquals(3, $this->_countAdmins(), "No rows should be removed");
  173. }
  174. try {
  175. $gw->removeAdmin($projectId = 1, $empNumber = "");
  176. $this->fail("Exception not thrown");
  177. } catch (ProjectAdminException $e) {
  178. $this->assertEquals(3, $this->_countAdmins(), "No rows should be removed");
  179. }
  180. try {
  181. $gw->removeAdmin($projectId = 1, $empNumber = "xyz");
  182. $this->fail("Exception not thrown");
  183. } catch (ProjectAdminException $e) {
  184. $this->assertEquals(3, $this->_countAdmins(), "No rows should be removed");
  185. }
  186. // empNumber invalid, project invalid
  187. $this->assertFalse($gw->removeAdmin($projectId = 111, $empNumber = 23));
  188. $this->assertEquals(3, $this->_countAdmins());
  189. // empNumber invalid, project valid
  190. $this->assertFalse($gw->removeAdmin($projectId = 2, $empNumber = 9));
  191. $this->assertEquals(3, $this->_countAdmins());
  192. // empNumber valid but not admin, project invalid
  193. $this->assertFalse($gw->removeAdmin($projectId = 13, $empNumber = 3));
  194. $this->assertEquals(3, $this->_countAdmins());
  195. // empNumber valid but not admin, project valid
  196. $this->assertFalse($gw->removeAdmin($projectId = 1, $empNumber = 3));
  197. $this->assertEquals(3, $this->_countAdmins());
  198. // empNumber valid, admin for different project.
  199. $this->assertFalse($gw->removeAdmin($projectId = 2, $empNumber = 1));
  200. $this->assertEquals(3, $this->_countAdmins());
  201. // empNumber valid, admin for given project.
  202. $this->assertTrue($gw->removeAdmin($projectId = 1, $empNumber = 1));
  203. $this->assertEquals(2, $this->_countAdmins());
  204. $this->assertEquals(0, $this->_countAdmins("emp_number = 1"));
  205. // attempt remove again.
  206. $this->assertFalse($gw->removeAdmin($projectId = 1, $empNumber = 1));
  207. $this->assertEquals(2, $this->_countAdmins());
  208. // Remove admin with multiple projects from one project
  209. $this->assertTrue($gw->removeAdmin($projectId = 1, $empNumber = 2));
  210. $this->assertEquals(1, $this->_countAdmins());
  211. $this->assertEquals(1, $this->_countAdmins("emp_number = 2 AND project_id = 2"));
  212. }
  213. /**
  214. * Tests removeAdmins() method.
  215. */
  216. public function testRemoveAdmins() {
  217. $gw = new ProjectAdminGateway();
  218. $this->_insertAdmins();
  219. // Verify that invalid project id's emp numbers throw exceptions
  220. try {
  221. $gw->removeAdmins($projectId = "", array(12));
  222. $this->fail("Exception not thrown");
  223. } catch (ProjectAdminException $e) {
  224. // Expected
  225. }
  226. try {
  227. $gw->removeAdmins($projectId = "test", array(12));
  228. $this->fail("Exception not thrown");
  229. } catch (ProjectAdminException $e) {
  230. // Expected
  231. }
  232. try {
  233. $gw->removeAdmins($projectId = null, array(12));
  234. $this->fail("Exception not thrown");
  235. } catch (ProjectAdminException $e) {
  236. // Expected
  237. }
  238. try {
  239. $gw->removeAdmins($projectId = 1, array(12, ""));
  240. $this->fail("Exception not thrown");
  241. } catch (ProjectAdminException $e) {
  242. // Expected
  243. }
  244. try {
  245. $gw->removeAdmins($projectId = 1, array(1, "xyz"));
  246. $this->fail("Exception not thrown");
  247. } catch (ProjectAdminException $e) {
  248. // Expected
  249. }
  250. try {
  251. $gw->removeAdmins($projectId = 1, null);
  252. $this->fail("Exception not thrown");
  253. } catch (ProjectAdminException $e) {
  254. // Expected
  255. }
  256. // Pass empty array, valid project Id
  257. $this->assertEquals(0, $gw->removeAdmins($projectId = 1, $empList = array()));
  258. $this->assertEquals(3, $this->_countAdmins());
  259. // Remove one admin, invalid empNumber
  260. $this->assertEquals(0, $gw->removeAdmins($projectId = 1, $empList = array(12)));
  261. $this->assertEquals(3, $this->_countAdmins());
  262. // Remove one admin, valid empNumber but not admin
  263. $this->assertEquals(0, $gw->removeAdmins($projectId = 1, $empList = array(3)));
  264. $this->assertEquals(3, $this->_countAdmins());
  265. // Remove one admin, valid empNumber and admin but wrong project
  266. $this->assertEquals(0, $gw->removeAdmins($projectId = 2, $empList = array(1)));
  267. $this->assertEquals(3, $this->_countAdmins());
  268. // Remove one admin, valid empNumber and admin for given project
  269. $this->assertEquals(1, $gw->removeAdmins($projectId = 1, $empList = array(1)));
  270. $this->assertEquals(2, $this->_countAdmins());
  271. $this->assertEquals(0, $this->_countAdmins("emp_number = 1"));
  272. $this->_deleteAllAdmins();
  273. $this->_insertAdmins();
  274. // Remove two admins, one valid, the other invalid
  275. $this->assertEquals(1, $gw->removeAdmins($projectId = 1, $empList = array(2, 12)));
  276. $this->assertEquals(2, $this->_countAdmins());
  277. $this->assertEquals(1, $this->_countAdmins("emp_number = 2"));
  278. $this->_deleteAllAdmins();
  279. $this->_insertAdmins();
  280. // Remove two admins, both valid admins but invalid project Id
  281. $this->assertEquals(0, $gw->removeAdmins($projectId = 14, $empList = array(2, 1)));
  282. $this->assertEquals(3, $this->_countAdmins());
  283. $this->assertTrue(mysql_query("INSERT INTO hs_hr_project_admin(emp_number, project_id) " .
  284. "VALUES(3, 1)"));
  285. $this->assertEquals(1, mysql_affected_rows());
  286. // Remove three admins, both valid admins
  287. $this->assertEquals(3, $gw->removeAdmins($projectId = 1, $empList = array(1, 2, 3)));
  288. $this->assertEquals(1, $this->_countAdmins());
  289. $this->assertEquals(1, $this->_countAdmins("emp_number = 2 AND project_id = 2"));
  290. }
  291. /**
  292. * Tests getAdmins() method.
  293. */
  294. public function testGetAdmins() {
  295. $gw = new ProjectAdminGateway();
  296. // Verify that invalid project ids throw exceptions
  297. try {
  298. $gw->getAdmins("");
  299. $this->fail("Exception not thrown");
  300. } catch (ProjectAdminException $e) {
  301. // Expected
  302. }
  303. try {
  304. $gw->getAdmins("xier");
  305. $this->fail("Exception not thrown");
  306. } catch (ProjectAdminException $e) {
  307. // Expected
  308. }
  309. try {
  310. $gw->getAdmins(null);
  311. $this->fail("Exception not thrown");
  312. } catch (ProjectAdminException $e) {
  313. // Expected
  314. }
  315. // Get admins for invalid project
  316. $list = $gw->getAdmins(12);
  317. $this->assertTrue(is_array($list));
  318. $this->assertEquals(0, count($list));
  319. mysql_query("INSERT INTO hs_hr_project(project_id, customer_id, name, description, deleted) " .
  320. "VALUES(21, 1, 'Test project 1', 'a test proj 1', 0)");
  321. // Get admins for valid project with no admins
  322. $list = $gw->getAdmins(21);
  323. $this->assertTrue(is_array($list));
  324. $this->assertEquals(0, count($list));
  325. $this->_deleteAllAdmins();
  326. $this->_insertAdmins();
  327. // Get admins for valid project with 1 admin
  328. $list = $gw->getAdmins(2);
  329. $this->assertTrue(is_array($list));
  330. $this->assertEquals(1, count($list));
  331. $admin = $list[0];
  332. $this->assertTrue($admin instanceof ProjectAdmin);
  333. $this->assertEquals(2, $admin->getEmpNumber());
  334. $this->assertEquals('Aruna', $admin->getFirstName());
  335. $this->assertEquals('Jayasinghe', $admin->getLastName());
  336. // Get admin for valid project with 2 admins
  337. $list = $gw->getAdmins(1);
  338. $this->assertTrue(is_array($list));
  339. $this->assertEquals(2, count($list));
  340. $validResults = array( 1 => array('Saman', 'Rajasinghe'), 2 => array('Aruna', 'Jayasinghe'));
  341. foreach ($list as $admin) {
  342. $empNo = $admin->getEmpNumber();
  343. $lastName = $admin->getLastName();;
  344. $this->assertTrue(array_key_exists($empNo, $validResults));
  345. $this->assertEquals($validResults[$empNo][0], $admin->getFirstName());
  346. $this->assertEquals($validResults[$empNo][1], $admin->getLastName());
  347. unset($validResults[$empNo]);
  348. }
  349. }
  350. /**
  351. * Tests the isAdmin() method.
  352. */
  353. public function testIsAdmin() {
  354. $gw = new ProjectAdminGateway();
  355. // Verify that invalid project id's emp numbers throw exceptions
  356. try {
  357. $gw->isAdmin($empNumber = 12, $projectId = "");
  358. $this->fail("Exception not thrown");
  359. } catch (ProjectAdminException $e) {
  360. // Expected.
  361. }
  362. try {
  363. $gw->isAdmin($empNumber = 12, $projectId = "test");
  364. $this->fail("Exception not thrown");
  365. } catch (ProjectAdminException $e) {
  366. // Expected.
  367. }
  368. try {
  369. $gw->isAdmin($empNumber = "", $projectId = 1);
  370. $this->fail("Exception not thrown");
  371. } catch (ProjectAdminException $e) {
  372. // Expected.
  373. }
  374. try {
  375. $gw->isAdmin($empNumber = "xyz", $projectId = 1);
  376. $this->fail("Exception not thrown");
  377. } catch (ProjectAdminException $e) {
  378. // Expected.
  379. }
  380. try {
  381. $gw->isAdmin($empNumber = 1, $projectId = null);
  382. } catch (ProjectAdminException $e) {
  383. $this->fail("null project id should be allowed.");
  384. }
  385. // valid employee but not admin
  386. $this->assertFalse($gw->isAdmin($empNumber = 1, $projectId = 1));
  387. $this->assertFalse($gw->isAdmin($empNumber = 1, $projectId = 11));
  388. $this->assertFalse($gw->isAdmin($empNumber = 1));
  389. // invalid emp number
  390. $this->assertFalse($gw->isAdmin($empNumber = 13, $projectId = 1));
  391. $this->assertFalse($gw->isAdmin($empNumber = 188, $projectId = 11));
  392. $this->assertFalse($gw->isAdmin($empNumber = 15));
  393. $this->_insertAdmins();
  394. // valid admin, correct project.
  395. $this->assertTrue($gw->isAdmin($empNumber = 1, $projectId = 1));
  396. // valid admin, without giving a project
  397. $this->assertTrue($gw->isAdmin($empNumber = 1));
  398. // valid admin, incorrect/invalid project.
  399. $this->assertFalse($gw->isAdmin($empNumber = 1, $projectId = 2));
  400. $this->assertFalse($gw->isAdmin($empNumber = 1, $projectId = 12));
  401. // admin with multiple projects
  402. $this->assertTrue($gw->isAdmin($empNumber = 2, $projectId = 1));
  403. $this->assertTrue($gw->isAdmin($empNumber = 2, $projectId = 2));
  404. $this->assertTrue($gw->isAdmin($empNumber = 2));
  405. $this->assertFalse($gw->isAdmin($empNumber = 2, $projectId = 21));
  406. // Deleted projects not considered when project Id not given
  407. $this->assertTrue(mysql_query("UPDATE hs_hr_project SET deleted = 1 WHERE project_id = 1"));
  408. $this->assertEquals(1, mysql_affected_rows());
  409. $this->assertFalse($gw->isAdmin($empNumber = 1));
  410. $this->assertTrue($gw->isAdmin($empNumber = 1, $projectId = 1));
  411. $this->assertTrue(mysql_query("UPDATE hs_hr_project SET deleted = 1 WHERE project_id = 2"));
  412. $this->assertEquals(1, mysql_affected_rows());
  413. $this->assertFalse($gw->isAdmin($empNumber = 2));
  414. $this->assertTrue($gw->isAdmin($empNumber = 2, $projectId = 2));
  415. $this->assertTrue($gw->isAdmin($empNumber = 2, $projectId = 1));
  416. }
  417. /**
  418. * Test for getProjectsForAdmin() method.
  419. */
  420. public function testGetProjectsForAdmin() {
  421. $gw = new ProjectAdminGateway();
  422. // Verify that invalid emp numbers throw exceptions
  423. try {
  424. $gw->getProjectsForAdmin("");
  425. $this->fail("Exception not thrown");
  426. } catch (ProjectAdminException $e) {
  427. // Expected.
  428. }
  429. try {
  430. $gw->getProjectsForAdmin("aer");
  431. $this->fail("Exception not thrown");
  432. } catch (ProjectAdminException $e) {
  433. // Expected.
  434. }
  435. try {
  436. $gw->getProjectsForAdmin(null);
  437. $this->fail("Exception not thrown");
  438. } catch (ProjectAdminException $e) {
  439. // Expected.
  440. }
  441. // invalid emp number
  442. $list = $gw->getProjectsForAdmin(100);
  443. $this->assertTrue(is_array($list));
  444. $this->assertEquals(0, count($list));
  445. // valid emp, not an admin
  446. $list = $gw->getProjectsForAdmin(1);
  447. $this->assertTrue(is_array($list));
  448. $this->assertEquals(0, count($list));
  449. $this->_insertAdmins();
  450. // valid emp, admin of one project
  451. $list = $gw->getProjectsForAdmin(1);
  452. $this->assertTrue(is_array($list));
  453. $this->assertEquals(1, count($list));
  454. $proj = $list[0];
  455. $this->assertTrue($proj instanceof Projects);
  456. $this->assertEquals(1, $proj->getProjectId());
  457. $this->assertEquals('Test project 1', $proj->getProjectName());
  458. // valid emp, admin of multiple projects
  459. $list = $gw->getProjectsForAdmin(2);
  460. $this->assertTrue(is_array($list));
  461. $this->assertEquals(2, count($list));
  462. $validResults = array( 1 => 'Test project 1', 2 => 'Test project 2');
  463. foreach ($list as $proj) {
  464. $this->assertTrue($proj instanceof Projects);
  465. $id = $proj->getProjectId();
  466. $name = $proj->getProjectName();
  467. $this->assertTrue(array_key_exists($id, $validResults));
  468. $this->assertEquals($name, $validResults[$id]);
  469. unset($validResults[$id]);
  470. }
  471. // Verify that deleted projects are not returned by default
  472. $this->assertTrue(mysql_query("UPDATE hs_hr_project SET deleted = 1 WHERE project_id = 1"));
  473. $this->assertEquals(1, mysql_affected_rows());
  474. $list = $gw->getProjectsForAdmin(1);
  475. $this->assertTrue(is_array($list));
  476. $this->assertEquals(0, count($list));
  477. // deleted projects are returned when requested
  478. $list = $gw->getProjectsForAdmin(1, true);
  479. $this->assertTrue(is_array($list));
  480. $this->assertEquals(1, count($list));
  481. $proj = $list[0];
  482. $this->assertTrue($proj instanceof Projects);
  483. $this->assertEquals(1, $proj->getProjectId());
  484. $this->assertEquals('Test project 1', $proj->getProjectName());
  485. }
  486. public function errorHandler($errlevel, $errstr, $errfile='', $errline='', $errcontext=''){
  487. $this->errorLevel = $errlevel;
  488. $this->errorStr = $errstr;
  489. }
  490. private function _clearError() {
  491. $this->errorLevel = null;
  492. $this->errorStr = null;
  493. }
  494. /**
  495. * Counts project admins (with optional condition)
  496. *
  497. * @param string $where where clause
  498. * @return int number of rows
  499. */
  500. private function _countAdmins($where = null) {
  501. $sql = "SELECT COUNT(*) FROM hs_hr_project_admin";
  502. if (!empty($where)) {
  503. $sql .= " WHERE " . $where;
  504. }
  505. $result = mysql_query($sql);
  506. $row = mysql_fetch_array($result, MYSQL_NUM);
  507. $count = $row[0];
  508. return $count;
  509. }
  510. /**
  511. * Inserts some admins for use in the tests
  512. */
  513. private function _insertAdmins() {
  514. $this->assertTrue(mysql_query("INSERT INTO hs_hr_project_admin(emp_number, project_id) " .
  515. "VALUES(1, 1)"));
  516. $this->assertEquals(1, mysql_affected_rows());
  517. $this->assertTrue(mysql_query("INSERT INTO hs_hr_project_admin(emp_number, project_id) " .
  518. "VALUES(2, 1)"));
  519. $this->assertEquals(1, mysql_affected_rows());
  520. $this->assertTrue(mysql_query("INSERT INTO hs_hr_project_admin(emp_number, project_id) " .
  521. "VALUES(2, 2)"));
  522. $this->assertEquals(1, mysql_affected_rows());
  523. }
  524. /**
  525. * Clears project admin table
  526. */
  527. private function _deleteAllAdmins() {
  528. mysql_query("TRUNCATE TABLE hs_hr_project_admin");
  529. }
  530. }
  531. // Call ProjectAdminGatewayTest::main() if this source file is executed directly.
  532. if (PHPUnit_MAIN_METHOD == "ProjectAdminGatewayTest::main") {
  533. ProjectAdminGatewayTest::main();
  534. }
  535. ?>