diff --git a/tests/form_test.php b/tests/form_test.php index f8448ec..0dac0cb 100644 --- a/tests/form_test.php +++ b/tests/form_test.php @@ -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. @@ -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'); @@ -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(); } @@ -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 diff --git a/tests/other_test.php b/tests/other_test.php index 8aa3185..8d51b32 100644 --- a/tests/other_test.php +++ b/tests/other_test.php @@ -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(''); } /**