Skip to content

Commit

Permalink
Merge pull request #67 from sarahjcotton/moodle401-fixes
Browse files Browse the repository at this point in the history
Fix to use correct DEBUG_ const causing unit test to fail
  • Loading branch information
marxjohnson authored Feb 8, 2023
2 parents 75f342c + af76b53 commit af78cd4
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://github.com/catalyst/moodle-fileconverter_librelambda/workflows/Run%20all%20tests%20for%20Moodle%2034+/badge.svg)](https://github.com/catalyst/moodle-fileconverter_librelambda/actions)
![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/catalyst/moodle-fileconverter_librelambda/ci.yml?branch=master)

# Libre Lambda Document Converter #

Expand Down
2 changes: 1 addition & 1 deletion classes/converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static function are_requirements_met() {
$converter = new \fileconverter_librelambda\converter();
// First check that we have the basic configuration settings set.
if (!$converter->is_config_set()) {
debugging(get_string('settings:confignotset', 'fileconverter_librelambda'), 'notifyproblem');
debugging(get_string('settings:confignotset', 'fileconverter_librelambda'), DEBUG_NORMAL);
return false;
}
$converter->create_client();
Expand Down
9 changes: 9 additions & 0 deletions classes/event/poll_conversion_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,25 @@
*/
class poll_conversion_status extends \core\event\base {

/**
* Init function.
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;

}

/**
* Get event name.
*/
public static function get_name() {
return get_string('event:poll_conversion_status', 'fileconverter_librelambda');
}

/**
* Get event description.
*/
public function get_description() {
return "The conversion with id '{$this->other['id']}' has been polled and returned the status '{$this->other['status']}'.";
}
Expand Down
9 changes: 9 additions & 0 deletions classes/event/start_document_conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,25 @@
*/
class start_document_conversion extends \core\event\base {

/**
* Init function.
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;

}

/**
* Get event name.
*/
public static function get_name() {
return get_string('event:start_document_conversion', 'fileconverter_librelambda');
}

/**
* Get event description.
*/
public function get_description() {
return "The conversion with id '{$this->other['id']}' has been commenced with status '{$this->other['status']}'.";
}
Expand Down
3 changes: 3 additions & 0 deletions classes/provision.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provision {
/** The default stack name */
const DEFAULT_STACK_NAME = 'LambdaConvert';

/** The max bucket prefix length */
const MAX_BUCKET_PREFIX_LEN = 52;

/**
Expand Down
4 changes: 3 additions & 1 deletion cli/get_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This command line script will get all document files from S3 in a site that
* The command line script.
*
* Will get all document files from S3 in a site that
* uses the object fs plugin and download them locally
*
* @package fileconverter_librelambda
Expand Down
5 changes: 4 additions & 1 deletion cli/provision.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
";
$stacknotexistsmsg = "Stack does not exsist.";

function abort($msg) {
/** Abort function
* @param string $msg
*/
function abort(string $msg) {
echo "$msg\n";
die;
}
Expand Down
7 changes: 6 additions & 1 deletion tests/converter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* @copyright 2018 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace fileconverter_librelambda;

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

global $CFG;
Expand All @@ -33,6 +36,8 @@
use Psr\Http\Message\RequestInterface;
use Aws\S3\Exception\S3Exception;
use \core_files\conversion;
use \context_module;
use \ReflectionMethod;

/**
* PHPUnit tests for Libre Lambda file converter.
Expand All @@ -41,7 +46,7 @@
* @copyright 2018 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class fileconverter_librelambda_converter_testcase extends advanced_testcase {
class converter_test extends \advanced_testcase {

/**
* Test is_config_set method with missing configuration.
Expand Down
6 changes: 5 additions & 1 deletion tests/events_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* @copyright 2018 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace fileconverter_librelambda;

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

global $CFG;
Expand All @@ -33,6 +36,7 @@
use Psr\Http\Message\RequestInterface;
use Aws\S3\Exception\S3Exception;
use \core_files\conversion;
use \context_module;

/**
* PHPUnit tests for Libre Lambda file converter.
Expand All @@ -41,7 +45,7 @@
* @copyright 2018 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class fileconverter_librelambda_events_testcase extends advanced_testcase {
class events_test extends \advanced_testcase {

/**
* Test start document conversion method.
Expand Down
25 changes: 14 additions & 11 deletions tests/provision_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
* @copyright 2018 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace fileconverter_librelambda;

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

global $CFG;
require_once($CFG->dirroot . '/local/aws/sdk/aws-autoloader.php');

use Aws\Result;
use Aws\MockHandler;
use Aws\Result;
use Aws\CommandInterface;
use Psr\Http\Message\RequestInterface;
use Aws\S3\Exception\S3Exception;
Expand All @@ -41,7 +44,7 @@
* @copyright 2018 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mock_provision extends \fileconverter_librelambda\provision {
class provision_mock extends provision {
/**
*
* @var MockHandler
Expand Down Expand Up @@ -100,29 +103,29 @@ public function check_bucket_exists($bucketname) {
* Create an S3 Bucket in AWS.
* Upgrade to public.
*
* @param string $bucketname The name to use for the S3 bucket.
* @return \stdClass $result The result of the bucket creation.
*/
public function create_resource_bucket() {
return parent::create_resource_bucket();
}
}


/**
* PHPUnit tests for Libre Lambda AWS provision.
*
* @package fileconverter_librelambda
* @copyright 2018 Matt Porritt <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class fileconverter_librelambda_provision_testcase extends advanced_testcase {
class provision_test extends \advanced_testcase {

/**
* Test the does bucket exist method. Should return false.
* We mock out the S3 client response as we are not trying to connect to the live AWS API.
*/
public function test_create_resource_bucket_exists_false() {
$provisioner = new mock_provision();
$provisioner = new provision_mock();

$provisioner->mocks3handler->append(function (CommandInterface $cmd, RequestInterface $req) {
return new S3Exception('Mock exception', $cmd, ['code' => 'NotFound']);
Expand All @@ -144,7 +147,7 @@ public function test_create_resource_bucket_exists_false() {
* We mock out the S3 client response as we are not trying to connect to the live AWS API.
*/
public function test_create_resource_bucket_exists_true() {
$provisioner = new mock_provision();
$provisioner = new provision_mock();

$provisioner->mocks3handler->append(new Result([]));

Expand All @@ -161,7 +164,7 @@ public function test_create_resource_bucket_exists_true() {
* We mock out the S3 client response as we are not trying to connect to the live AWS API.
*/
public function test_create_resource_bucket_exists_forbidden() {
$provisioner = new mock_provision();
$provisioner = new provision_mock();

$bucketname = 'foobar';
$provisioner->mocks3handler->append(function (CommandInterface $cmd, RequestInterface $req) {
Expand All @@ -179,7 +182,7 @@ public function test_create_resource_bucket_exists_forbidden() {
public function test_provision_stack_exists_no_replace() {
global $CFG;

$provisioner = new mock_provision();
$provisioner = new provision_mock();

$provisioner->mocks3handler->append(new Result([]));
$provisioner->mocks3handler->append(new Result(['ObjectURL' => "https://amazon/lambdaconvert.zip"]));
Expand Down Expand Up @@ -212,7 +215,7 @@ public function test_provision_stack_exists_replace() {
global $CFG;

$lambdazip = 'lambdaconvert.zip';
$provisioner = new mock_provision();
$provisioner = new provision_mock();

$provisioner->mocks3handler->append(new Result([]));
$provisioner->mocks3handler->append(new Result(['ObjectURL' => "https://amazon/$lambdazip"]));
Expand Down Expand Up @@ -268,7 +271,7 @@ public function test_provision_stack_not_exists() {

$stack = 'AnotherStack';
$lambdazip = 'lambdaconvert.zip';
$provisioner = new mock_provision($stack);
$provisioner = new provision_mock($stack);

$provisioner->mocks3handler->append(new Result([]));
$provisioner->mocks3handler->append(new Result(['ObjectURL' => "https://amazon/$lambdazip"]));
Expand Down Expand Up @@ -323,7 +326,7 @@ public function test_remove_stack_remove_objects_ok() {
global $CFG;

$filename = 'some.file';
$provisioner = new mock_provision();
$provisioner = new provision_mock();

$cloudformationpath = $CFG->dirroot . '/files/converter/librelambda/lambda/stack.template';
$provisioner->mockcloudformationhandler->append(new Result([
Expand Down
8 changes: 4 additions & 4 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'fileconverter_librelambda';
$plugin->release = 2022011500;
$plugin->version = 2022011500;
$plugin->release = 2023010900;
$plugin->version = 2023010900;
$plugin->requires = 2017111309;
$plugin->maturity = MATURITY_STABLE;
$plugin->dependencies = array(
'local_aws' => 2020061500
'local_aws' => 2022033100
);
$plugin->supported = [34, 311]; // A range of branch numbers of supported moodle versions.
$plugin->supported = [34, 401]; // A range of branch numbers of supported moodle versions.

0 comments on commit af78cd4

Please sign in to comment.