test/snac/server/database/DBUtilTest.php
/**
     * Check multiple related
     *
     * Check multiple versions for multiple records of related second order data: source, date, place
     * (place_link), meta (scm), language.
     *
     * Verify that multiples of each are written to the db and read back from the db when some of the multis
     * have different version numbers.
     */
Check multiple related
Check multiple versions for multiple records of related second order data: source, date, place
(place_link), meta (scm), language.

Verify that multiples of each are written to the db and read back from the db when some of the multis
have different version numbers.
Check multiple related Check multiple versions for multiple records of related second order data : source date place ( place_link ) meta ( scm ) language . Verify that multiples of each are written to the db and read back from the db when some of the multis have different version numbers .
public function testMultiSecondOrderData()
    {
        $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");
        $retObj = $this->dbu->writeConstellation($this->user,
                                                 $cObj,
                                                 'testing multi exist date',
                                                 'ingest cpf');
        $newRetObj = $this->dbu->readConstellation($retObj->getID(), $retObj->getVersion());
        $firstSourceCount = count($newRetObj->getSources());
        $firstPlaceCount = count($newRetObj->getPlaces());
        $firstSCMCount = count($newRetObj->getPlaces()[0]->getSNACControlMetadata());
        $placeID = $newRetObj->getPlaces()[0]->getID();
        $firstLangCount = count($newRetObj->getLanguagesUsed());
        $firstDateCount = count($newRetObj->getDateList());
        $this->assertTrue(count($cObj->getDateList()) > 1);
        $this->assertEquals(count($cObj->getDateList()), count($newRetObj->getDateList()));
        $dateObj = new \snac\data\SNACDate();
        $dateObj->setRange(true);
        $dateObj->setFromDate('1940',
                              '1940',
                              null);
        $dateObj->setToDate('1960',
                            '1960',
                            null);
        $dateObj->setOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        $newRetObj->addDate($dateObj);
        $newSource = new \snac\data\Source();
        $newSource->setNote("new added source");
        $newSource->setURI("http://example.com/newsource");
        $newSource->setOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        $newRetObj->addSource($newSource);
        $newPlace = new \snac\data\Place();
        $newPlace->setOriginal("Foo City");
        $newPlace->setNote("Test place");
        $newPlace->setOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        $newRetObj->addPlace($newPlace);
        $newSCM = new \snac\data\SNACControlMetadata();
        $newSCM->setSourceData("third paragraph page 25");
        $newSCM->setNote("test scm");
        $newSCM->setOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        foreach($newRetObj->getPlaces() as $gObj)
        {
            if ($placeID == $gObj->getID())
            {
                $gObj->addSNACControlMetadata($newSCM);
                break;
            }
        }
        $newLang = clone($newRetObj->getLanguagesUsed()[0]);
        $newLang->setID(null);
        $newLang->setVersion(null);
        $newLang->setOperation(\snac\data\AbstractData::$OPERATION_INSERT);
        $newRetObj->addLanguageUsed($newLang);
        $retObj = $this->dbu->writeConstellation($this->user,
                                                 $newRetObj,
                                                 'testing adding date to multi exist date',
                                                 'ingest cpf');
        $thirdRetObj = $this->dbu->readConstellation($retObj->getID(), $retObj->getVersion());
        $this->assertEquals(count($thirdRetObj->getSources()), $firstSourceCount+1);
        $this->assertEquals(count($thirdRetObj->getPlaces()), $firstPlaceCount+1);
        foreach($thirdRetObj->getPlaces() as $gObj)
        {
            if ($placeID == $gObj->getID())
            {
                $this->assertEquals(count($gObj->getSNACControlMetadata()), $firstSCMCount+1);
                break;
            }
        }
        $this->assertEquals(count($thirdRetObj->getLanguagesUsed()), $firstLangCount+1);
        $this->assertEquals(count($thirdRetObj->getDateList()), $firstDateCount+1);
        $firstDateList = array();
        foreach($newRetObj->getDateList() as $gObj)
        {
            array_push($firstDateList, $gObj->getFromDate());
        }
        sort($firstDateList);
        $secondDateList = array();
        foreach($thirdRetObj->getDateList() as $gObj)
        {
            array_push($secondDateList, $gObj->getFromDate());
        }
        sort($secondDateList);
        $this->assertEquals($firstDateList[0], $secondDateList[0]);
        $this->assertEquals($firstDateList[1], $secondDateList[1]);
        $this->assertEquals($firstDateList[2], $secondDateList[2]);
        $this->logger->addDebug("Ending: " . __METHOD__);
    }
public function testMultiSecondOrderData ( ) { $ 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 " ) ; $ retObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ cObj , 'testing multi exist date' , 'ingest cpf' ) ; $ newRetObj = $ this -> dbu -> readConstellation ( $ retObj -> getID ( ) , $ retObj -> getVersion ( ) ) ; $ firstSourceCount = count ( $ newRetObj -> getSources ( ) ) ; $ firstPlaceCount = count ( $ newRetObj -> getPlaces ( ) ) ; $ firstSCMCount = count ( $ newRetObj -> getPlaces ( ) [ 0 ] -> getSNACControlMetadata ( ) ) ; $ placeID = $ newRetObj -> getPlaces ( ) [ 0 ] -> getID ( ) ; $ firstLangCount = count ( $ newRetObj -> getLanguagesUsed ( ) ) ; $ firstDateCount = count ( $ newRetObj -> getDateList ( ) ) ; $ this -> assertTrue ( count ( $ cObj -> getDateList ( ) ) > 1 ) ; $ this -> assertEquals ( count ( $ cObj -> getDateList ( ) ) , count ( $ newRetObj -> getDateList ( ) ) ) ; $ dateObj = new \ snac \ data \ SNACDate ( ) ; $ dateObj -> setRange ( true ) ; $ dateObj -> setFromDate ( '1940' , '1940' , null ) ; $ dateObj -> setToDate ( '1960' , '1960' , null ) ; $ dateObj -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; $ newRetObj -> addDate ( $ dateObj ) ; $ newSource = new \ snac \ data \ Source ( ) ; $ newSource -> setNote ( " new added source " ) ; $ newSource -> setURI ( " http://example.com/newsource " ) ; $ newSource -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; $ newRetObj -> addSource ( $ newSource ) ; $ newPlace = new \ snac \ data \ Place ( ) ; $ newPlace -> setOriginal ( " Foo City " ) ; $ newPlace -> setNote ( " Test place " ) ; $ newPlace -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; $ newRetObj -> addPlace ( $ newPlace ) ; $ newSCM = new \ snac \ data \ SNACControlMetadata ( ) ; $ newSCM -> setSourceData ( " third paragraph page 25 " ) ; $ newSCM -> setNote ( " test scm " ) ; $ newSCM -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; foreach ( $ newRetObj -> getPlaces ( ) as $ gObj ) { if ( $ placeID == $ gObj -> getID ( ) ) { $ gObj -> addSNACControlMetadata ( $ newSCM ) ; break ; } } $ newLang = clone ( $ newRetObj -> getLanguagesUsed ( ) [ 0 ] ) ; $ newLang -> setID ( null ) ; $ newLang -> setVersion ( null ) ; $ newLang -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_INSERT ) ; $ newRetObj -> addLanguageUsed ( $ newLang ) ; $ retObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ newRetObj , 'testing adding date to multi exist date' , 'ingest cpf' ) ; $ thirdRetObj = $ this -> dbu -> readConstellation ( $ retObj -> getID ( ) , $ retObj -> getVersion ( ) ) ; $ this -> assertEquals ( count ( $ thirdRetObj -> getSources ( ) ) , $ firstSourceCount + 1 ) ; $ this -> assertEquals ( count ( $ thirdRetObj -> getPlaces ( ) ) , $ firstPlaceCount + 1 ) ; foreach ( $ thirdRetObj -> getPlaces ( ) as $ gObj ) { if ( $ placeID == $ gObj -> getID ( ) ) { $ this -> assertEquals ( count ( $ gObj -> getSNACControlMetadata ( ) ) , $ firstSCMCount + 1 ) ; break ; } } $ this -> assertEquals ( count ( $ thirdRetObj -> getLanguagesUsed ( ) ) , $ firstLangCount + 1 ) ; $ this -> assertEquals ( count ( $ thirdRetObj -> getDateList ( ) ) , $ firstDateCount + 1 ) ; $ firstDateList = array ( ) ; foreach ( $ newRetObj -> getDateList ( ) as $ gObj ) { array_push ( $ firstDateList , $ gObj -> getFromDate ( ) ) ; } sort ( $ firstDateList ) ; $ secondDateList = array ( ) ; foreach ( $ thirdRetObj -> getDateList ( ) as $ gObj ) { array_push ( $ secondDateList , $ gObj -> getFromDate ( ) ) ; } sort ( $ secondDateList ) ; $ this -> assertEquals ( $ firstDateList [ 0 ] , $ secondDateList [ 0 ] ) ; $ this -> assertEquals ( $ firstDateList [ 1 ] , $ secondDateList [ 1 ] ) ; $ this -> assertEquals ( $ firstDateList [ 2 ] , $ secondDateList [ 2 ] ) ; $ this -> logger -> addDebug ( " Ending:  " . __METHOD__ ) ; }
Check multiple related
 Check multiple versions for multiple records of related second order data: source, date, place
 (place_link), meta (scm), language.
Check multiple related Check multiple versions for multiple records of related second order data : source date place ( place_link ) meta ( scm ) language .
// $dateObj->setFromBC(false); // $dateObj->setFromDateRange($singleDate['from_not_before'], $singleDate['from_not_after']); // $dateObj->setToBC($this->db->pgToBool($singleDate['to_bc'])); // $dateObj->setToDateRange($singleDate['to_not_before'], $singleDate['to_not_after']); // $dateObj->setNote($singleDate['descriptive_note']); // $dateObj->setDBInfo($singleDate['version'], $singleDate['id']); // place // scm // language aka languagesUsed // Note singular "language" for add, although get has plural. // Yes, we are re-using $retObj. /*
         * Every other time this test is run, the returned dates are in a different order. Unclear why, but we
         * don't have an "order by" clause in the SQL, so changing order is sort of expected. Create the tests
         * to be independent of order. There must be 3 dates.
         */