test/snac/server/database/DBUtilTest.php
/**
     * Insert a test record, then change the status to update and make sure that nrd is updated.
     *
     * This is similar to testFullCPFWithEditList() below.
     *
     * Parse test record, set operation to insert, write to db. We know that the entity type is person.
     *
     * .dbutiltest et term json: {
     * "id": "698",
     * "term": "person"
     * }
     *
     * The next step is the whole point of the test: does table nrd get updated when operation is update.
     *
     * Read the record from db, change entity type to family, set operation to update, write to db.
     *
     * Read the record from db and verify entity type is still family.
     *
     */
Insert a test record, then change the status to update and make sure that nrd is updated.
This is similar to testFullCPFWithEditList() below.

Parse test record, set operation to insert, write to db. We know that the entity type is person.



The next step is the whole point of the test: does table nrd get updated when operation is update.

Read the record from db, change entity type to family, set operation to update, write to db.

Read the record from db and verify entity type is still family.
Insert a test record then change the status to update and make sure that nrd is updated . This is similar to testFullCPFWithEditList () below . Parse test record set operation to insert write to db . We know that the entity type is person . The next step is the whole point of the test : does table nrd get updated when operation is update . Read the record from db change entity type to family set operation to update write to db . Read the record from db and verify entity type is still family .
public function testFullCPFNrdOperationUpdate()
    {
        $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");
        $eParser->setConstellationOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        $firstJSON = $cObj->toJSON();
        $startingARK = $cObj->getArk();
        $startingEntity = $cObj->getEntityType()->getTerm();
        $retObj = $this->dbu->writeConstellation($this->user,
                                                 $cObj,
                                                 'ingest from file',
                                                 'ingest cpf');
        $this->assertNotNull($retObj);
        $readObj = $this->dbu->readConstellation($retObj->getID(), $retObj->getVersion());
        $vocabList = $this->dbu->searchVocabulary('entity_type', 'family');
        if (count($vocabList) != 1)
        {
            throw new \snac\exceptions\SNACException("Did not get exactly 1 result for 'entity_type' and 'family'.");
        }
        if ($vocabList[0]->getTerm() != 'family')
        {
            throw new \snac\exceptions\SNACException("Did not get expected 'family' as value.");
        }
        $readObj->setEntityType($vocabList[0]);
        $readObj->setOperation(\snac\data\AbstractData::$OPERATION_UPDATE);
        $xObj = $this->dbu->writeConstellation($this->user,
                                               $readObj,
                                               'change nrd term operation update',
                                               'ingest cpf');
        $finalObj = $this->dbu->readConstellation($xObj->getID(), $xObj->getVersion());
        $this->assertEquals($finalObj->getEntityType()->getTerm(), 'family');
        $this->logger->addDebug("Ending: " . __METHOD__);
    }
public function testFullCPFNrdOperationUpdate ( ) { $ 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 " ) ; $ eParser -> setConstellationOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; $ firstJSON = $ cObj -> toJSON ( ) ; $ startingARK = $ cObj -> getArk ( ) ; $ startingEntity = $ cObj -> getEntityType ( ) -> getTerm ( ) ; $ retObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ cObj , 'ingest from file' , 'ingest cpf' ) ; $ this -> assertNotNull ( $ retObj ) ; $ readObj = $ this -> dbu -> readConstellation ( $ retObj -> getID ( ) , $ retObj -> getVersion ( ) ) ; $ vocabList = $ this -> dbu -> searchVocabulary ( 'entity_type' , 'family' ) ; if ( count ( $ vocabList ) != 1 ) { throw new \ snac \ exceptions \ SNACException ( " Did not get exactly 1 result for 'entity_type' and 'family'. " ) ; } if ( $ vocabList [ 0 ] -> getTerm ( ) != 'family' ) { throw new \ snac \ exceptions \ SNACException ( " Did not get expected 'family' as value. " ) ; } $ readObj -> setEntityType ( $ vocabList [ 0 ] ) ; $ readObj -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_UPDATE ) ; $ xObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ readObj , 'change nrd term operation update' , 'ingest cpf' ) ; $ finalObj = $ this -> dbu -> readConstellation ( $ xObj -> getID ( ) , $ xObj -> getVersion ( ) ) ; $ this -> assertEquals ( $ finalObj -> getEntityType ( ) -> getTerm ( ) , 'family' ) ; $ this -> logger -> addDebug ( " Ending:  " . __METHOD__ ) ; }
Insert a test record, then change the status to update and make sure that nrd is updated.
Insert a test record then change the status to update and make sure that nrd is updated .
// $cObj->setOperation(\snac\data\AbstractData::$OPERATION_INSERT); /*
         * Read from the db what we just wrote to the db.
         *
         * Assume that the vocabulary table is carved in stone, as it should be. Hard code the id 697, and if
         * someone messes with vocabulary this should break. Multilingual vocabulary will break this, and will
         * break a query to retrieve the 697, so there's not much point in trying to use a query instead of
         * simply hard coding the id.
         *
         * (old)
         *
         * wfdb=> select * from vocabulary where type='entity_type';
         *  id  |    type     |     value     | uri | description
         * -----+-------------+---------------+-----+-------------
         *  698 | entity_type | person        |     |
         *  697 | entity_type | family        |     |
         *  696 | entity_type | corporateBody |     |
         * (3 rows)
         *
         * may 24 2016 Things were added to the vocab, now the id value is different
         *
         * wfdb=> select * from vocabulary where type='entity_type';
         * id  |    type     |     value     | uri | description
         * -----+-------------+---------------+-----+-------------
         * 700 | entity_type | person        |     |
         * 699 | entity_type | family        |     |
         * 698 | entity_type | corporateBody |     |
         * (3 rows)

         */ /*
         * We are expecting only one result. Search the vocab list so even if the IDs change, we will get the
         * correct id for entity_type family.
         */