Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit ff5a9a7

Browse files
authored
Merge pull request #368 from AKSW/fix/content-types-for-resource-exports
Fix content-type for resource exports
2 parents 14fbe19 + 8214d40 commit ff5a9a7

File tree

4 files changed

+30
-83
lines changed

4 files changed

+30
-83
lines changed

application/classes/OntoWiki/Test/ControllerTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public function setUpUnitTest()
4343
);
4444

4545
parent::setUp();
46+
47+
$this->_storeAdapter = Erfurt_App::getInstance(false)->getStore()->getBackendAdapter();
4648
}
4749

4850
public function setUpExtensionUnitTest()

application/classes/OntoWiki/Test/UnitTestBootstrap.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,20 @@ public function _initErfurt()
6161
);
6262
$erfurt->setStore($store);
6363

64+
$erfurt->setAc(new Erfurt_Ac_None());
65+
6466
// make available
6567
$ontoWiki->erfurt = $erfurt;
6668

6769
return $erfurt;
6870
}
71+
72+
public function _initPlugins()
73+
{
74+
// require front controller
75+
$this->bootstrap('frontController');
76+
$frontController = $this->getResource('frontController');
77+
78+
// We do not register any plugins for unit tests.
79+
}
6980
}

application/controllers/ResourceController.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -478,24 +478,9 @@ public function exportAction()
478478

479479
$filename = 'export' . date('Y-m-d_Hi');
480480

481-
switch ($format) {
482-
case 'rdfxml':
483-
$contentType = 'application/rdf+xml';
484-
$filename .= '.rdf';
485-
break;
486-
case 'rdfn3':
487-
$contentType = 'text/rdf+n3';
488-
$filename .= '.n3';
489-
break;
490-
case 'rdfjson':
491-
$contentType = 'application/json';
492-
$filename .= '.json';
493-
break;
494-
case 'turtle':
495-
$contentType = 'application/x-turtle';
496-
$filename .= '.ttl';
497-
break;
498-
}
481+
$formatDescription = Erfurt_Syntax_RdfSerializer::getFormatDescription($format);
482+
$contentType = $formatDescription['contentType'];
483+
$filename .= $formatDescription['fileExtension'];
499484

500485
/*
501486
* Event: allow for adding / deleting statements to the export

application/tests/unit/controller/ResourceControllerTest.php

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,71 +23,20 @@ public function setUp()
2323
$this->setUpUnitTest();
2424
}
2525

26-
public function testDummyTestUnlessNoWorkingActualTestExists()
26+
public function testExportActionReturnsCorrectContentTypeForTurtle()
2727
{
28-
$this->assertTrue(true);
28+
$r = 'http://example.org/resource1';
29+
$m = 'http://example.org/model1/';
30+
$this->_storeAdapter->createModel($m);
31+
32+
$this->request->setParam('r', $r);
33+
$this->request->setParam('m', $m);
34+
$this->request->setParam('f', 'turtle');
35+
$this->dispatch('/resource/export');
36+
37+
$this->assertController('resource');
38+
$this->assertAction('export');
39+
$this->assertResponseCode(200);
40+
$this->assertHeaderContains('Content-Type', 'text/turtle');
2941
}
30-
31-
/*
32-
public function testListInstantiation()
33-
{
34-
$this->request->setMethod('POST')
35-
->setPost(
36-
array(
37-
'list' => 'instances',
38-
'init' => true,
39-
)
40-
);
41-
42-
$this->dispatch('/list');
43-
44-
$this->assertController('resource');
45-
$this->assertAction('instances');
46-
$this->assertResponseCode(200);
47-
}
48-
49-
50-
public function testListConfig()
51-
{
52-
$c = array(
53-
'filter' => array(
54-
'action' => 'add',
55-
'mode' => 'box',
56-
'filter' => 'equals',
57-
'value' => 'http://test.com/'
58-
)
59-
);
60-
$this->request->setMethod('POST')
61-
->setPost(
62-
array(
63-
'list' => 'instances',
64-
'init' => true,
65-
'instancesconfig' => json_encode($c)
66-
)
67-
);
68-
69-
$this->dispatch('/list');
70-
71-
$this->assertController('resource');
72-
$this->assertAction('instances');
73-
$this->assertResponseCode(200);
74-
}
75-
76-
public function testListError()
77-
{
78-
$c = array();
79-
$this->request->setMethod('POST')
80-
->setPost(
81-
array(
82-
'list' => 'newone',
83-
//no init parameter
84-
'instancesconfig' => json_encode($c)
85-
)
86-
);
87-
88-
$this->dispatch('/list');
89-
90-
$this->assertController('error');
91-
}
92-
*/
9342
}

0 commit comments

Comments
 (0)