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

after_file_create hook is not run in unit tests

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.5.3
    • Files API

      MDL-75850 added logic to skip firing the after_file_created hook in unit tests.

      https://github.com/moodle/moodle/blob/b9a5ed77371d1a3af2e255492ae98a6967701dd2/lib/filestorage/file_storage.php#L1079-L1081

      This causes problems for unit tests that test functionality triggered by the after_file_created hook.

      This is not an ideal approach to take. Hooks should fire in unit tests. If a unit test requires specific functionality (or to avoid specific functionality) from a hook, it can be intercepted by mocking a hook listener: https://moodledev.io/docs/5.0/apis/core/hooks#dispatching-hooks

      It seems like at one point there was an `after_file_created` listener (initially introduced in MDL-75850), but MDL-83245 since removed that listener, and there are no others in core. So it should be safe to revert this code back to how it used to be (i.e., always fire the hook).

            Unassigned Unassigned
            cameron1729 cameron1729
            cameron1729 cameron1729
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 minute
                1m

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