diff --git a/phpunit.xml b/phpunit.xml index e111f91e4..1d6aebfe9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -17,7 +17,7 @@ - + + + + + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e8d0561cf..39262bc13 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -12,6 +12,8 @@ if (!defined('__DIR__')) { define('PATH_TRUNK', realpath(__DIR__ . '/../') . PATH_SEP); define('PATH_HOME', PATH_TRUNK . 'workflow' . PATH_SEP); +define('SYS_SYS', $GLOBALS['SYS_SYS']); + require PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'paths.php'; set_include_path( @@ -21,3 +23,19 @@ set_include_path( PATH_RBAC_CORE . PATH_SEPARATOR . get_include_path() ); + +// perpare propel env. +require_once "propel/Propel.php"; +require_once "creole/Creole.php"; + +Propel::init( PATH_CORE . "config/databases.php" ); + +//initialize required classes +G::LoadClass ('dbtable'); +G::LoadClass ('system'); + +//read memcached configuration +$config = System::getSystemConfiguration ('', '', SYS_SYS); +define ('MEMCACHED_ENABLED', $config ['memcached']); +define ('MEMCACHED_SERVER', $config ['memcached_server']); +define ('TIME_ZONE', $config ['time_zone']); \ No newline at end of file diff --git a/tests/unit/gulliver/system/GTest.php b/tests/unit/gulliver/system/GTest.php index 5ca29343c..932eeb89f 100644 --- a/tests/unit/gulliver/system/GTest.php +++ b/tests/unit/gulliver/system/GTest.php @@ -780,7 +780,7 @@ class GTest extends PHPUnit_Framework_TestCase */ public function testMySQLSintaxis() { - define('DB_ADAPTER', 'mysql'); + //define('DB_ADAPTER', 'mysql'); $this->assertTrue(G::MySQLSintaxis()); } diff --git a/tests/unit/workflow/engine/classes/AppSolrTest.php b/tests/unit/workflow/engine/classes/AppSolrTest.php new file mode 100644 index 000000000..2d9c5fe72 --- /dev/null +++ b/tests/unit/workflow/engine/classes/AppSolrTest.php @@ -0,0 +1,248 @@ +object = new AppSolr ($solrConf ['solr_enabled'], $solrConf ['solr_host'], $solrConf ['solr_instance']); + } + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + /** + * @covers AppSolr::isSolrEnabled + */ + public function testIsSolrEnabled() + { + // display messages with --debug option + // print "XXXXXXXXXXXXXXXXXXXXX"; + $result = $this->object->isSolrEnabled (); + $this->assertEquals ($result, true, "Assert error testIsSolrEnabled"); + } + + /** + * @covers AppSolr::reindexAllApplications + * executed first to copy all the application records to the search server + * @depends testIsSolrEnabled + */ + public function testReindexAllApplications() + { + $this->object->reindexAllApplications (); + } + + /** + * @covers AppSolr::getCountApplicationsPMOS2 + * + * @depends testReindexAllApplications + */ + public function testGetCountApplicationsPMOS2() + { + $result = $this->object->getCountApplicationsPMOS2 (); + $this->assertGreaterThan (0, $result, "Assert error testGetCountApplicationsPMOS2"); + print "Applications count: " . $result . "\n"; + + return $result; + } + + + /** + * @covers AppSolr::getPagedApplicationUids + * + * @depends testGetCountApplicationsPMOS2 + */ + public function testGetPagedApplicationUids($totalNumApplications) + { + $pagesize = 2; + + $aAppUids = $this->object->getPagedApplicationUids(0, $pagesize); + + if($totalNumApplications >= $pagesize){ + $this->assertCount(2, $aAppUids, 'Error returned paginated list of AppUids'); + } + else{ + $this->assertGreaterThan(0, $aAppUids, 'No AppUids found'); + } + + return $aAppUids; + } + + /** + * @covers AppSolr::getAppGridData + * + * @depends testReindexAllApplications + */ + public function testGetAppGridData() + { + //$userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, $process = null, $user = null, + //$status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, $dir = null, $sort = 'APP_CACHE_VIEW.APP_NUMBER', $doCount = false + $userUid = '00000000000000000000000000000001'; //admin user + $start = 0; + $limit = 20; + $action = 'todo'; + $sort = 'APP_NUMBER'; + $dir = 'ASC'; + $result = $this->object->getAppGridData ($userUid, $start, $limit, $action, null, null, null, null, + null, null, null, null, null, $dir, $sort, false); + print_r($result); + if(!$result ['success']){ + $this->assertEmpty($result ['message'], 'The message is only display in not success'); + } + if(!$result ['result']){ + $this->assertCount(0, $result ['data'], 'Returned data when not success reported'); + } + + //verify the number of returned rows + print 'count results: ' . count($result ['data']); + //$this->assertGreaterThan($result ['totalCount'], count($result ['data']), 'The returned records are less than the total'); + + + + //test all the views + $userUid = '00000000000000000000000000000001'; //admin user + $start = 0; + $limit = 20; + $action = 'participated'; + $sort = 'APP_NUMBER'; + $dir = 'ASC'; + $result = $this->object->getAppGridData ($userUid, $start, $limit, $action, null, null, null, null, + null, null, null, null, null, $dir, $sort, false); + + + $userUid = '00000000000000000000000000000001'; //admin user + $start = 0; + $limit = 20; + $action = 'draft'; + $sort = 'APP_NUMBER'; + $dir = 'ASC'; + $result = $this->object->getAppGridData ($userUid, $start, $limit, $action, null, null, null, null, + null, null, null, null, null, $dir, $sort, false); + + $userUid = '00000000000000000000000000000001'; //admin user + $start = 0; + $limit = 20; + $action = 'unassigned'; + $sort = 'APP_NUMBER'; + $dir = 'ASC'; + $result = $this->object->getAppGridData ($userUid, $start, $limit, $action, null, null, null, null, + null, null, null, null, null, $dir, $sort, false); + + //test search functionality + + + } + + /** + * @covers AppSolr::getCasesCount + * + */ + public function testGetCasesCount() + { + $userUid = '00000000000000000000000000000001'; + $result = $this->object->getCasesCount($userUid); + print_r($result); + $this->assertNotEmpty($result, 'Empty array of counters'); + } + + /** + * @covers AppSolr::updateApplicationSearchIndex + * + * @depends testGetPagedApplicationUids + */ + public function testUpdateApplicationSearchIndex($aAppUids) + { + + $this->object->updateApplicationSearchIndex($aAppUids); + + } + + /** + * @covers AppSolr::deleteApplicationSearchIndex + * + * @depends testGetPagedApplicationUids + */ + public function testDeleteApplicationSearchIndex($aAppUids) + { + $appUID = $aAppUids[0]['APP_UID']; + + $count = $this->object->getCountApplicationsSearchIndex(); + $this->object->deleteApplicationSearchIndex($appUID); + $count2 = $this->object->getCountApplicationsSearchIndex(); + + $this->assertEquals($count, $count2 + 1, 'Error deleting application in search index'); + + //leave index as in the beginning + $this->object->reindexAllApplications(); + + $count3 = $this->object->getCountApplicationsSearchIndex(); + + $this->assertEquals($count, $count3, 'Error restoring deleted application in search index'); + } + + + /** + * @covers AppSolr::applicationChangedUpdateSolrQueue + * + * @depends testGetPagedApplicationUids + */ + public function testApplicationChangedUpdateSolrQueue($aAppUids) + { + $appUID = $aAppUids[0]['APP_UID']; + + //mark application for deletion + $this->object->applicationChangedUpdateSolrQueue($appUID, 2); //to delete + + } + + /** + * @covers AppSolr::synchronizePendingApplications + * + * @depends testApplicationChangedUpdateSolrQueue + */ + public function testSynchronizePendingApplications() + { + //count number of indexed applications + $count = $this->object->getCountApplicationsSearchIndex(); + + print "Total applications:" . $count; + //delete application marked in previous test + $this->object->synchronizePendingApplications(); + + $count2 = $this->object->getCountApplicationsSearchIndex(); + print "Total applications deleted record:" . $count2; + + $this->assertEquals($count, $count2 + 1, 'Error synchronizing applications in search index'); + + //leave index as in the beginning + $this->object->reindexAllApplications(); + + $count3 = $this->object->getCountApplicationsSearchIndex(); + + $this->assertEquals($count, $count3, 'Error restoring deleted application in search index'); + } + +} diff --git a/workflow/engine/classes/class.AppSolr.php b/workflow/engine/classes/class.AppSolr.php index fb8971b1c..23f001ea4 100644 --- a/workflow/engine/classes/class.AppSolr.php +++ b/workflow/engine/classes/class.AppSolr.php @@ -193,6 +193,7 @@ class AppSolr $swErrorInSearchText = false; $solrQueryResult = null; + $aPriorities = array('1'=>'VL', '2'=>'L', '3'=>'N', '4'=>'H', '5'=>'VH'); $result = array (); $result ['totalCount'] = 0; @@ -492,6 +493,7 @@ class AppSolr $aRow ['PREVIOUS_USR_UID'] = $row ['PREVIOUS_USR_UID']; $aRow ['TAS_UID'] = $row ['TAS_UID']; $aRow ['USR_UID'] = $userUid; + $aRow ['DEL_PRIORITY'] = G::LoadTranslation("ID_PRIORITY_{$aPriorities[$aRow['DEL_PRIORITY']]}"); $rows [] = $aRow; } @@ -957,9 +959,10 @@ class AppSolr return; // check if index server is available - if (! $this->isSolrEnabled) { + if (! $this->_solrIsEnabled) { // store update in table and return $this->applicationChangedUpdateSolrQueue ($appUID ['APP_UID'], 2); // delete + return; } $idQuery = "APP_UID:" . $appUID; @@ -2002,7 +2005,12 @@ class AppSolr foreach ($aAppSolrQueue as $oAppSolrQueueEntity) { // call the syncronization function - $this->updateApplicationSearchIndex ($oAppSolrQueueEntity->appUid); + if($oAppSolrQueueEntity->appUpdated == 1){ + $this->updateApplicationSearchIndex ($oAppSolrQueueEntity->appUid); + } + if($oAppSolrQueueEntity->appUpdated == 2){ + $this->deleteApplicationSearchIndex ($oAppSolrQueueEntity->appUid); + } $this->applicationChangedUpdateSolrQueue ($oAppSolrQueueEntity->appUid, 0); } } @@ -2010,7 +2018,7 @@ class AppSolr /** * Get the total number of application records in database * - * @return application counter + * @return integer application counter */ public function getCountApplicationsPMOS2() { @@ -2023,6 +2031,20 @@ class AppSolr return $count; } + /** + * Get the total number of application records in search index + * + * @return integer application counter + */ + public function getCountApplicationsSearchIndex() + { + $searchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost); + // execute query + $count = $searchIndex->getNumberDocuments ($this->_solrInstance); + + return $count; + } + /** * Get a paginated list of application uids from database. *