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

Unittests fail if a plugin creates a role on install

XMLWordPrintable

    • MOODLE_37_STABLE
    • MOODLE_36_STABLE, MOODLE_37_STABLE
    • MDL-65726-master
    • 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

      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.

        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

            marina Marina Glancy
            marina Marina Glancy
            David Carrillo David Carrillo
            Adrian Greeve Adrian Greeve
            Janelle Barcega Janelle Barcega
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.