Source of file GetRecordsCommandTest.php
Size: 7,012 Bytes - Last Modified: 2021-12-23T10:31:40+00:00
/var/www/docs.ssmods.com/process/src/tests/GetRecordsCommandTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 | <?php /** * @package geocatalog * @subpackage tests */ class GetRecordsCommandTest extends SapphireTest { /** * Also uses SimpleNzctFixture in setUp() */ public static $fixture_file = 'geocatalogue/tests/GetRecordsCommandTest.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() . 'GetRecordsCommandTest_Controller'; $page = $this->objFromFixture('CataloguePage', 'catalogue'); $page->GeonetworkBaseURL = $url; $this->controller = new CataloguePage_Controller($page); $this->controller->pushCurrent(); GetRecordsCommand::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 testGetRecordsInISOCommand * * Test the testGetRecordsInISOCommand. The test controller GetRecordsCommandTest_Controller * expects a certain request and returns ok or failed. * * This test tests the cswGetRecordsSummaryISO_xml template only. * * @see GetRecordsCommand * @see GetRecordsCommandTest_Controller */ public function testGetRecordsInISOCommand() { $data = array(); $data['requestxml'] = "cswGetRecordsSummaryISO_xml"; $data['searchterm'] = "testGetRecordsCommand"; $data['startPosition'] = "5"; $data['maxRecords'] = "15"; $cmd = $this->controller->getCommand("GetRecords", $data); $result = $cmd->execute(); $position = strpos($result, '<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" service="CSW" version="2.0.2" resultType="results" outputSchema="csw:IsoRecord" maxRecords="15" startPosition="5">'); if ($position === false) { $this->assertEquals(1, 0, 'Invalid CSW GetRecord XML request.'); } $position = strpos($result, '<Literal>%testGetRecordsCommand%</Literal>'); if ($position === false) { $this->assertEquals(1, 0, 'Invalid literal search term.'); } } /** * Test the testDefaultValues * * Test the testDefaultValues. The test controller GetRecordsCommandTest_Controller * expects a certain request and returns ok or failed. * * This test tests the cswGetRecordsSummaryISO_xml template only. * * @see GetRecordsCommand * @see GetRecordsCommandTest_Controller */ public function testDefaultValuesForPaging() { $data = array(); $data['requestxml'] = "cswGetRecordsSummaryISO_xml"; $data['searchterm'] = "testGetRecordsCommand"; $cmd = $this->controller->getCommand("GetRecords", $data); $result = $cmd->execute(); $position = strpos($result, '<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" service="CSW" version="2.0.2" resultType="results" outputSchema="csw:IsoRecord" maxRecords="10" startPosition="0">'); if ($position === false) { $this->assertEquals(1, 0, 'Invalid CSW GetRecord XML request.'); } } /** * Test the testDefaultValuesForSearchTerm */ public function testDefaultValuesForSearchTerm() { $data = array(); $data['requestxml'] = "cswGetRecordsSummaryISO_xml"; $data['startPosition'] = "0"; $data['maxRecords'] = "10"; $cmd = $this->controller->getCommand("GetRecords", $data); try { $result = $cmd->execute(); } catch (CreateRequestCommand_Exception $e) { return; } $this->assertTrue(false, "Exception expected, but hasn't been thrown."); } /** * Test the testDefaultValuesForSearchTerm */ public function testDefaultValuesForRequestXML() { $data = array(); $data['searchterm'] = "testGetRecordsCommand"; $data['startPosition'] = "0"; $data['maxRecords'] = "10"; $cmd = $this->controller->getCommand("GetRecords", $data); try { $result = $cmd->execute(); } catch (CreateRequestCommand_Exception $e) { return; } $this->assertTrue(false, "Exception expected, but hasn't been thrown."); } /** * Test the testApostrophySearchTerm * * * This test tests the cswGetRecordsSummaryISO_xml template only. * * @see GetRecordsCommand * @see GetRecordsCommandTest_Controller */ public function testApostrophySearchTerm() { $data = array(); $data['requestxml'] = "cswGetRecordsSummaryISO_xml"; $data['searchterm'] = "test'test"; $data['startPosition'] = "0"; $data['maxRecords'] = "0"; $cmd = $this->controller->getCommand("GetRecords", $data); $result = $cmd->execute(); $position = strpos($result, "<Literal>%test'test%</Literal>"); if ($position === false) { $this->assertEquals(1, 0, 'Invalid literal search term.'); } } /** * Test the testLessThanSearchTerm * * * This test tests the cswGetRecordsSummaryISO_xml template only. * * @see GetRecordsCommand * @see GetRecordsCommandTest_Controller */ public function testLessThanSearchTerm() { $data = array(); $data['requestxml'] = "cswGetRecordsSummaryISO_xml"; $data['searchterm'] = "test<test"; $data['startPosition'] = "0"; $data['maxRecords'] = "0"; $cmd = $this->controller->getCommand("GetRecords", $data); $result = $cmd->execute(); $position = strpos($result, "<Literal>%test<test%</Literal>"); if ($position === false) { $this->assertEquals(1, 0, 'Invalid literal search term.'); } } } /** * @package geocatalog * @subpackage tests * * Mockup controller class to simulate the GeoNetwork side in this test. */ class GetRecordsCommandTest_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; } } |