Source of file GetRecordByIdCommandTest.php
Size: 7,235 Bytes - Last Modified: 2021-12-23T10:31:40+00:00
/var/www/docs.ssmods.com/process/src/tests/GetRecordByIdCommandTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 | <?php /** * @package geocatalog * @subpackage tests */ class GetRecordByIdCommandTest extends SapphireTest { /** * Also uses SimpleNzctFixture in setUp() */ public static $fixture_file = 'geocatalogue/tests/GetRecordByIdCommandTest.yml'; 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() . 'GetRecordByIdCommandTest_Controller'; $page = $this->objFromFixture('BrowsePage', 'catalogbrowsepage'); $page->GeonetworkBaseURL = $url; $this->controller = new BrowsePage_Controller($page); $this->controller->pushCurrent(); //GetRecordsCommand::set_catalogue_url("/dogetrecordbyid/7f1db956-b017-427c-866d-25c7a8af7384/?usetestmanifest=1&flush=1"); GetRecordByIdCommand::set_catalogue_url("/getrecords?usetestmanifest=1&flush=1"); } /** * Remove test controller from global controller-stack. */ public function tearDown() { $this->controller->popCurrent(); parent::tearDown(); } /** * Test the testGetRecordByIdCommand * * Test the testGetRecordByIdCommand. The test controller GetRecordByIdCommandTest_Controller * expects a certain request and returns ok or failed. * * This test tests the cswGetRecordById_xml template only. * * @see GetRecordByIdCommand * @see GetRecordByIdCommandTest_Controller */ public function testGetRecordByIdCommand() { $id = '7f1db956-b017-427c-866d-25c7a8af7384'; $outputFormat = 'html'; $format = 'iso'; $data = array( 'fileIdentifier' => Convert::raw2xml($id), 'outputFormat' => Convert::raw2xml($outputFormat), 'requestxml' => 'cswGetRecordByID_xml' ); $cmd = $this->controller->getCommand("GetRecordById", $data); $result = $cmd->execute(); $position = strpos($result, '<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" outputSchema="csw:IsoRecord">'); if ($position === false) { $this->assertEquals(1, 0, "Invalid CSW GetRecordById XML request"); } $position = strpos($result, "<csw:Id>". $id ."</csw:Id>"); if ($position === false) { $this->assertEquals(1, 0, "Invalid csw:Id or not found"); } } /** * * This test tests the cswGetRecordById_xml template only. * Without ID * * @see GetRecordByIdCommand * @see GetRecordByIdCommandTest_Controller */ public function testGetRecordByIdCommandWithoutID() { $id = ''; $outputFormat = 'html'; $format = 'iso'; $data = array( 'fileIdentifier' => Convert::raw2xml($id), 'outputFormat' => Convert::raw2xml($outputFormat), 'requestxml' => 'cswGetRecordByID_xml' ); $cmd = $this->controller->getCommand("GetRecordById", $data); $result = $cmd->execute(); $position = strpos($result, '<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" outputSchema="csw:IsoRecord">'); if ($position === false) { $this->assertEquals(1, 0, "Invalid CSW GetRecordById XML request"); } $position = strpos($result, "<csw:Id>". $id ."</csw:Id>"); if ($position === false) { $this->assertEquals(1, 0, "Failed empty id"); } } /** * * This test tests the cswGetRecordById_xml template only. * With > in ID * * @see GetRecordByIdCommand * @see GetRecordByIdCommandTest_Controller */ public function testGetRecordByIdCommandWithLessThenInID() { $id = 'whatever < this means'; $outputFormat = 'html'; $format = 'iso'; $data = array( 'fileIdentifier' => Convert::raw2xml($id), 'outputFormat' => Convert::raw2xml($outputFormat), 'requestxml' => 'cswGetRecordByID_xml' ); $cmd = $this->controller->getCommand("GetRecordById", $data); $result = $cmd->execute(); $position = strpos($result, '<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" outputSchema="csw:IsoRecord">'); if ($position === false) { $this->assertEquals(1, 0, "Invalid CSW GetRecordById XML request"); } $position = strpos($result, "<csw:Id>whatever < this means</csw:Id>"); if ($position === false) { $this->assertEquals(1, 0, "failed id with < \n" . $result); } } /** * * This test tests the cswGetRecordById_xml template only. * With ' in ID * * @see GetRecordByIdCommand * @see GetRecordByIdCommandTest_Controller */ public function testGetRecordByIdCommandWithQuoteInID() { $id = 'with \' here'; $outputFormat = 'html'; $format = 'iso'; $data = array( 'fileIdentifier' => Convert::raw2xml($id), 'outputFormat' => Convert::raw2xml($outputFormat), 'requestxml' => 'cswGetRecordByID_xml' ); $cmd = $this->controller->getCommand("GetRecordById", $data); $result = $cmd->execute(); $position = strpos($result, '<csw:GetRecordById xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" service="CSW" version="2.0.2" outputSchema="csw:IsoRecord">'); if ($position === false) { $this->assertEquals(1, 0, "Invalid CSW GetRecordById XML request"); } // NOTE: // This is not an interesting change. When converting a ' into xml // we got a plain ' back, later this behaviour changed and returned // ' instead of '. // Again a change, now we get a ' back again. // Need ot investigate side effects of this new behaviour $position = (strpos($result, "<csw:Id>with ' here</csw:Id>")) ? (strpos($result, "<csw:Id>with ' here</csw:Id>")) : strpos($result, "<csw:Id>with ' here</csw:Id>"); if ($position === false) { $this->assertEquals(1, 0, "failed id with ' \n"); } } } /** * @package geocatalog * @subpackage tests * * Mockup controller class to simulate the GeoNetwork side in this test. */ class GetRecordByIdCommandTest_Controller extends Controller { /** * 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($data) { $request = $data->getBody(); return $request; } } |