Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

Unit tests for file_system_filedir.

Copyright: 2017 Andrew Nicols <andrew@nicols.co.uk>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1127 lines (38 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: core_files_file_system_filedir_testcase  - X-Ref

Unit tests for file_system_filedir.

setUp()   X-Ref
Shared test setUp.


tearDown()   X-Ref
Shared teset tearDown.


setup_vfile_root($filedir = [], $trashdir = [], $sourcedir = null)   X-Ref
Helper function to help setup and configure the virtual file system stream.

param: array $filedir Directory structure and content of the filedir
param: array $trashdir Directory structure and content of the sourcedir
param: array $sourcedir Directory structure and content of a directory used for source files for tests
return: \org\bovigo\vfs\vfsStream

get_stored_file($filecontent, $filename = null, $mockedmethods = null)   X-Ref
Helper to create a stored file objectw with the given supplied content.

param: string  $filecontent The content of the mocked file
param: string  $filename The file name to use in the stored_file
param: array   $mockedmethods A list of methods you intend to override
return: stored_file

get_testable_mock($mockedmethods = [])   X-Ref
Get a testable mock of the file_system_filedir class.

param: array   $mockedmethods A list of methods you intend to override
return: file_system

test_readonly_filesystem_filedir()   X-Ref
Ensure that an appropriate error is shown when the filedir directory
is not writable.


test_readonly_filesystem_trashdir()   X-Ref
Ensure that an appropriate error is shown when the trash directory
is not writable.


test_warnings_put_in_place()   X-Ref
Test that the standard Moodle warning message is put into the filedir.


test_get_remote_path_from_hash()   X-Ref
Ensure that the default implementation of get_remote_path_from_hash
simply calls get_local_path_from_hash.


test_get_local_path_from_storedfile_with_recovery()   X-Ref
Test the stock implementation of get_local_path_from_storedfile_with_recovery with no file found and
a failed recovery.


test_get_local_path_from_storedfile_without_recovery()   X-Ref
Test the stock implementation of get_local_path_from_storedfile_with_recovery with no file found and
a failed recovery.


test_get_fulldir_from_hash($hash, $hashdir)   X-Ref
Test that the correct path is generated for the supplied content
hashes.

param: string  $hash contenthash to test
param: string  $hashdir Expected format of content directory

test_get_fulldir_from_storedfile($hash, $hashdir)   X-Ref
Test that the correct path is generated for the supplied content
hashes when used with a stored_file.

param: string  $hash contenthash to test
param: string  $hashdir Expected format of content directory

test_get_contentdir_from_hash($hash, $hashdir)   X-Ref
Test that the correct content directory is generated for the supplied
content hashes.

param: string  $hash contenthash to test
param: string  $hashdir Expected format of content directory

test_get_contentpath_from_hash($hash, $hashdir)   X-Ref
Test that the correct content path is generated for the supplied
content hashes.

param: string  $hash contenthash to test
param: string  $hashdir Expected format of content directory

test_get_trash_fullpath_from_hash($hash, $hashdir)   X-Ref
Test that the correct trash path is generated for the supplied
content hashes.

param: string  $hash contenthash to test
param: string  $hashdir Expected format of content directory

test_get_trash_fulldir_from_hash($hash, $hashdir)   X-Ref
Test that the correct trash directory is generated for the supplied
content hashes.

param: string  $hash contenthash to test
param: string  $hashdir Expected format of content directory

test_copy_content_from_storedfile()   X-Ref
Ensure that copying a file to a target from a stored_file works as anticipated.


test_recover_file()   X-Ref
Ensure that content recovery works.


test_recover_file_already_present()   X-Ref
Ensure that content recovery works.


test_recover_file_size_mismatch()   X-Ref
Ensure that content recovery works.


test_recover_file_has_mismatch()   X-Ref
Ensure that content recovery works.


test_recover_file_alttrash()   X-Ref
Ensure that content recovery works when the content file is in the
alt trash directory.


test_recover_file_contentdir_readonly()   X-Ref
Test that an appropriate error message is generated when adding a
file to the pool when the pool directory structure is not writable.


test_add_file_from_path()   X-Ref
Test adding a file to the pool.


test_add_file_from_path_file_unavailable()   X-Ref
Test that an appropriate error message is generated when adding an
unavailable file to the pool is attempted.


test_add_file_from_path_mismatched_hash()   X-Ref
Test that an appropriate error message is generated when specifying
the wrong contenthash when adding a file to the pool.


test_add_file_from_path_existing_content_invalid()   X-Ref
Test that an appropriate error message is generated when an existing
file in the pool has the wrong contenthash


test_add_file_from_path_existing_cannot_write_hashpath()   X-Ref
Test that an appropriate error message is generated when adding a
file to the pool when the pool directory structure is not writable.


test_add_file_from_string()   X-Ref
Test adding a string to the pool.


test_add_file_from_string_existing_cannot_write_hashpath()   X-Ref
Test that an appropriate error message is generated when adding a
string to the pool when the pool directory structure is not writable.


test_add_file_from_string_existing_matches()   X-Ref
Test adding a string to the pool when an item with the same
contenthash is already present.


test_remove_file_missing()   X-Ref
Test the cleanup of deleted files when there are no files to delete.


test_remove_file_existing_trash()   X-Ref
Test the cleanup of deleted files when a file already exists in the
trash for that path.


test_remove_file_empty()   X-Ref
Ensure that remove_file does nothing with an empty file.


test_remove_file_in_use()   X-Ref
Ensure that remove_file does nothing when a file is still
in use.


test_remove_file_expired()   X-Ref
Ensure that remove_file removes the file when it is no
longer in use.


test_empty_trash()   X-Ref
Test purging the cache.


contenthash_dataprovider()   X-Ref
Data Provider for contenthash to contendir conversion.

return: array