Permalink
Browse files

filters incorrect URIs for knowledge base creation out

adds a test for the filter and  adds  frontendlogin into the ControllerTestCase.php
  • Loading branch information...
shinobu committed Oct 4, 2016
1 parent 5585752 commit d28de8504dfe18987e9d41c79a71af41557db62a
@@ -82,6 +82,16 @@ public function setUpExtensionIntegrationTest()
}
}
public function frontEndLogin() {
$store = OntoWiki::getInstance()->erfurt->getStore();
$this->request->setMethod('POST')->setPost(
array(
'u' => $store->getDbUser(),
'p' => $store->getDbPassword()
)
);
}
private function _markTestNeedsDatabase()
{
$config = Erfurt_App::getInstance(false)->getConfig();
@@ -2,7 +2,7 @@
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2006-2016, {@link http://aksw.org AKSW}
* @copyright Copyright (c) 2006-2017, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
@@ -503,6 +503,13 @@ public function createAction()
);
$this->view->errorFlag = true;
return;
} else if (filter_var($newModelUri, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) === false
&& strcmp(substr($newModelUri, 0, 4), 'urn:') != 0
) {
//the filter doesnt filter urn's properly, hence they are excluded from the check
$this->_owApp->appendMessage(
new OntoWiki_Message('The given String is no legal URI', OntoWiki_Message::ERROR)
);
} else {
// model does not exist, will be created
$model = $store->getNewModel(
@@ -0,0 +1,77 @@
<?php
/**
* This file is part of the {@link http://ontowiki.net OntoWiki} project.
*
* @copyright Copyright (c) 2006-2017, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
*/
/**
* This test class comtains tests for the OntoWiki service controller.
*
* @category OntoWiki
* @package controlers
* @subpackage IntegrationTests
* @copyright Copyright (c) 2017, {@link http://aksw.org AKSW}
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License, version 2 (GPLv2)
* @author Fabian Niehoff <niehoff.fabian@web.de>
*/
class ModelControllerTest extends OntoWiki_Test_ControllerTestCase
{
public function setUp()
{
$this->setUpIntegrationTest();
//this is necessary to allow the dispatch to create a model (ac)
$this->frontEndLogin();
}
/**
* @dataProvider uriProvider
*/
public function testCreateActionFiltersOnlyIncorrectUris($uri, $correctUri)
{
$this->dispatch('/service/auth');
$this->request->setPost(
array(
'title' => 'test',
'modeluri' => $uri,
'importOptions' => 'import-empty'
)
);
$this->dispatch('/model/create');
$this->assertController('model');
$this->assertAction('create');
//when the URI is correct expect the model in the store
$store = OntoWiki::getInstance()->erfurt->getStore();
if ($correctUri) {
$this->assertTrue($store->isModelAvailable($uri, true));
} else {
$this->assertFalse($store->isModelAvailable($uri, true));
}
}
public function uriProvider()
{
return [
['ftp://ftp.is.co.za.example.org/ontowiki/ontowiki.txt', true],
['gopher://spinaltap.micro.umn.example.edu/00/Weather/California/Los%20Angeles', true],
['http://www.ontowiki.aksw.no.example.net/faq/ontowiki-faq/part1.html', true],
['mailto:aksw@ifi.unizh.example.gov', true],
['news:comp.aksw.www.servers.unix', true],
['telnet://melvyl.ucop.example.edu/', true],
['http://www.ietf.org/rfc/rfc2396.txt', true],
['ldap://[2001:db8::7]/c=GB?objectClass?one', true],
['mailto:AKSW.L@example.com', true],
['telnet://192.0.2.16:80/', true],
['urn:oasis:names:specification:docbook:dtd:xml:4.1.2', true],
['https://www.aksw.org/faq', true],
['ptth://www.aksw.org', true],
['\\äüö', false],
['plainText', false],
['noProtocol.de', false],
['http://www.äß', false],
['http://www.⺅⺔.com', false]
];
}
}

0 comments on commit d28de85

Please sign in to comment.