test/snac/server/database/DBUtilTest.php
/**
     * Test that an scm can use an existing source, and round trip the SCM.
     */
Test that an scm can use an existing source, and round trip the SCM.
Test that an scm can use an existing source and round trip the SCM .
public function testSourceSCM()
    {
        $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->getPlaces()[1]->setConfirmed(true);
        $retObj = $this->dbu->writeConstellation($this->user,
                                                 $cObj,
                                                 'ingest full CPF prior to checking adding source to scm',
                                                 'ingest cpf');
        $readObj = $this->dbu->readConstellation($retObj->getID());
        $readObj->getPlaces()[0]->getSNACControlMetadata()[0]->setCitation($readObj->getSources()[0]);
        $readObj->getPlaces()[0]->getSNACControlMetadata()[0]->setNote("adding source");
        $readObj->getPlaces()[0]->getSNACControlMetadata()[0]->setOperation(\snac\data\AbstractData::$OPERATION_UPDATE);
        $firstJSON = $readObj->toJSON();
        $origObj = $this->dbu->writeConstellation($this->user,
                                                  $readObj,
                                                  'adding source to scm',
                                                  'ingest cpf');
        $newObj = $this->dbu->readConstellation($readObj->getID());
        $secondJSON = $newObj->toJSON();
        $this->assertTrue($newObj->equals($origObj, false));
        $sourceList = $newObj->getSources();
        $newSource = clone($sourceList[0]);
        $newSource->setID(null);
        $newSource->setVersion(null); 
        $newSource->setDisplayName("added source");
        $newSource->setURI("http://foo.com/bar/baz/");
        $newSource->setOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        $newObj->addSource($newSource);
        $this->dbu->writeConstellation($this->user,
                                       $newObj,
                                       'Added another source for foo.com',
                                       'ingest cpf');
        $postAddObj = $this->dbu->readConstellation($newObj->getID());
        $longerSourceList = $postAddObj->getSources();
        $this->assertEquals(count($sourceList)+1, count($longerSourceList));
        $this->logger->addDebug("Ending: " . __METHOD__);
    }
public function testSourceSCM ( ) { $ 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 -> getPlaces ( ) [ 1 ] -> setConfirmed ( true ) ; $ retObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ cObj , 'ingest full CPF prior to checking adding source to scm' , 'ingest cpf' ) ; $ readObj = $ this -> dbu -> readConstellation ( $ retObj -> getID ( ) ) ; $ readObj -> getPlaces ( ) [ 0 ] -> getSNACControlMetadata ( ) [ 0 ] -> setCitation ( $ readObj -> getSources ( ) [ 0 ] ) ; $ readObj -> getPlaces ( ) [ 0 ] -> getSNACControlMetadata ( ) [ 0 ] -> setNote ( " adding source " ) ; $ readObj -> getPlaces ( ) [ 0 ] -> getSNACControlMetadata ( ) [ 0 ] -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_UPDATE ) ; $ firstJSON = $ readObj -> toJSON ( ) ; $ origObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ readObj , 'adding source to scm' , 'ingest cpf' ) ; $ newObj = $ this -> dbu -> readConstellation ( $ readObj -> getID ( ) ) ; $ secondJSON = $ newObj -> toJSON ( ) ; $ this -> assertTrue ( $ newObj -> equals ( $ origObj , false ) ) ; $ sourceList = $ newObj -> getSources ( ) ; $ newSource = clone ( $ sourceList [ 0 ] ) ; $ newSource -> setID ( null ) ; $ newSource -> setVersion ( null ) ; $ newSource -> setDisplayName ( " added source " ) ; $ newSource -> setURI ( " http://foo.com/bar/baz/ " ) ; $ newSource -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; $ newObj -> addSource ( $ newSource ) ; $ this -> dbu -> writeConstellation ( $ this -> user , $ newObj , 'Added another source for foo.com' , 'ingest cpf' ) ; $ postAddObj = $ this -> dbu -> readConstellation ( $ newObj -> getID ( ) ) ; $ longerSourceList = $ postAddObj -> getSources ( ) ; $ this -> assertEquals ( count ( $ sourceList ) + 1 , count ( $ longerSourceList ) ) ; $ this -> logger -> addDebug ( " Ending:  " . __METHOD__ ) ; }
Test that an scm can use an existing source, and round trip the SCM.
Test that an scm can use an existing source and round trip the SCM .
/*
         * Run toJSON before write because write changes the constellation in place (apparently) even though
         * it should not be doing that.
         */ /*
         * These files are sometimes useful for debugging.
         */ /*
         * $cfile = fopen('scm_before_save.txt', 'w');
         * fwrite($cfile, $firstJSON);
         * fclose($cfile);
         * $cfile = fopen('scm_after_read.txt', 'w');
         * fwrite($cfile, $secondJSON);
         * fclose($cfile);
         */ /*
         * We have Constellation->equals() which is a more accurate check of equality than line count.
         *
         * This compares the constellation after adding an SCM and writing, with the same constellation read
         * back from the db.
         */ // Seems like insert code should write over this.