test/snac/server/database/DBUtilTest.php
/**
     * Read in the full test record
     *
     * Set the operation to be insert.
     *
     * After parsing, change the second place to be confirmed. It is only possible to set confirmed on a place
     * with a geoplace (aka GeoTerm), and that's why we use [1] instead of [0].
     *
     * Count how many constellations are status 'locked editing'.
     *
     * Change the status of one record and compare the count of records locked for editing, which should be initial+1.
     *
     * Read the record back from the db, and make sure the ARK and entity type are correct.
     *
     * Delete a constellation, then attempt a read and make sure it did not read.
     *
     * Apr 21 2016 Added <descriptiveNote> to existDates in test_record.xml and verified that it shows up in
     * the JSON from parsing and reading back out of the db. There's no explicit test for that here, just like
     * there's no explicit test for all the other CPF elements.
     */
Read in the full test record
Set the operation to be insert.

After parsing, change the second place to be confirmed. It is only possible to set confirmed on a place
with a geoplace (aka GeoTerm), and that's why we use [1] instead of [0].

Count how many constellations are status 'locked editing'.

Change the status of one record and compare the count of records locked for editing, which should be initial+1.

Read the record back from the db, and make sure the ARK and entity type are correct.

Delete a constellation, then attempt a read and make sure it did not read.

Apr 21 2016 Added  to existDates in test_record.xml and verified that it shows up in
the JSON from parsing and reading back out of the db. There's no explicit test for that here, just like
there's no explicit test for all the other CPF elements.
Read in the full test record Set the operation to be insert . After parsing change the second place to be confirmed . It is only possible to set confirmed on a place with a geoplace ( aka GeoTerm ) and that ' s why we use [ 1 ] instead of [ 0 ] . Count how many constellations are status ' locked editing ' . Change the status of one record and compare the count of records locked for editing which should be initial + 1 . Read the record back from the db and make sure the ARK and entity type are correct . Delete a constellation then attempt a read and make sure it did not read . Apr 21 2016 Added to existDates in test_record . xml and verified that it shows up in the JSON from parsing and reading back out of the db . There ' s no explicit test for that here just like there ' s no explicit test for all the other CPF elements .
public function testFullCPFWithEditList()
    {
        $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);
        $firstJSON = $cObj->toJSON();
        $startingARK = $cObj->getArk();
        $startingEntity = $cObj->getEntityType()->getTerm();
        $retObj = $this->dbu->writeConstellation($this->user,
                                                 $cObj,
                                                 'testing ingest of a full CPF record',
                                                 'ingest cpf');
        $this->assertTrue($cObj->equals($retObj, false), "Initial parsed constellation doesn't equal written one");
        $readObj = $this->dbu->readConstellation($retObj->getID(), $retObj->getVersion());
        $this->assertTrue($readObj->equals($retObj, false), "Written constellation is not equal to next read version");
        $this->dbu->writeConstellationStatus($this->user, $retObj->getID(), 'published');
        $this->assertNotNull($retObj);
        $editList = $this->dbu->listConstellationsWithStatusForUser($this->user, 'locked editing', -1, -1);
        $initialEditCount = count($editList);
        $newSVersion = $this->dbu->writeConstellationStatus($this->user, $retObj->getID(),
                                                            'locked editing',
                                                            'test write constellation status change published to locked editing');
        $this->assertTrue($newSVersion > 1);
        $newStatus = $this->dbu->readConstellationStatus($retObj->getID());
        $newStatusToo = $this->dbu->readConstellationStatus($retObj->getID(), $newSVersion);
        $editList = $this->dbu->listConstellationsWithStatusForUser($this->user, 'locked editing', -1, -1);
        $postEditCount = count($editList);
        $this->assertEquals('locked editing', $newStatus);
        $this->assertEquals('locked editing', $newStatusToo);
        $this->assertEquals($initialEditCount+1, $postEditCount);
        $this->dbu->writeConstellationStatus($this->user, $retObj->getID(), 'published', 'change status back to published in order toclean up');
        $washObj = $this->dbu->readPublishedConstellationByARK('http://n2t.net/ark:/99166/w6028ps4');
        $this->dbu->writeConstellationStatus($this->user, $washObj->getID(), 'published', 'modify status as part of testFullCPFWithEditList');
        $readObj = $this->dbu->readConstellation($retObj->getID(), $retObj->getVersion());
        $readingARK = $readObj->getArk();
        $readingEntity = $readObj->getEntityType()->getTerm();
        $this->assertEquals($startingARK, $readingARK);
        $this->assertEquals($startingEntity, $readingEntity);
        $secondJSON = $readObj->toJSON();
        $this->assertTrue($retObj->equals($readObj, false));
        $readObj->setOperation(\snac\data\AbstractData::$OPERATION_DELETE);
        $deletedObj = $this->dbu->writeConstellation($this->user,
                                                     $readObj,
                                                     'test deleting a whole constellation',
                                                     'ingest cpf');
        $tryObj = $this->dbu->readPublishedConstellationByID($deletedObj->getID());
        $postDeleteJSON = "";
        if ($tryObj)
        {
            $postDeleteJSON = $tryObj->toJSON();
        }
        $this->assertFalse($tryObj);
        if (0)
        {
            $cfile = fopen('post_delete_json.txt', 'w');
            fwrite($cfile, $postDeleteJSON);
            fclose($cfile);
        }
        $this->logger->addDebug("Ending: " . __METHOD__);
    }
public function testFullCPFWithEditList ( ) { $ 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 ) ; $ firstJSON = $ cObj -> toJSON ( ) ; $ startingARK = $ cObj -> getArk ( ) ; $ startingEntity = $ cObj -> getEntityType ( ) -> getTerm ( ) ; $ retObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ cObj , 'testing ingest of a full CPF record' , 'ingest cpf' ) ; $ this -> assertTrue ( $ cObj -> equals ( $ retObj , false ) , " Initial parsed constellation doesn't equal written one " ) ; $ readObj = $ this -> dbu -> readConstellation ( $ retObj -> getID ( ) , $ retObj -> getVersion ( ) ) ; $ this -> assertTrue ( $ readObj -> equals ( $ retObj , false ) , " Written constellation is not equal to next read version " ) ; $ this -> dbu -> writeConstellationStatus ( $ this -> user , $ retObj -> getID ( ) , 'published' ) ; $ this -> assertNotNull ( $ retObj ) ; $ editList = $ this -> dbu -> listConstellationsWithStatusForUser ( $ this -> user , 'locked editing' , - 1 , - 1 ) ; $ initialEditCount = count ( $ editList ) ; $ newSVersion = $ this -> dbu -> writeConstellationStatus ( $ this -> user , $ retObj -> getID ( ) , 'locked editing' , 'test write constellation status change published to locked editing' ) ; $ this -> assertTrue ( $ newSVersion > 1 ) ; $ newStatus = $ this -> dbu -> readConstellationStatus ( $ retObj -> getID ( ) ) ; $ newStatusToo = $ this -> dbu -> readConstellationStatus ( $ retObj -> getID ( ) , $ newSVersion ) ; $ editList = $ this -> dbu -> listConstellationsWithStatusForUser ( $ this -> user , 'locked editing' , - 1 , - 1 ) ; $ postEditCount = count ( $ editList ) ; $ this -> assertEquals ( 'locked editing' , $ newStatus ) ; $ this -> assertEquals ( 'locked editing' , $ newStatusToo ) ; $ this -> assertEquals ( $ initialEditCount + 1 , $ postEditCount ) ; $ this -> dbu -> writeConstellationStatus ( $ this -> user , $ retObj -> getID ( ) , 'published' , 'change status back to published in order toclean up' ) ; $ washObj = $ this -> dbu -> readPublishedConstellationByARK ( 'http://n2t.net/ark:/99166/w6028ps4' ) ; $ this -> dbu -> writeConstellationStatus ( $ this -> user , $ washObj -> getID ( ) , 'published' , 'modify status as part of testFullCPFWithEditList' ) ; $ readObj = $ this -> dbu -> readConstellation ( $ retObj -> getID ( ) , $ retObj -> getVersion ( ) ) ; $ readingARK = $ readObj -> getArk ( ) ; $ readingEntity = $ readObj -> getEntityType ( ) -> getTerm ( ) ; $ this -> assertEquals ( $ startingARK , $ readingARK ) ; $ this -> assertEquals ( $ startingEntity , $ readingEntity ) ; $ secondJSON = $ readObj -> toJSON ( ) ; $ this -> assertTrue ( $ retObj -> equals ( $ readObj , false ) ) ; $ readObj -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_DELETE ) ; $ deletedObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ readObj , 'test deleting a whole constellation' , 'ingest cpf' ) ; $ tryObj = $ this -> dbu -> readPublishedConstellationByID ( $ deletedObj -> getID ( ) ) ; $ postDeleteJSON = " " ; if ( $ tryObj ) { $ postDeleteJSON = $ tryObj -> toJSON ( ) ; } $ this -> assertFalse ( $ tryObj ) ; if ( 0 ) { $ cfile = fopen ( 'post_delete_json.txt' , 'w' ) ; fwrite ( $ cfile , $ postDeleteJSON ) ; fclose ( $ cfile ) ; } $ this -> logger -> addDebug ( " Ending:  " . __METHOD__ ) ; }
Read in the full test record
 Set the operation to be insert.
Read in the full test record Set the operation to be insert .
/*
         * Change the status to published so that we can change it to 'locked editing' further below.  The new
         * default on insert is 'locked editing', but we want to test listConstellationsWithStatusForUser() and to
         * do that we want to change status and call listConstellationsWithStatusForUser() a second time.
         *
         */ // It defaults to 'locked editing', but be explicit anyway. // Not really necessary, since other tests will fail later if the writeConstellationStatus() fails. /*
         * Get the post-status-change count, and test.
         */ // It defaults to 'locked editing', but be explicit anyway. /*
         * If you get a number like 42 doesn't match expected 43, look at the optional limit and offset for
         * listConstellationsWithStatusForUser(). The default limit is 42.
         */ /*
         * Change back to published so it doesn't show up on anyone's dashboard.
         * When we have real users this won't matter as much because testing will be done with the "test" user.
         */ /*
         * Change status of some other constellation. This tests a bug Robbie found on Mar 25 where
         * non-contiguous version numbers for the otherRecordID (table otherid) caused selectOtherID() to not
         * return the records.
         *
         * Get the Washington record which as of this test has just become a requirement. We can use any
         * record, so you should be able to change the ARK below to any ARK which is known to be loaded.
         *
         * Incidentally, this exercises readPublishedConstellationByARK() and selectMainID().
         */ /*
         * read from the db what we just wrote to the db back at the beginning.
         */ /*
         * Legalstatus is broken because all the terms are not in the db?
         */ // $this->assertEquals("Sample legal status", $readObj->getLegalStatuses()[0]->getTerm()->getTerm()); /*
         * Before uncommenting this, copy the old files. Any time these need updating, you should diff the old
         * and new to confirm that what you think changed, changed, and nothing else.
         *
         * first is from $cObj.
         * second is from $readObj.
         */ /*
         * $cfile = fopen('first_json.txt', 'w');
         * fwrite($cfile, $firstJSON);
         * fclose($cfile);
         * $cfile = fopen('second_json.txt', 'w');
         * fwrite($cfile, $secondJSON);
         * fclose($cfile);
         */ /*
         * $retObj is returned by the first wrieConstellation(). $readObj is the result of readConstellation()
         * on the same constellation, to confirm that was was written is read back again.
         */ /*
         * readPublishedConstellationByID() should return false when the constellation in question has been
         * deleted.
         *
         * Try to get it, then test the returned value to be false.
         *
         * Interestingly, this now also writes a log message.
         */ // These files may be interesting when debugging