2012-06-18 17:58:14 -04:00
|
|
|
<?php
|
|
|
|
|
// require_once PATH_HOME . PATH_SEP . "engine" . PATH_SEP . "classes" .
|
|
|
|
|
// PATH_SEP . "class.AppSolr.php";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2012-05-30 at 12:36:24.
|
|
|
|
|
*/
|
|
|
|
|
class AppSolrTest extends PHPUnit_Framework_TestCase
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @var AppSolr
|
|
|
|
|
*/
|
|
|
|
|
protected $object;
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
|
|
|
* This method is called before each test is executed.
|
|
|
|
|
*/
|
|
|
|
|
protected function setUp()
|
|
|
|
|
{
|
2012-07-04 17:13:44 -04:00
|
|
|
// get Solr initialization variables
|
|
|
|
|
// get Solr initialization variables
|
|
|
|
|
$solrConf = array(
|
|
|
|
|
'solr_enabled' => 1,
|
|
|
|
|
'solr_host' => 'localhost',
|
|
|
|
|
'solr_instance' => 'os'
|
|
|
|
|
);
|
2012-06-18 17:58:14 -04:00
|
|
|
G::LoadClass ('AppSolr');
|
|
|
|
|
$this->object = new AppSolr ($solrConf ['solr_enabled'], $solrConf ['solr_host'], $solrConf ['solr_instance']);
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* Tears down the fixture, for example, closes a network connection.
|
|
|
|
|
* This method is called after a test is executed.
|
|
|
|
|
*/
|
|
|
|
|
protected function tearDown()
|
|
|
|
|
{
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::isSolrEnabled
|
|
|
|
|
*/
|
|
|
|
|
public function testIsSolrEnabled()
|
|
|
|
|
{
|
|
|
|
|
// display messages with --debug option
|
|
|
|
|
// print "XXXXXXXXXXXXXXXXXXXXX";
|
|
|
|
|
$result = $this->object->isSolrEnabled ();
|
|
|
|
|
$this->assertEquals ($result, true, "Assert error testIsSolrEnabled");
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::reindexAllApplications
|
|
|
|
|
* executed first to copy all the application records to the search server
|
|
|
|
|
* @depends testIsSolrEnabled
|
|
|
|
|
*/
|
|
|
|
|
public function testReindexAllApplications()
|
|
|
|
|
{
|
|
|
|
|
$this->object->reindexAllApplications ();
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::getCountApplicationsPMOS2
|
|
|
|
|
*
|
|
|
|
|
* @depends testReindexAllApplications
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCountApplicationsPMOS2()
|
|
|
|
|
{
|
|
|
|
|
$result = $this->object->getCountApplicationsPMOS2 ();
|
|
|
|
|
$this->assertGreaterThan (0, $result, "Assert error testGetCountApplicationsPMOS2");
|
|
|
|
|
print "Applications count: " . $result . "\n";
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
return $result;
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
|
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::getPagedApplicationUids
|
|
|
|
|
*
|
|
|
|
|
* @depends testGetCountApplicationsPMOS2
|
|
|
|
|
*/
|
|
|
|
|
public function testGetPagedApplicationUids($totalNumApplications)
|
|
|
|
|
{
|
|
|
|
|
$pagesize = 2;
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$aAppUids = $this->object->getPagedApplicationUids(0, $pagesize);
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
if($totalNumApplications >= $pagesize){
|
|
|
|
|
$this->assertCount(2, $aAppUids, 'Error returned paginated list of AppUids');
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
$this->assertGreaterThan(0, $aAppUids, 'No AppUids found');
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
return $aAppUids;
|
2012-07-04 17:13:44 -04:00
|
|
|
}
|
|
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::getAppGridData
|
|
|
|
|
*
|
|
|
|
|
* @depends testReindexAllApplications
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAppGridData()
|
|
|
|
|
{
|
2012-07-04 17:13:44 -04:00
|
|
|
//$userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, $process = null, $user = null,
|
2012-06-18 17:58:14 -04:00
|
|
|
//$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';
|
2012-07-04 17:13:44 -04:00
|
|
|
$result = $this->object->getAppGridData ($userUid, $start, $limit, $action, null, null, null, null,
|
2012-06-18 17:58:14 -04:00
|
|
|
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');
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
//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');
|
|
|
|
|
|
2012-07-04 17:13:44 -04:00
|
|
|
|
|
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
//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,
|
2012-07-04 17:13:44 -04:00
|
|
|
null, null, null, null, null, $dir, $sort, false);
|
|
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
|
|
|
|
|
$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);
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
//test search functionality
|
2012-07-04 17:13:44 -04:00
|
|
|
|
|
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::getCasesCount
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function testGetCasesCount()
|
|
|
|
|
{
|
|
|
|
|
$userUid = '00000000000000000000000000000001';
|
|
|
|
|
$result = $this->object->getCasesCount($userUid);
|
2012-07-04 17:13:44 -04:00
|
|
|
print_r($result);
|
2012-06-18 17:58:14 -04:00
|
|
|
$this->assertNotEmpty($result, 'Empty array of counters');
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::updateApplicationSearchIndex
|
|
|
|
|
*
|
|
|
|
|
* @depends testGetPagedApplicationUids
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdateApplicationSearchIndex($aAppUids)
|
|
|
|
|
{
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$this->object->updateApplicationSearchIndex($aAppUids);
|
2012-07-04 17:13:44 -04:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::deleteApplicationSearchIndex
|
|
|
|
|
*
|
|
|
|
|
* @depends testGetPagedApplicationUids
|
|
|
|
|
*/
|
|
|
|
|
public function testDeleteApplicationSearchIndex($aAppUids)
|
|
|
|
|
{
|
|
|
|
|
$appUID = $aAppUids[0]['APP_UID'];
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$count = $this->object->getCountApplicationsSearchIndex();
|
|
|
|
|
$this->object->deleteApplicationSearchIndex($appUID);
|
|
|
|
|
$count2 = $this->object->getCountApplicationsSearchIndex();
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$this->assertEquals($count, $count2 + 1, 'Error deleting application in search index');
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
//leave index as in the beginning
|
|
|
|
|
$this->object->reindexAllApplications();
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$count3 = $this->object->getCountApplicationsSearchIndex();
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$this->assertEquals($count, $count3, 'Error restoring deleted application in search index');
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
|
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::applicationChangedUpdateSolrQueue
|
|
|
|
|
*
|
|
|
|
|
* @depends testGetPagedApplicationUids
|
|
|
|
|
*/
|
|
|
|
|
public function testApplicationChangedUpdateSolrQueue($aAppUids)
|
|
|
|
|
{
|
|
|
|
|
$appUID = $aAppUids[0]['APP_UID'];
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
//mark application for deletion
|
|
|
|
|
$this->object->applicationChangedUpdateSolrQueue($appUID, 2); //to delete
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
/**
|
|
|
|
|
* @covers AppSolr::synchronizePendingApplications
|
|
|
|
|
*
|
|
|
|
|
* @depends testApplicationChangedUpdateSolrQueue
|
|
|
|
|
*/
|
|
|
|
|
public function testSynchronizePendingApplications()
|
|
|
|
|
{
|
|
|
|
|
//count number of indexed applications
|
|
|
|
|
$count = $this->object->getCountApplicationsSearchIndex();
|
2012-07-04 17:13:44 -04:00
|
|
|
|
|
|
|
|
print "Total applications:" . $count;
|
2012-06-18 17:58:14 -04:00
|
|
|
//delete application marked in previous test
|
|
|
|
|
$this->object->synchronizePendingApplications();
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$count2 = $this->object->getCountApplicationsSearchIndex();
|
|
|
|
|
print "Total applications deleted record:" . $count2;
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$this->assertEquals($count, $count2 + 1, 'Error synchronizing applications in search index');
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
//leave index as in the beginning
|
|
|
|
|
$this->object->reindexAllApplications();
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$count3 = $this->object->getCountApplicationsSearchIndex();
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
$this->assertEquals($count, $count3, 'Error restoring deleted application in search index');
|
|
|
|
|
}
|
2012-07-04 17:13:44 -04:00
|
|
|
|
2012-06-18 17:58:14 -04:00
|
|
|
}
|