Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebleu committed Apr 24, 2024
1 parent 893f12b commit 66bf146
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
32 changes: 25 additions & 7 deletions tests/form_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@

namespace repository_s3bucket;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->dirroot . '/repository/s3bucket/lib.php');

/**
* Form tests.
Expand All @@ -50,6 +44,10 @@ final class form_test extends \advanced_testcase {
* Create type and instance.
*/
public function setUp(): void {
global $CFG;
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->dirroot . '/repository/s3bucket/lib.php');
$this->resetAfterTest(true);
set_config('s3mock', true);
$this->getDataGenerator()->create_repository_type('s3bucket');
Expand All @@ -58,7 +56,8 @@ public function setUp(): void {
'endpoint' => 'eu-west-2',
'secret_key' => 'secret',
'bucket_name' => 'test',
'access_key' => 'abc', ];
'access_key' => 'abc',
];
$this->SetAdminUser();
}

Expand Down Expand Up @@ -105,6 +104,25 @@ public function test_instance_form(): void {
$this->assertStringContainsString('Required', $out);
}

/**
* Test instance form error.
* @covers \repository_s3bucket
*/
public function test_instance_form2(): void {
global $USER;
$context = \context_user::instance($USER->id);
$para = ['plugin' => 's3bucket', 'typeid' => '', 'instance' => null, 'contextid' => $context->id];
$mform = new \repository_instance_form('', $para);
$this->data['bucket_name'] = '';
$this->expectException('InvalidArgumentException');
\repository_s3bucket::instance_form_validation($mform, $this->data, []);
$this->data['bucket_name'] = 'test';
$this->data['endpoint'] = 'aws_instance_wrong';
$this->expectException('Aws\Exception\InvalidRegionException');
\repository_s3bucket::instance_form_validation($mform, $this->data, []);
}


/**
* Test instance form with proxy.
* @covers \repository_s3bucket
Expand Down
4 changes: 4 additions & 0 deletions tests/other_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public function test_getfile(): void {
get_file_storage()->create_file_from_string($filerecord, 'test content');
$result = $repo->get_file('/filename.txt');
$this->assertEquals('/filename.txt', $result['url']);
$result = $repo->get_file('/otherfilename.txt');
$this->assertEquals('/otherfilename.txt', $result['url']);
$this->expectException('moodle_exception');
$result = $repo->get_file('');
}

/**
Expand Down

0 comments on commit 66bf146

Please sign in to comment.