Changeset 1e8249e


Ignore:
Timestamp:
08/24/10 19:51:26 (21 months ago)
Author:
Benoit Grégoire <benoitg@…>
Branches:
('master', '8434b8322dd6f8ff37c17bd45b94e7a826f86b53')('vitrine', 'afe109c61a407808bd54d88bcccb1cde726a010a')
Children:
c644bf60405467e51cba29d863ad84bf11a27add
Parents:
df1a05b5c412f8cf82a7dada90cd6ab90cc88973
git-author:
Benoit Grégoire <benoitg@coeus.ca>2010-08-24 19:51:26-04:00
git-committer:
Benoit Grégoire <benoitg@coeus.ca>2010-08-24 19:51:26-04:00
Message:

Finish regression tests for future vocabulary traversal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • html/tests/VocabRelationshipNavigationTest.php

    rdf1a05b r1e8249e  
    33require_once dirname(dirname(__FILE__)).'/include/common.php'; 
    44require_once 'classes/Vocabulary.php'; 
    5  
     5require_once 'classes/Theme.php'; 
     6require_once 'classes/Lom.php'; 
     7require_once 'classes/SearchEngine.php'; 
    68class VocabRelationshipImportTest extends PHPUnit_Framework_TestCase 
    79{ 
    810    protected function setUp() 
    911    { 
     12 
     13 
     14        /* Otherwise everytime the test crashes the teardown won't be done properly */ 
     15        try { 
     16            $voc = new Vocabulary('pivotVoc'); 
     17            $voc->delete(); 
     18        } 
     19        catch (Exception $e) { 
     20        } 
     21        try { 
     22            $voc = new Vocabulary('rVoc1'); 
     23            $voc->delete(); 
     24        } 
     25        catch (Exception $e) { 
     26        } 
     27        try { 
     28            $voc = new Vocabulary('rVoc2'); 
     29            $voc->delete(); 
     30        } 
     31        catch (Exception $e) { 
     32        } 
    1033        $this->pivotVocIdStr='pivotVoc'; 
    1134        $this->pivotVoc = new Vocabulary('NEW'); 
     
    2245        $vocXml = file_get_contents(dirname(__FILE__) . '/testVocs/rVoc2.xml'); 
    2346        $this->rVoc2->import(DOMDocument :: loadXML($vocXml), 'VDEX'); 
     47        /* Link Learning objects to the vocabulary terms */ 
     48        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r1', array('rVoc1T1', 'rVoc1')); 
     49        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r2', array('rVoc1T2', 'rVoc1')); 
     50        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r3', array('pivotVocT1', 'pivotVoc')); 
     51        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r4', array('pivotVocT2', 'pivotVoc')); 
     52        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r5', array('pivotVocT3', 'pivotVoc')); 
     53        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r6', array('rVoc2T1', 'rVoc2')); 
     54        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r7', array('rVoc2T2', 'rVoc2')); 
     55        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r8', array('rVoc2T3', 'rVoc2')); 
     56        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r9', array('rVoc2T4', 'rVoc2')); 
     57        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r10', array('rVoc2T5', 'rVoc2')); 
     58        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r11', array('rVoc2T6', 'rVoc2')); 
     59        $this->los[] = $this->addLo('oai:eureka.coeus.ca:r12', array('rVoc2T7', 'rVoc2')); 
     60    } 
     61    /** 
     62     * @param $oaiId string example:  'oai:eureka.coeus.ca:r1' 
     63     * @param $termId array example array('rVoc1T1', 'rVoc1') 
     64     */ 
     65    private function addLo($oaiId, $termId) { 
     66        $db = AbstractDb::getObject(); 
     67        global $bypassAccessControl; 
     68        $bypassAccessControl = true; 
     69        $rootTheme = Theme::getObject(array(EUREKA_THEME_ROOT_ID, VOC_EUREKA_THEME)); 
     70        $lo = new Lom('NEW', $rootTheme, null,$oaiId); 
     71        $theme_taxon_path = new LomTaxonPath('NEW'); 
     72        $theme_taxon_path->setPathFromVocabularyTerm(Theme::getObject($termId)); 
     73        $theme_classification = new LomClassification('NEW'); 
     74        $theme_classification->AddTaxonPath($theme_taxon_path); 
     75        $sql = "INSERT INTO lom_has_lom_9_classification (lom_id, lom_9_classification_id) VALUES (".$lo->getId()."," . $theme_classification->getId() . "); \n"; 
     76        $db->execSqlUpdate($sql, false); 
     77        return $lo; 
     78    } 
    2479 
     80    private function getThemeLOArray(Theme $theme) { 
     81        $searchEngine = new SearchEngine(); 
     82        $searchEngine->setSearchLomStatus(null); 
     83        //$searchEngine->setSqlAdditionalWhereString(SearchEngine::ONLY_VALID_WHERE_SQL); 
     84 
     85        $searchEngine->addThemeLimit('AND', $theme, false); 
     86        $searchEngine->executeSearch(); 
     87        $fiches_array = $searchEngine->getResultLOs(); 
     88        foreach($fiches_array as $lo) { 
     89        $retval[]=$lo->getOaiId()->getEntry(); 
     90        } 
     91        sort($retval); 
     92        return $retval; 
    2593    } 
    2694    protected function tearDown() 
    2795    { 
     96        foreach($this->los as $lo) { 
     97            $lo->delete(); 
     98        } 
     99        $this->rVoc2->delete(); 
     100        $this->rVoc1->delete(); 
    28101        $this->pivotVoc->delete(); 
    29         $this->rVoc1->delete(); 
    30         $this->rVoc2->delete(); 
    31  
    32102    } 
    33  
     103    /** Normally i'd do more than one test, but the fixtures are unbearably slow */ 
    34104    public function testNoRegressionWhenVocabularyNavigationIsTurnedOff() 
    35105    { 
     106        /* Check that the test vocabularies have been imported successfully */ 
    36107        $this->assertEquals($this->pivotVocIdStr, $this->pivotVoc->getId()); 
    37108        $this->assertEquals($this->rVoc1IdStr, $this->rVoc1->getId()); 
    38109        $this->assertEquals($this->rVoc2IdStr, $this->rVoc2->getId()); 
     110 
     111        /* Check that the resources have been put in the right vocabularies, and that there are no regressing if navigation is disabled */ 
     112        $this->assertEquals(array('oai:eureka.coeus.ca:r1'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T1', 'rVoc1')))); 
     113        $this->assertEquals(array('oai:eureka.coeus.ca:r2'), $this->getThemeLOArray(Theme::getObject(array('rVoc1T2', 'rVoc1')))); 
     114        $this->assertEquals(array('oai:eureka.coeus.ca:r3'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT1', 'pivotVoc')))); 
     115        $this->assertEquals(array('oai:eureka.coeus.ca:r4'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT2', 'pivotVoc')))); 
     116        $this->assertEquals(array('oai:eureka.coeus.ca:r5'), $this->getThemeLOArray(Theme::getObject(array('pivotVocT3', 'pivotVoc')))); 
     117        $this->assertEquals(array('oai:eureka.coeus.ca:r6'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T1', 'rVoc2')))); 
     118        $this->assertEquals(array('oai:eureka.coeus.ca:r7'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T2', 'rVoc2')))); 
     119        $this->assertEquals(array('oai:eureka.coeus.ca:r8'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T3', 'rVoc2')))); 
     120        $this->assertEquals(array('oai:eureka.coeus.ca:r9'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T4', 'rVoc2')))); 
     121        $this->assertEquals(array('oai:eureka.coeus.ca:r10'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T5', 'rVoc2')))); 
     122        $this->assertEquals(array('oai:eureka.coeus.ca:r11'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T6', 'rVoc2')))); 
     123        $this->assertEquals(array('oai:eureka.coeus.ca:r12'), $this->getThemeLOArray(Theme::getObject(array('rVoc2T7', 'rVoc2')))); 
    39124    } 
    40125} 
Note: See TracChangeset for help on using the changeset viewer.