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

Core unit tests fail when plugins define their custom fields in install

XMLWordPrintable

    • MOODLE_401_STABLE
    • MDL-78303-master
    • Hide

      No manual testing is required.
      CI will make sure the unit test is passing:

      root@01c31895db1b:/var/www/vanilla-moodle-master# vendor/bin/phpunit --filter='test_get_empty_internalfield_list'
      Moodle 4.3dev (Build: 20230512), 063ffc8073c679537b3a23ec8f3fc3dec03dba69
      Php: 8.0.26, pgsql: 14.0 (Debian 14.0-1.pgdg110+1), OS: Linux 5.15.0-69-generic x86_64
      PHPUnit 9.5.27 by Sebastian Bergmann and contributors.
       
      .                                                                   1 / 1 (100%)
       
      Time: 01:23.600, Memory: 326.00 MB
       
      OK (1 test, 1 assertion)
      

      Show
      No manual testing is required. CI will make sure the unit test is passing: root @01c31895db1b :/var/www/vanilla-moodle-master# vendor/bin/phpunit --filter= 'test_get_empty_internalfield_list' Moodle 4 .3dev (Build: 20230512 ), 063ffc8073c679537b3a23ec8f3fc3dec03dba69 Php: 8.0 . 26 , pgsql: 14.0 (Debian 14.0 - 1 .pgdg110+ 1 ), OS: Linux 5.15 . 0 - 69 -generic x86_64 PHPUnit 9.5 . 27 by Sebastian Bergmann and contributors.   . 1 / 1 ( 100 %)   Time: 01 : 23.600 , Memory: 326.00 MB   OK ( 1 test, 1 assertion)

      Got the following unit test failure recently:

      Moodle 4.1.3+ (Build: 20230427)
      Php: 7.4.33, mariadb: 10.5.20, OS: Linux 5.15.0-1023-aws x86_64
      PHPUnit 9.5.27 by Sebastian Bergmann and contributors.
       
      ...
       
      There were N failures:
       
      1) core\oauth2_test::test_get_empty_internalfield_list
      Failed asserting that two arrays are equal.
      --- Expected
      +++ Actual
      @@ @@
           16 => 'alternatename'
           17 => 'picture'
           18 => 'username'
      +    19 => 'profile_field_provider'
      +    20 => 'profile_field_birthdate'
       )
       
      /var/www/site/lib/tests/oauth2_test.php:557
      /var/www/site/lib/phpunit/classes/advanced_testcase.php:80
      phpvfscomposer:///var/www/site/vendor/phpunit/phpunit/phpunit:97
      

      The profile_field_provider and profile_field_birthdate fields are fields added by a 3rd party plugin on install.

      They way the test asserts user fields doesn't allow plugins to add their custom fields, see https://github.com/moodle/moodle/blob/017a3274fe8f24ab2473eb6e5626070f97d2721d/lib/tests/oauth2_test.php#L547-L558

      Seems to be a regression of MDL-77436.

      Steps to replicate:

      1. Add a plugin that has any profile fields, eg:

        git clone git@github.com:golenkovm/moodle-local_mdl_helper.git local/mdl_helper
        

      2. Run the unit test and confirm it fails:

        root@01c31895db1b:/var/www/vanilla-moodle-master# vendor/bin/phpunit --filter='test_get_empty_internalfield_list'
        Moodle 4.3dev (Build: 20230512), 063ffc8073c679537b3a23ec8f3fc3dec03dba69
        Php: 8.0.26, pgsql: 14.0 (Debian 14.0-1.pgdg110+1), OS: Linux 5.15.0-69-generic x86_64
        PHPUnit 9.5.27 by Sebastian Bergmann and contributors.
         
        F                                                                   1 / 1 (100%)
         
        Time: 00:00.700, Memory: 320.00 MB
         
        There was 1 failure:
         
        1) core\oauth2_test::test_get_empty_internalfield_list
        Failed asserting that two arrays are equal.
        --- Expected
        +++ Actual
        @@ @@
             16 => 'alternatename'
             17 => 'picture'
             18 => 'username'
        +    19 => 'profile_field_myprofilefield1'
        +    20 => 'profile_field_myprofilefield2'
         )
         
        /var/www/vanilla-moodle-master/lib/tests/oauth2_test.php:557
        /var/www/vanilla-moodle-master/lib/phpunit/classes/advanced_testcase.php:94
         
        FAILURES!
        Tests: 1, Assertions: 1, Failures: 1.
        

      Edit: the following tests are failing:

      test_create_custom_profile_field_category

      test_create_custom_profile_field

      test_get_empty_internalfield_list (this is the one you mentioned)

            Unassigned Unassigned
            mikhailgolenkov Misha Golenkov
            Votes:
            0 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 - 5 minutes
                5m

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