test/snac/server/database/DBUtilTest.php
/**
     * Test name component related code
     *
     * Test both saving and reading name components, as well as searchVocabulary() which has special behavior
     * related to name components.
     *
     */
Test name component related code
Test both saving and reading name components, as well as searchVocabulary() which has special behavior
related to name components.
Test name component related code Test both saving and reading name components as well as searchVocabulary () which has special behavior related to name components .
public function testSearchVocabularyNameComponent()
    {
        $this->logger->addDebug("Starting: " . __METHOD__);
        $eParser = new \snac\util\EACCPFParser();
        $eParser->setConstellationOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        $cObj = $eParser->parseFile("test/snac/server/database/test_record.xml");
        $cObj->getNameEntries()[0]->setOriginal("Foo Bar Test");
        $componentObj = new \snac\data\NameComponent();
        $componentObj->setText("Foo");
        $componentObj->setOrder(1);
        $entList = $this->dbu->searchVocabulary('entity_type', '');
        $personID = 0;
        foreach($entList as $ent)
        {
            if ($ent->getTerm() == 'person')
            {
                $personID = $ent->getID();
            }
        }
        $svList = $this->dbu->searchVocabulary('name_component', 'Surname', $personID);
        $ctObj = new \snac\data\Term();
        foreach($svList as $svocab)
        {
            if ($svocab->getTerm() == 'Surname')
            {
                $ctObj = $svocab;
            }
        }
        $componentObj->setType($ctObj);
        $componentObj->setOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        $cObj->getNameEntries()[0]->addComponent($componentObj);
        $retObj = $this->dbu->writeConstellation($this->user, 
                                                 $cObj,       
                                                 'testing ingest full CPF record with ingest cpf', 
                                                 'ingest cpf'); 
        $this->assertTrue($cObj->equals($retObj, false), "Initial parsed constellation doesn't equal written one");
        $readObj = $this->dbu->readConstellation($retObj->getID());
        if (0)
        {
            $cfile = fopen('name_component_json.txt', 'w');
            $ncJSON = $readObj->toJSON();
            fwrite($cfile, $ncJSON);
            fclose($cfile);
        }
        $this->assertEquals($this->dbu->readConstellationStatus($readObj->getID()), 'locked editing');
        $this->logger->addDebug("Ending: " . __METHOD__);
    }
public function testSearchVocabularyNameComponent ( ) { $ this -> logger -> addDebug ( " Starting:  " . __METHOD__ ) ; $ eParser = new \ snac \ util \ EACCPFParser ( ) ; $ eParser -> setConstellationOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; $ cObj = $ eParser -> parseFile ( " test/snac/server/database/test_record.xml " ) ; $ cObj -> getNameEntries ( ) [ 0 ] -> setOriginal ( " Foo Bar Test " ) ; $ componentObj = new \ snac \ data \ NameComponent ( ) ; $ componentObj -> setText ( " Foo " ) ; $ componentObj -> setOrder ( 1 ) ; $ entList = $ this -> dbu -> searchVocabulary ( 'entity_type' , '' ) ; $ personID = 0 ; foreach ( $ entList as $ ent ) { if ( $ ent -> getTerm ( ) == 'person' ) { $ personID = $ ent -> getID ( ) ; } } $ svList = $ this -> dbu -> searchVocabulary ( 'name_component' , 'Surname' , $ personID ) ; $ ctObj = new \ snac \ data \ Term ( ) ; foreach ( $ svList as $ svocab ) { if ( $ svocab -> getTerm ( ) == 'Surname' ) { $ ctObj = $ svocab ; } } $ componentObj -> setType ( $ ctObj ) ; $ componentObj -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; $ cObj -> getNameEntries ( ) [ 0 ] -> addComponent ( $ componentObj ) ; $ retObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ cObj , 'testing ingest full CPF record with ingest cpf' , 'ingest cpf' ) ; $ this -> assertTrue ( $ cObj -> equals ( $ retObj , false ) , " Initial parsed constellation doesn't equal written one " ) ; $ readObj = $ this -> dbu -> readConstellation ( $ retObj -> getID ( ) ) ; if ( 0 ) { $ cfile = fopen ( 'name_component_json.txt' , 'w' ) ; $ ncJSON = $ readObj -> toJSON ( ) ; fwrite ( $ cfile , $ ncJSON ) ; fclose ( $ cfile ) ; } $ this -> assertEquals ( $ this -> dbu -> readConstellationStatus ( $ readObj -> getID ( ) ) , 'locked editing' ) ; $ this -> logger -> addDebug ( " Ending:  " . __METHOD__ ) ; }
Test name component related code
 Test both saving and reading name components, as well as searchVocabulary() which has special behavior
 related to name components.
Test name component related code Test both saving and reading name components as well as searchVocabulary () which has special behavior related to name components .
// Only one record will match. // Only one record will match. // $user // $argObj // $note // $statusArg // Get the most recent version. /*
         * Change to 1 for debugging.  Do we have an environment var for debug mode?
         */ /*
         * The constellation object does not contain a populated status because the server may change it. If
         * you want status you must call readConstellationStatus() and get it directly from the db.
         */