Error when running unit test

Issue #59 resolved
eason yao created an issue
  1. format_tiles_course_courselib_testcase::test_course_restored_event
    Trying to access array offset on value of type null

/siteroot/course/format/tiles/lib.php:733
/siteroot/backup/moodle2/restore_stepslib.php:1922
/siteroot/backup/util/plan/restore_structure_step.class.php:137
/siteroot/backup/util/helper/restore_structure_parser_processor.class.php:121
/siteroot/backup/util/xml/parser/processors/grouped_parser_processor.class.php:178
/siteroot/backup/util/helper/restore_structure_parser_processor.class.php:109
/siteroot/backup/util/xml/parser/processors/simplified_parser_processor.class.php:148
/siteroot/backup/util/xml/parser/processors/progressive_parser_processor.class.php:92
/siteroot/backup/util/xml/parser/progressive_parser.class.php:190
/siteroot/backup/util/xml/parser/progressive_parser.class.php:237
/siteroot/backup/util/xml/parser/progressive_parser.class.php:179
/siteroot/backup/util/xml/parser/progressive_parser.class.php:158
/siteroot/backup/util/plan/restore_structure_step.class.php:110
/siteroot/backup/util/plan/base_task.class.php:181
/siteroot/backup/util/plan/base_plan.class.php:178
/siteroot/backup/util/plan/restore_plan.class.php:168
/siteroot/backup/controller/restore_controller.class.php:385
/siteroot/course/format/tiles/tests/format_tiles_courselib_test.php:2089
/siteroot/lib/phpunit/classes/advanced_testcase.php:80

To re-run:
vendor/bin/phpunit "format_tiles_course_courselib_testcase" course/format/tiles/tests/format_tiles_courselib_test.php

I guess we should not assume anyone has capacity moodle/course:update is updating course. we should add && $oldcourse !== null to https://bitbucket.org/dw8/moodle-format_tiles/src/098c9658f0717d9ed2e69199e648354fbead0f05/lib.php#lines-732

Comments (4)

  1. Kristian Ringer

    I did this to fix the issue:

    diff --git a/lib.php b/lib.php
    index 02969ff..b25b072 100755
    --- a/lib.php
    +++ b/lib.php
    @@ -730,14 +730,14 @@ class format_tiles extends format_base {
                 $coursecontext = context_course::instance($courseid);
    
                 if (has_capability('moodle/course:update', $coursecontext)) {
    -                if ($oldcourse['format'] !== 'tiles') {
    +                if ($oldcourse !== null && $oldcourse['format'] !== 'tiles') {
                         // We are switching in to tiles from something else.
                         // Double check we don't have any old tiles images in the {files} table.
                         format_tiles\tile_photo::delete_all_tile_photos_course($courseid);
                     }
    
                     // If we are changing from Grid format, we iterate through each of the grid images and set it up for this format.
    -                if ($oldcourse['format'] == 'grid') {
    +                if ($oldcourse !== null && $oldcourse['format'] == 'grid') {
                         $gridformaticons = $DB->get_records('format_grid_icon', array('courseid' => $courseid), 'sectionid');
    

    It’s not letting me open a PR on Bitbucket though

  2. Log in to comment