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

Unittests fail if a plugin creates a role on install

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Requires code modifications

      1. Locate any standard plugin in moodle that has db/install.php (for example, auth/cas/db/install.php )
      2. Add the following code to the _install() function:

            $roleid = create_role('Dummy role', 'mydummyrole', '', '');
            assign_capability('moodle/user:editownprofile', CAP_ALLOW, $roleid, context_system::instance()->id);
         
            foreach (get_role_archetypes() as $archetype) {
                if (!in_array($archetype, ['guest', 'user', 'frontpage'])) {
                    $roleid = create_role($archetype . ' Copy', $archetype . 'copy', '', $archetype);
                    assign_capability('moodle/user:editownprofile', CAP_ALLOW, $roleid, context_system::instance()->id);
                }
            }
        

      3. Initialise and run unittests on accesslib and enrol_self and make sure they pass:

        php admin/tool/phpunit/cli/util.php --drop
        php admin/tool/phpunit/cli/init.php
        ./vendor/bin/phpunit lib/tests/accesslib_test.php
        ./vendor/bin/phpunit enrol/self/tests/self_test.php
        

      Show
      Requires code modifications Locate any standard plugin in moodle that has db/install.php (for example, auth/cas/db/install.php ) Add the following code to the _install() function: $roleid = create_role('Dummy role', 'mydummyrole', '', ''); assign_capability('moodle/user:editownprofile', CAP_ALLOW, $roleid, context_system::instance()->id);   foreach (get_role_archetypes() as $archetype) { if (!in_array($archetype, ['guest', 'user', 'frontpage'])) { $roleid = create_role($archetype . ' Copy', $archetype . 'copy', '', $archetype); assign_capability('moodle/user:editownprofile', CAP_ALLOW, $roleid, context_system::instance()->id); } } Initialise and run unittests on accesslib and enrol_self and make sure they pass: php admin/tool/phpunit/cli/util.php --drop php admin/tool/phpunit/cli/init.php ./vendor/bin/phpunit lib/tests/accesslib_test.php ./vendor/bin/phpunit enrol/self/tests/self_test.php
    • Affected Branches:
      MOODLE_37_STABLE
    • Fixed Branches:
      MOODLE_36_STABLE, MOODLE_37_STABLE
    • Pull 3.6 Branch:
    • Pull 3.7 Branch:
    • Pull Master Branch:
      MDL-65726-master

      Description

      If a plugin creates a role in its install.php the core unittest fails.

      We need to be able to create some roles on install and we also want to have all core unittests passing.

      The unittest

      $this->assertCount(8, $allroles); // There are 8 roles is standard install.
      

      can be replaced with one that checks that standard roles were indeed created but without counting them.

        Attachments

        1. screenshot-1.png
          screenshot-1.png
          62 kB
        2. screenshot-2.png
          screenshot-2.png
          248 kB
        3. screenshot-3.png
          screenshot-3.png
          302 kB

          Issue Links

            Activity

              People

              • Assignee:
                marina Marina Glancy
                Reporter:
                marina Marina Glancy
                Peer reviewer:
                David Matamoros
                Integrator:
                Adrian Greeve
                Tester:
                Janelle Barcega
                Participants:
                Component watchers:
                Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  8/Jul/19

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 4 hours, 5 minutes
                  4h 5m