Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-37476

Unit test fails if course completion is enabled

    XMLWordPrintable

    Details

      Description

      Two issues here:

      1. In the test "core_course_external_testcase::test_create_courses" there is a conditional test on L390 that checks completion_info::is_enabled_for_site().

      Because PHPUnit pulls its config from the default for the setting (not from the site's config table) this branch is never executed even if you enable completion on the site you are testing. It will only run if you added "set_config('enablecompletion', 1);" in the test, or if you changed the enablecompletion default to 1 in admin/settings/subsystems.php.

      2. If that branch of code was executed there is a bug, causing a test failure:

      There was 1 error:

      1) core_course_external_testcase::test_create_courses
      Undefined index: enabledcompletion

      /home/simonc/code/mdl22/course/tests/externallib_test.php:392
      /home/simonc/code/mdl22/lib/phpunit/classes/advanced_testcase.php:76

      The issue is that the array key on L391 should be 'enablecompletion' not 'enabledcompletion'.

      The fix for the 2nd problem is to correct the type in the array key. The 1st problem could be fixed by removing the if statement and the 'true' condition completely or by using set_config() and testing with and without completion enabled separately.

        Attachments

          Activity

            People

            Assignee:
            jerome Jérôme Mouneyrac
            Reporter:
            simoncoggins Simon Coggins
            Peer reviewer:
            Rajesh Taneja
            Integrator:
            Sam Hemelryk
            Tester:
            Rossiani Wijaya
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              11/Mar/13