From 63e11203c0c000dd867727f44866f72a89563fe6 Mon Sep 17 00:00:00 2001 From: Justus Dieckmann Date: Tue, 23 Apr 2024 13:14:37 +0200 Subject: [PATCH 1/2] Codestyle: Adjust to new rules --- block_qrcode.php | 4 ++-- classes/block_qrcode_form.php | 8 ++++---- classes/output_image.php | 6 +++--- db/access.php | 26 +++++++++++++------------- lang/en/block_qrcode.php | 34 +++++++++++++++++----------------- renderer.php | 12 ++++++------ tests/generator/lib.php | 2 +- tests/output_image_test.php | 10 ++++++---- 8 files changed, 52 insertions(+), 50 deletions(-) diff --git a/block_qrcode.php b/block_qrcode.php index a157521..0ab8600 100644 --- a/block_qrcode.php +++ b/block_qrcode.php @@ -67,7 +67,7 @@ public function get_content() { $this->content->text .= $renderer->display_download_section($COURSE->id, $this->instance->id); } - $this->page->requires->js_call_amd('block_qrcode/fullscreenqrcode', 'init', array($qrcode)); + $this->page->requires->js_call_amd('block_qrcode/fullscreenqrcode', 'init', [$qrcode]); return $this->content; } @@ -78,7 +78,7 @@ public function get_content() { * @return array of applicable formats */ public function applicable_formats() { - return array('course-view' => true, 'mod' => false, 'my' => false); + return ['course-view' => true, 'mod' => false, 'my' => false]; } /** diff --git a/classes/block_qrcode_form.php b/classes/block_qrcode_form.php index 461ac3b..c785c88 100644 --- a/classes/block_qrcode_form.php +++ b/classes/block_qrcode_form.php @@ -53,8 +53,8 @@ public function definition() { 'select', 'format', get_string('formats', 'block_qrcode'), - array(1 => 'svg', 2 => 'png'), - array('id' => 'slc_format')); + [1 => 'svg', 2 => 'png'], + ['id' => 'slc_format']); $selectf->setSelected($this->_customdata['format']); // Select image size. @@ -62,8 +62,8 @@ public function definition() { 'select', 'size', get_string('sizes', 'block_qrcode'), - array(150 => '150px', 300 => '300px'), - array('id' => 'slc_size', 'disabled' => true)); + [150 => '150px', 300 => '300px'], + ['id' => 'slc_size', 'disabled' => true]); $selects->setSelected($this->_customdata['size']); $mform->disabledIf('size', 'format', 'eq', 1); diff --git a/classes/output_image.php b/classes/output_image.php index aa756a2..f01acb9 100644 --- a/classes/output_image.php +++ b/classes/output_image.php @@ -102,7 +102,7 @@ public function __construct($format, $size, $courseid, $instanceid) { $file = $CFG->localcachedir . '/block_qrcode/course-' . (int)$courseid . '-' . $this->size; // Set file path. - $instance = $DB->get_record('block_instances', array('id' => $instanceid), '*', MUST_EXIST); + $instance = $DB->get_record('block_instances', ['id' => $instanceid], '*', MUST_EXIST); $block = block_instance('qrcode', $instance); if (is_null($block->config)) { @@ -290,7 +290,7 @@ public function get_logo() { 'block_qrcode', 'customlogopng', 0, 'sortorder', false); if ($this->format == 1) { - if (count($filessvg) == 1 AND get_config('block_qrcode', 'allow_customlogo') == 1) { + if (count($filessvg) == 1 && get_config('block_qrcode', 'allow_customlogo') == 1) { $filesvg = reset($filessvg); return $filesvg; } else { @@ -311,7 +311,7 @@ public function get_logo() { } } } else { - if (count($filespng) == 1 AND get_config('block_qrcode', 'allow_customlogo') == 1) { + if (count($filespng) == 1 && get_config('block_qrcode', 'allow_customlogo') == 1) { $filepng = reset($filespng); return $filepng; } else { diff --git a/db/access.php b/db/access.php index ebeb9bd..f220917 100644 --- a/db/access.php +++ b/db/access.php @@ -23,25 +23,25 @@ */ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( - 'block/qrcode:addinstance' => array( +$capabilities = [ + 'block/qrcode:addinstance' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/site:manageblocks' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/site:manageblocks', + ], - 'block/qrcode:download' => array( + 'block/qrcode:download' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), -); + 'manager' => CAP_ALLOW, + ], + ], +]; diff --git a/lang/en/block_qrcode.php b/lang/en/block_qrcode.php index 3eadcde..7e726c6 100644 --- a/lang/en/block_qrcode.php +++ b/lang/en/block_qrcode.php @@ -22,27 +22,27 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['allow_customlogo'] = 'Allow Customlogo'; +$string['allow_customlogo_help'] = 'If the checkbox is checked, it allows teachers to upload a custom logo to be shown in the QR code'; +$string['button'] = 'Download'; +$string['cachedef_qrcodes'] = 'Cache for the QR codes'; +$string['customfilepng'] = 'Custom File .png'; +$string['customfilesvg'] = 'Custom File .svg'; +$string['editblock'] = 'Edit QR code block'; +$string['filename'] = 'course'; +$string['formats'] = 'Format'; +$string['img_tag_alt'] = 'QR code'; +$string['instc_uselogo'] = 'Use logo'; +$string['logofile_png'] = 'Choose .png logo'; +$string['logofile_svg'] = 'Choose .svg logo'; $string['pluginname'] = 'QR code'; +$string['privacy:metadata'] = 'The qrcode block only displays information about a course, but does not effect or store any personal data.'; $string['qrcode:addinstance'] = 'Add a new QR code block'; $string['qrcode:download'] = 'Show Download button'; -$string['filename'] = 'course'; -$string['cachedef_qrcodes'] = 'Cache for the QR codes'; -$string['img_tag_alt'] = 'QR code'; -$string['button'] = 'Download'; -$string['formats'] = 'Format'; -$string['sizes'] = 'Size'; $string['settings'] = 'QR code settings'; +$string['sizes'] = 'Size'; +$string['submit'] = 'Save changes'; +$string['uploadpng'] = 'Upload Customlogo as .png also'; $string['use_logo'] = 'Use logo'; $string['use_logo_help'] = 'If the checkbox is checked, a logo is shown in the QR code. By default the moodle logo is shown but you can upload a custom logo.'; -$string['logofile_png'] = 'Choose .png logo'; -$string['logofile_svg'] = 'Choose .svg logo'; -$string['submit'] = 'Save changes'; -$string['editblock'] = 'Edit QR code block'; $string['usedefault'] = 'Use default settings'; -$string['instc_uselogo'] = 'Use logo'; -$string['privacy:metadata'] = 'The qrcode block only displays information about a course, but does not effect or store any personal data.'; -$string['customfilesvg'] = 'Custom File .svg'; -$string['customfilepng'] = 'Custom File .png'; -$string['uploadpng'] = 'Upload Customlogo as .png also'; -$string['allow_customlogo'] = 'Allow Customlogo'; -$string['allow_customlogo_help'] = 'If the checkbox is checked, it allows teachers to upload a custom logo to be shown in the QR code'; diff --git a/renderer.php b/renderer.php index 77bbdb1..f945c10 100644 --- a/renderer.php +++ b/renderer.php @@ -39,13 +39,13 @@ class block_qrcode_renderer extends plugin_renderer_base { */ public function display_image($courseid, $instanceid) { $link = new moodle_url('/blocks/qrcode/download.php', - array('courseid' => $courseid, + ['courseid' => $courseid, 'download' => false, 'format' => 1, 'size' => 150, - 'instance' => $instanceid)); + 'instance' => $instanceid]); - return html_writer::img($link, get_string('img_tag_alt', 'block_qrcode'), array('id' => 'img_qrcode', 'width' => '90%')); + return html_writer::img($link, get_string('img_tag_alt', 'block_qrcode'), ['id' => 'img_qrcode', 'width' => '90%']); } /** @@ -56,10 +56,10 @@ public function display_image($courseid, $instanceid) { */ public function display_download_section($courseid, $instanceid) { $download = new moodle_url('/blocks/qrcode/download.php', - array('courseid' => $courseid, + ['courseid' => $courseid, 'download' => true, - 'instance' => $instanceid)); - $mform = new block_qrcode\block_qrcode_form($download, array('format' => 1, 'size' => 150), 'post', + 'instance' => $instanceid]); + $mform = new block_qrcode\block_qrcode_form($download, ['format' => 1, 'size' => 150], 'post', '', ['data-double-submit-protection' => 'off']); return $mform->render(); } diff --git a/tests/generator/lib.php b/tests/generator/lib.php index e2c8f14..64bff87 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -39,7 +39,7 @@ class block_qrcode_generator extends testing_block_generator { */ public function create_course() { $generator = advanced_testcase::getDataGenerator(); - $data = array(); + $data = []; // Create a course. $course = $generator->create_course(); diff --git a/tests/output_image_test.php b/tests/output_image_test.php index c42118d..bde719e 100644 --- a/tests/output_image_test.php +++ b/tests/output_image_test.php @@ -31,7 +31,7 @@ * @copyright 2017 T Gunkel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class output_image_test extends \advanced_testcase { +final class output_image_test extends \advanced_testcase { /** * course object * @var object @@ -48,7 +48,7 @@ class output_image_test extends \advanced_testcase { * * Create a course and a block instance. */ - protected function setUp() : void { + protected function setUp(): void { $generator = $this->getDataGenerator()->get_plugin_generator('block_qrcode'); $this->course = $generator->create_course()['course']; $this->block = $generator->create_instance(); @@ -59,8 +59,9 @@ protected function setUp() : void { /** * Tests, if the image is created. + * @covers \block_qrcode\output_image */ - public function test_create_image() { + public function test_create_image(): void { global $CFG; set_config('use_logo', 0, 'block_qrcode'); @@ -80,8 +81,9 @@ public function test_create_image() { /** * Tests, if the QR code is created with the moodle logo if no custom logo was uploaded * when no logo is uploaded. + * @covers \block_qrcode\output_image */ - public function test_no_logo() { + public function test_no_logo(): void { global $CFG; $this->assertEquals('', get_config('block_qrcode', 'logofile_svg')); From 0c80af80e91b5de5c2b194b3f7e5d90e6d85a232 Mon Sep 17 00:00:00 2001 From: Justus Dieckmann Date: Sun, 28 Apr 2024 00:16:09 +0200 Subject: [PATCH 2/2] CI: Update for Moodle 4.0 --- .github/workflows/moodle-ci.yml | 86 +++++++++------------------------ 1 file changed, 23 insertions(+), 63 deletions(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 496f0ce..618bd74 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: php: ['8.2'] - moodle-branch: ['MOODLE_403_STABLE'] + moodle-branch: ['MOODLE_404_STABLE'] database: ['pgsql'] steps: @@ -20,7 +20,7 @@ jobs: run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14 - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin @@ -36,29 +36,9 @@ jobs: ini-values: max_input_vars=5000 coverage: none - - name: Get composer cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Composer cache - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: npm cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Initialise moodle-plugin-ci run: | - composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 echo $(cd ci/bin; pwd) >> $GITHUB_PATH echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH sudo locale-gen en_AU.UTF-8 @@ -75,10 +55,6 @@ jobs: if: ${{ always() }} run: moodle-plugin-ci phplint - - name: PHP Copy/Paste Detector - if: ${{ always() }} - run: moodle-plugin-ci phpcpd - - name: PHP Mess Detector if: ${{ always() }} run: moodle-plugin-ci phpmd @@ -116,30 +92,20 @@ jobs: fail-fast: false matrix: php: ['8.0', '8.1', '8.2'] - moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE'] + moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE'] database: ['mariadb', 'pgsql'] exclude: + - php: '8.0' + moodle-branch: 'MOODLE_404_STABLE' - php: '8.2' moodle-branch: 'MOODLE_401_STABLE' include: - php: '7.4' - moodle-branch: 'MOODLE_39_STABLE' - database: 'mariadb' - - php: '7.4' - moodle-branch: 'MOODLE_39_STABLE' - database: 'pgsql' - - php: '8.0' - moodle-branch: 'MOODLE_311_STABLE' - database: 'mariadb' - - php: '8.0' - moodle-branch: 'MOODLE_311_STABLE' + moodle-branch: 'MOODLE_401_STABLE' database: 'pgsql' - - php: '8.0' - moodle-branch: 'MOODLE_400_STABLE' + - php: '7.4' + moodle-branch: 'MOODLE_401_STABLE' database: 'mariadb' - - php: '8.0' - moodle-branch: 'MOODLE_400_STABLE' - database: 'pgsql' steps: - name: Start MariaDB @@ -151,7 +117,7 @@ jobs: run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14 - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin @@ -162,24 +128,6 @@ jobs: ini-values: max_input_vars=5000 coverage: none - - name: Get composer cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - name: Composer cache - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - name: npm cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Initialise moodle-plugin-ci run: | composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 @@ -201,4 +149,16 @@ jobs: - name: Behat features if: ${{ always() }} - run: moodle-plugin-ci behat --profile chrome + run: moodle-plugin-ci behat --profile chrome --auto-rerun 0 + + # This step allows to upload Behat faildump (screenshots) as workflow artifact, + # so it can be downloaded and inspected. You don't need this step if you + # are not running Behat test. Artifact will be retained for 7 days. + - name: Upload Behat Faildump + if: ${{ failure() && steps.behat.outcome == 'failure' }} + uses: actions/upload-artifact@v4 + with: + name: Behat Faildump (${{ join(matrix.*, ', ') }}) + path: ${{ github.workspace }}/moodledata/behat_dump + retention-days: 7 + if-no-files-found: ignore