Skip to content

Commit

Permalink
MDL-45131 files: Add validation for returned parameters in WS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jleyva committed Apr 16, 2015
1 parent b489630 commit b780109
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions files/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function test_upload() {
// Call the api to create a file.
$fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath,
$filename, $filecontent, $contextlevel, $instanceid);
$fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
// Get the created draft item id.
$itemid = $fileinfo['itemid'];

Expand All @@ -76,6 +77,7 @@ public function test_upload() {
// Call the api to create a file.
$fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid,
$filepath, $filename, $filecontent, $contextlevel, $instanceid);
$fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
$file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
$this->assertNotEmpty($file);

Expand All @@ -88,6 +90,7 @@ public function test_upload() {
$this->assertEmpty($file);
$fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath,
$filename, $filecontent, $contextlevel, $instanceid);
$fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
$file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
$this->assertNotEmpty($file);

Expand Down Expand Up @@ -142,7 +145,8 @@ public function test_upload_param_area() {
$instanceid = null;

// Make sure the file is created.
@core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent);
$fileinfo = @core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent);
$fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
$browser = get_file_browser();
$file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
$this->assertNotEmpty($file);
Expand All @@ -165,7 +169,8 @@ public function test_upload_without_new_param() {
$filename = "Simple4.txt";
$filecontent = base64_encode("Let us create a nice simple file");

@core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent);
$fileinfo = @core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent);
$fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);

// Assert debugging called (deprecation warning).
$this->assertDebuggingCalled();
Expand Down Expand Up @@ -251,6 +256,7 @@ public function test_get_files() {
// The first time is with a valid context ID.
$filename = '';
$testfilelisting = core_files_external::get_files($context->id, $component, $filearea, $itemid, '/', $filename);
$testfilelisting = external_api::clean_returnvalue(core_files_external::get_files_returns(), $testfilelisting);

// With the information that we have provided we should get an object exactly like the one below.
$coursecontext = context_course::instance($course->id);
Expand Down Expand Up @@ -311,6 +317,8 @@ public function test_get_files() {
$contextlevel = 'module';
$instanceid = $module->cmid;
$testfilelisting = core_files_external::get_files($nocontext, $component, $filearea, $itemid, '/', $filename, $modified, $contextlevel, $instanceid);
$testfilelisting = external_api::clean_returnvalue(core_files_external::get_files_returns(), $testfilelisting);

$this->assertEquals($testfilelisting, $testdata);
}
}

0 comments on commit b780109

Please sign in to comment.