test/snac/server/ServerTest.php
/**
     * Test editing and updating a constellation by the server
     * @param \snac\data\Constellation $constellation The Constellation object from testReadConstellation
     * @depends testReadConstellation
     */
Test editing and updating a constellation by the server
@param \snac\data\Constellation $constellation The Constellation object from testReadConstellation
@depends testReadConstellation
Test editing and updating a constellation by the server @param \ snac \ data \ Constellation $constellation The Constellation object from testReadConstellation @depends testReadConstellation
public function testEditUpdateConstellation(\snac\data\Constellation $constellation) {
        if ($constellation == null) {
            $this->fail("Depends on read constellation");
        }
        $server = new Server( array(
                "command" => "edit",
                "user" => $this->user->toArray(),
                "constellationid" => $constellation->getID()
        ));
        $server->run();
        $response = $server->getResponse();
        $this->assertNotNull($response);
        $response = json_decode($response, true);
        $this->assertArrayHasKey("constellation", $response);
        $c = new \snac\data\Constellation($response["constellation"]);
        $this->assertTrue($c->equals($constellation, false), "Read copy is not equal to original");
        $nE = new \snac\data\NameEntry();
        $nE->setOperation(\snac\data\NameEntry::$OPERATION_INSERT);
        $nE->setOriginal("Snac Test Original Name");
        $c->addNameEntry($nE);
        $c->getSources()[0]->setOperation(\snac\data\Source::$OPERATION_DELETE);
        $server = new Server( array(
                "command" => "update_constellation",
                "user" => $this->user->toArray(),
                "constellation" => $c->toArray()
        ));
        $server->run();
        $response = $server->getResponse();
        $this->assertNotNull($response);
        $response = json_decode($response, true);
        $this->assertArrayHasKey("constellation", $response);
        $this->assertEquals("success", $response["result"]);
        $c2 = new \snac\data\Constellation($response["constellation"]);
        $this->assertTrue($c->equals($c2, false), "Updated returned copy is not equal to original");
        $server = new Server( array(
                "command" => "read",
                "user" => $this->user->toArray(),
                "constellationid" => $c2->getID(),
                "version" => $c2->getVersion()
        ));
        $server->run();
        $response = $server->getResponse();
        $this->assertNotNull($response);
        $response = json_decode($response, true);
        $this->assertArrayHasKey("constellation", $response);
        $c3 = new \snac\data\Constellation($response["constellation"]);
        $newSources = $c->getSources();
        array_shift($newSources);
        $c->setAllSources($newSources);
        $this->assertTrue($c->equals($c3, false), "The updated copy on read is not the same as the updated original");
    }
public function testEditUpdateConstellation ( \ snac \ data \ Constellation $ constellation ) { if ( $ constellation == null ) { $ this -> fail ( " Depends on read constellation " ) ; } $ server = new Server ( array ( " command " => " edit " , " user " => $ this -> user -> toArray ( ) , " constellationid " => $ constellation -> getID ( ) ) ) ; $ server -> run ( ) ; $ response = $ server -> getResponse ( ) ; $ this -> assertNotNull ( $ response ) ; $ response = json_decode ( $ response , true ) ; $ this -> assertArrayHasKey ( " constellation " , $ response ) ; $ c = new \ snac \ data \ Constellation ( $ response [ " constellation " ] ) ; $ this -> assertTrue ( $ c -> equals ( $ constellation , false ) , " Read copy is not equal to original " ) ; $ nE = new \ snac \ data \ NameEntry ( ) ; $ nE -> setOperation ( \ snac \ data \ NameEntry :: $ OPERATION_INSERT ) ; $ nE -> setOriginal ( " Snac Test Original Name " ) ; $ c -> addNameEntry ( $ nE ) ; $ c -> getSources ( ) [ 0 ] -> setOperation ( \ snac \ data \ Source :: $ OPERATION_DELETE ) ; $ server = new Server ( array ( " command " => " update_constellation " , " user " => $ this -> user -> toArray ( ) , " constellation " => $ c -> toArray ( ) ) ) ; $ server -> run ( ) ; $ response = $ server -> getResponse ( ) ; $ this -> assertNotNull ( $ response ) ; $ response = json_decode ( $ response , true ) ; $ this -> assertArrayHasKey ( " constellation " , $ response ) ; $ this -> assertEquals ( " success " , $ response [ " result " ] ) ; $ c2 = new \ snac \ data \ Constellation ( $ response [ " constellation " ] ) ; $ this -> assertTrue ( $ c -> equals ( $ c2 , false ) , " Updated returned copy is not equal to original " ) ; $ server = new Server ( array ( " command " => " read " , " user " => $ this -> user -> toArray ( ) , " constellationid " => $ c2 -> getID ( ) , " version " => $ c2 -> getVersion ( ) ) ) ; $ server -> run ( ) ; $ response = $ server -> getResponse ( ) ; $ this -> assertNotNull ( $ response ) ; $ response = json_decode ( $ response , true ) ; $ this -> assertArrayHasKey ( " constellation " , $ response ) ; $ c3 = new \ snac \ data \ Constellation ( $ response [ " constellation " ] ) ; $ newSources = $ c -> getSources ( ) ; array_shift ( $ newSources ) ; $ c -> setAllSources ( $ newSources ) ; $ this -> assertTrue ( $ c -> equals ( $ c3 , false ) , " The updated copy on read is not the same as the updated original " ) ; }
Test editing and updating a constellation by the server
 @param \snac\data\Constellation $constellation The Constellation object from testReadConstellation
 @depends testReadConstellation
Test editing and updating a constellation by the server @param \ snac \ data \ Constellation $constellation The Constellation object from testReadConstellation @depends testReadConstellation
// Remove the first source (should have been deleted)