diff --git a/module/search/test/lib/tao.class.php b/module/search/test/lib/tao.class.php index 531c92017d..a3eb69e132 100644 --- a/module/search/test/lib/tao.class.php +++ b/module/search/test/lib/tao.class.php @@ -141,4 +141,19 @@ class searchTaoTest extends baseTest if(dao::isError()) return dao::getError(); return $result; } + + /** + * Test checkProgramPriv method. + * + * @param array $results + * @param array $objectIdList + * @access public + * @return array + */ + public function checkProgramPrivTest(array $results, array $objectIdList): array + { + $result = $this->invokeArgs('checkProgramPriv', [$results, $objectIdList]); + if(dao::isError()) return dao::getError(); + return $result; + } } diff --git a/module/search/test/tao/checkprogrampriv.php b/module/search/test/tao/checkprogrampriv.php new file mode 100755 index 0000000000..303c5b50c7 --- /dev/null +++ b/module/search/test/tao/checkprogrampriv.php @@ -0,0 +1,59 @@ +#!/usr/bin/env php +id->range('1-10'); +$project->name->range('Program1,Program2,Program3,Program4,Program5,Program6,Program7,Program8,Program9,Program10'); +$project->code->range('code1,code2,code3,code4,code5,code6,code7,code8,code9,code10'); +$project->type->range('program'); +$project->status->range('doing'); +$project->acl->range('open'); +$project->parent->range('0'); +$project->gen(10); + +su('admin'); + +global $app; +$app->user->view = new stdClass(); +$app->user->view->programs = '1,3,5,6,7'; + +$searchTest = new searchTaoTest(); + +$results1 = array(1 => (object)array('id' => 1, 'objectID' => 1, 'objectType' => 'program', 'title' => 'Test Result 1')); +$objectIdList1 = array(1 => 1); +r($searchTest->checkProgramPrivTest($results1, $objectIdList1)) && p('1:objectID') && e('1'); + +$results2 = array(2 => (object)array('id' => 2, 'objectID' => 2, 'objectType' => 'program', 'title' => 'Test Result 2')); +$objectIdList2 = array(2 => 2); +r(count($searchTest->checkProgramPrivTest($results2, $objectIdList2))) && p() && e('0'); + +$results3 = array(); +$objectIdList3 = array(); +r(count($searchTest->checkProgramPrivTest($results3, $objectIdList3))) && p() && e('0'); + +$results4 = array(1 => (object)array('id' => 1, 'objectID' => 1, 'objectType' => 'program', 'title' => 'Test Result 1'), 2 => (object)array('id' => 2, 'objectID' => 2, 'objectType' => 'program', 'title' => 'Test Result 2'), 3 => (object)array('id' => 3, 'objectID' => 3, 'objectType' => 'program', 'title' => 'Test Result 3'), 4 => (object)array('id' => 4, 'objectID' => 4, 'objectType' => 'program', 'title' => 'Test Result 4')); +$objectIdList4 = array(1 => 1, 2 => 2, 3 => 3, 4 => 4); +r($searchTest->checkProgramPrivTest($results4, $objectIdList4)) && p('1:objectID;3:objectID') && e('1;3'); + +$results5 = array(1 => (object)array('id' => 1, 'objectID' => 8, 'objectType' => 'program', 'title' => 'Test Result 1'), 2 => (object)array('id' => 2, 'objectID' => 9, 'objectType' => 'program', 'title' => 'Test Result 2'), 3 => (object)array('id' => 3, 'objectID' => 10, 'objectType' => 'program', 'title' => 'Test Result 3')); +$objectIdList5 = array(8 => 1, 9 => 2, 10 => 3); +r(count($searchTest->checkProgramPrivTest($results5, $objectIdList5))) && p() && e('0'); \ No newline at end of file