test/snac/server/database/DBUtilTest.php
/**
     * Can we get a random Constellation?
     * Can we reverse the order of keys in $vhInfo?
     * Can we get 100 constellations from the db?
     * Can we delete 1 name from a multiname constellation?
     * Can we undelete the name we just deleted?
     *
     * https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers
     *
     * Maybe use @dataProvider to test various records from the db for function, subject, etc.
     *
     * Check expected output: $this->expectOutputString()
     *
     */
Can we get a random Constellation.
Can we reverse the order of keys in $vhInfo.
Can we get 100 constellations from the db.
Can we delete 1 name from a multiname constellation.



Maybe use @dataProvider to test various records from the db for function, subject, etc.

Check expected output: $this->expectOutputString()
Can we get a random Constellation . Can we reverse the order of keys in $vhInfo . Can we get 100 constellations from the db . Can we delete 1 name from a multiname constellation . Maybe use @dataProvider to test various records from the db for function subject etc . Check expected output : $this - > expectOutputString ()
public function testDemoConstellation()
    {
        $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");
        $tmp = $this->dbu->writeConstellation($this->user,
                                              $cObj,
                                              'test demo constellation',
                                              'ingest cpf');
        $cObj = $this->dbu->readConstellation($tmp->getID(), $tmp->getVersion());
        $this->assertNotNull($cObj);
        $preDeleteNameCount = count($cObj->getNameEntries());
        $cObj->getNameEntries()[0]->setOperation(\snac\data\AbstractData::$OPERATION_DELETE);
        $cObj->setOperation(null);
        $returnedDeleteObj = $this->dbu->writeConstellation($this->user,
                                                            $cObj,
                                                            'delete a name, that is: set is_deleted to true',
                                                            'ingest cpf');
        $postDObj = $this->dbu->readConstellation($returnedDeleteObj->getID(),
                                                  $returnedDeleteObj->getVersion());
        $postDeleteNameCount = count($postDObj->getNameEntries());
        $this->assertEquals($preDeleteNameCount, ($postDeleteNameCount+1));
        $neNameListRef = $postDObj->getNameEntries();
        $origNCount = count($neNameListRef);
        $name = $neNameListRef[0]->getOriginal();
        $modName = preg_replace('/(^.*) /', '$1xx ', $name);
        $neNameListRef[0]->setOriginal($modName);
        $neNameListRef[0]->setOperation(\snac\data\AbstractData::$OPERATION_UPDATE);
        $retObj = $this->dbu->writeConstellation($this->user,
                                                 $postDObj,
                                                 'modified first alt name',
                                                 'ingest cpf');
        $this->dbu->writeConstellationStatus($this->user, $retObj->getID(), 'needs review', 'send for review after a name change');
        $modObj = $this->dbu->readConstellation($retObj->getID(), $retObj->getVersion());
        $this->assertEquals($modName, $modObj->getNameEntries()[0]->getOriginal());
        $this->assertTrue($origNCount == count($modObj->getNameEntries()));
        $this->logger->addDebug("Ending: " . __METHOD__);
    }
public function testDemoConstellation ( ) { $ 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 " ) ; $ tmp = $ this -> dbu -> writeConstellation ( $ this -> user , $ cObj , 'test demo constellation' , 'ingest cpf' ) ; $ cObj = $ this -> dbu -> readConstellation ( $ tmp -> getID ( ) , $ tmp -> getVersion ( ) ) ; $ this -> assertNotNull ( $ cObj ) ; $ preDeleteNameCount = count ( $ cObj -> getNameEntries ( ) ) ; $ cObj -> getNameEntries ( ) [ 0 ] -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_DELETE ) ; $ cObj -> setOperation ( null ) ; $ returnedDeleteObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ cObj , 'delete a name, that is: set is_deleted to true' , 'ingest cpf' ) ; $ postDObj = $ this -> dbu -> readConstellation ( $ returnedDeleteObj -> getID ( ) , $ returnedDeleteObj -> getVersion ( ) ) ; $ postDeleteNameCount = count ( $ postDObj -> getNameEntries ( ) ) ; $ this -> assertEquals ( $ preDeleteNameCount , ( $ postDeleteNameCount + 1 ) ) ; $ neNameListRef = $ postDObj -> getNameEntries ( ) ; $ origNCount = count ( $ neNameListRef ) ; $ name = $ neNameListRef [ 0 ] -> getOriginal ( ) ; $ modName = preg_replace ( '/(^.*) /' , '$1xx ' , $ name ) ; $ neNameListRef [ 0 ] -> setOriginal ( $ modName ) ; $ neNameListRef [ 0 ] -> setOperation ( \ snac \ data \ AbstractData :: $ OPERATION_UPDATE ) ; $ retObj = $ this -> dbu -> writeConstellation ( $ this -> user , $ postDObj , 'modified first alt name' , 'ingest cpf' ) ; $ this -> dbu -> writeConstellationStatus ( $ this -> user , $ retObj -> getID ( ) , 'needs review' , 'send for review after a name change' ) ; $ modObj = $ this -> dbu -> readConstellation ( $ retObj -> getID ( ) , $ retObj -> getVersion ( ) ) ; $ this -> assertEquals ( $ modName , $ modObj -> getNameEntries ( ) [ 0 ] -> getOriginal ( ) ) ; $ this -> assertTrue ( $ origNCount == count ( $ modObj -> getNameEntries ( ) ) ) ; $ this -> logger -> addDebug ( " Ending:  " . __METHOD__ ) ; }
Can we get a random Constellation?
Can we get a random Constellation?
/*
         * Delete a name and verify it.
         */ /*
         * We need the new version of the deleted record, which becomes the max(version) of the constellation.
         *
         * Older code used $mNObj->getNameEntries()[0]->getMainID() for the mainID, but it is better that
         * mainID aka ic_id exist only in the Constellation object. Or that we have a variable outside the
         * object as we do here.
         *
         */ /*
         * Post delete. The delete operation mints a new version number which is returned in the object
         * returned by writeConstellation().  We combine the new version and the known (and unchanged ic_id)
         * to create a new vhInfo associative list. Then we pass that to readConstellation() to get the
         * current copy of the constellation from the database.
         *
         * Note: constellation object getID() returns the constellation id, not the per-record id as with
         * getID() for all other data objects.
         *
         */ /*
         * Modify a name and save the modified name only. No other parts of the constellation are updated,
         * which is reasonable because no other parts have been modified. After saving, re-read the entire
         * constellation and check that the number of names is unchanged, and that we have the modified
         * name. An early bug caused names to multiply on update.
         *
         * Note: getNameEntries() returns a reference, and changes to that reference modify $postDObj in place.
         *
         * Use that name reference so we can modify the name in place without asking for it a second time.
         */ /*
         * This may be fine during testing, and simulates a record going off for review after a change.
         */ /*
         * Confirm that we can read the modified name back from the db.
         */