Skip to content

Commit

Permalink
Add some controller tests for import and update
Browse files Browse the repository at this point in the history
Currently these just  validate expected errors caused by limitations
in the test stack.
  • Loading branch information
mikesname committed Apr 13, 2021
1 parent 88a332e commit a7bb058
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helpers/TeiEditions_Helpers_DataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function updateItems($items, $neatline, &$updated)
$currentItem->id, metadata($currentItem, "display_title"), $e->getMessage());
throw new TeiEditions_Helpers_ImportError($msg, 0, $e);
} else {
throw $e;
throw new TeiEditions_Helpers_ImportError("Error running update", 0, $e);
}
}
}
Expand Down
52 changes: 52 additions & 0 deletions test/integration/AdminController_FilesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* @package TeiEditions
*
* @copyright Copyright 2021 King's College London Department of Digital Humanities
*/


class AdminController_FilesTest extends TeiEditions_Case_Default
{
public function setUpLegacy()
{
parent::setUpLegacy();

$importer = new TeiEditions_Helpers_DataImporter(get_db());

$created = 0;
$updated = 0;
$onDone = function() { };
$importer->importData(
__DIR__ . '/../resources/enhance-tei.xml',
'text/xml',
false,
false,
$created,
$updated,
function(){}
);
$this->assertEquals(1, $created);
}

public function testFilesImport() {
// TODO: figure out how to test an upload...???
$this->request->setMethod('POST');
$this->dispatch('tei-editions/files/import');

// The form will error because we haven't provided a file
$this->assertXpath("//div[@id='flash']/ul/li[@class='error']");
}

public function testFilesUpdate() {
// An empty items[] key should update all items...
$this->request->setMethod('POST')->setPost(['create_exhibit' => 0]);
$this->dispatch('tei-editions/files/update');

// NB: as with the Data Import test I haven't figured out how to
// make updating work in the test environment because the files are
// not available at their web URL. Therefore, for now asserting that
// this method errors as expected at least ensures it doesn't crash.
$this->assertXpath("//div[@id='flash']/ul/li[@class='error']");
}
}

0 comments on commit a7bb058

Please sign in to comment.