Source of file GnPublishMetadataCommandTest.php
Size: 4,596 Bytes - Last Modified: 2021-12-23T10:31:40+00:00
/var/www/docs.ssmods.com/process/src/tests/GnPublishMetadataCommandTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 | <?php /** * @package geocatalog * @subpackage tests */ class GnPublishMetadataCommandTest extends SapphireTest { /** * Also uses SimpleNzctFixture in setUp() */ public static $fixture_file = 'geocatalogue/tests/GnGetUUIDOfRecordByIDCommandTest.yml'; public static $xsl_path = ''; protected $controller = null; /** * Initiate the controller and page classes and configure GeoNetwork service * to use the mockup-controller for testing. */ public function setUp() { parent::setUp(); $url = Director::absoluteBaseURL() . 'GnPublishMetadataCommandTest_Controller'; $page = $this->objFromFixture('RegisterDataPage', 'registerdatapage'); $page->GeonetworkBaseURL = $url; $this->controller = new CataloguePage_Controller($page); $this->controller->pushCurrent(); //GetRecordsCommand::set_catalogue_url("/getrecords?usetestmanifest=1&flush=1"); GnPublishMetadataCommand::set_api_url('/getrecords?usetestmanifest=1&flush=1'); // check from where the test is executed (important when running the // tests via a CI environment. self::$xsl_path = GnPublishMetadataCommand::get_xsl_path(); if (in_array('cli-script.php', scandir('.'))) { // system is in sapphire directory GnPublishMetadataCommand::set_xsl_path('../geocatalogue/xslt/gnInsertResponse.xsl'); } elseif (in_array('geocatalog', scandir('.'))) { GnPublishMetadataCommand::set_xsl_path('geocatalogue/xslt/gnInsertResponse.xsl'); } } /** * Remove test controller from global controller-stack. */ public function tearDown() { $this->controller->popCurrent(); GnPublishMetadataCommand::set_xsl_path(self::$xsl_path); parent::tearDown(); } /** * Test the GnPublishMetadataCommand * */ public function testGnPublishMetadataCommand() { $data = array(); $data['gnID'] = 1963; $cmd = $this->controller->getCommand("GnPublishMetadata", $data); $result = $cmd->execute(); $this->assertEquals($result, 1963, 'GnPublishMetadataCommand returned another ID. It should throw an exception instead.'); } /** * Test the GnPublishMetadataCommand with an unexpectes id * */ public function testGnPublishMetadataCommandWithUnexpectedId() { $data = array(); $data['gnID'] = 2009; $cmd = $this->controller->getCommand("GnPublishMetadata", $data); try { $result = $cmd->execute(); } catch (GnPublishMetadataCommand_Exception $e) { return; } $this->assertEquals(1, 0, 'GnPublishMetadataCommand has not thrown a "GeoNetwork publication has failed" exception'); } /** * Test the GnPublishMetadataCommand with 0 id * which leads in a fake-response without an <id> tag * resulting in an exception */ public function testGnPublishMetadataCommandWithNullId() { $data = array(); $data['gnID'] = 1234; $cmd = $this->controller->getCommand("GnPublishMetadata", $data); try { $result = $cmd->execute(); } catch (GnPublishMetadataCommand_Exception $e) { return; } $this->assertEquals(1, 0, 'GnPublishMetadataCommand has not thrown a "GeoNetwork ID for the new dataset has not been created" exception'); } } /** * @package geocatalog * @subpackage tests * * Mockup controller class to simulate the GeoNetwork side in this test. */ class GnPublishMetadataCommandTest_Controller extends Controller implements TestOnly { /** * Standard method, not in use. */ public function index() { BasicAuth::disable(); return "failed"; } /** * Returns the request body so that the calling unit test can perform the validation. * * @return string request body */ public function getrecords($httprequest) { $paramid=$_POST['id']; $resp=$this->getResponse(); $resp->addHeader("Content-Type", "text/xml"); // if id=0 was given we use this test to force an exception by omitting the <id> tag if ($paramid == 1234) { return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Failresponse></Failresponse>"; } return"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><id>1963</id></response>"; } } |