Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

PHPUnit tests for fileconverter API.

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

Defines 7 classes

core_files_converter_testcase:: (33 methods):
  get_testable_mock()
  get_testable_conversion()
  get_mocked_converter()
  get_stored_file()
  create_stored_file()
  get_file_storage_mock()
  test_start_conversion_existing_single()
  test_start_conversion_existing_multiple()
  test_start_conversion_no_existing()
  test_get_document_converter_classes_no_plugins()
  test_get_document_converter_classes_plugin_class_not_found()
  test_get_document_converter_classes_plugin_class_requirements_not_met()
  test_get_document_converter_classes_plugin_class_met_not_supported()
  test_get_document_converter_classes_plugin_class_met_and_supported()
  test_can_convert_storedfile_to_directory()
  test_can_convert_storedfile_to_emptyfile()
  test_can_convert_storedfile_to_no_mimetype()
  test_can_convert_storedfile_to_docx()
  test_can_convert_format_to_found()
  test_can_convert_format_to_not_found()
  test_poll_conversion_in_progress()
  test_poll_conversion_in_progress_fail()
  test_poll_conversion_none_supported()
  test_poll_conversion_pick_first()
  test_poll_conversion_pick_subsequent()
  test_start_conversion_one_supported_success()
  test_start_conversion_one_supported_failure()
  test_start_conversion_two_supported()
  test_get_next_converter_no_converters()
  test_get_next_converter_only_converters()
  test_get_next_converter_last_converters()
  test_get_next_converter_middle_converters()
  test_get_next_converter_first()

core_file_converter_requirements_test_base:: (5 methods):
  are_requirements_met()
  start_document_conversion()
  poll_conversion_status()
  supports()
  get_supported_conversions()

core_file_converter_requirements_not_met_test:: (0 methods):

core_file_converter_type_not_supported_test:: (1 method):
  are_requirements_met()

core_file_converter_type_supported_test:: (2 methods):
  are_requirements_met()
  supports()

core_file_converter_type_successful:: (2 methods):
  start_document_conversion()
  supports()

core_file_converter_type_failed:: (3 methods):
  are_requirements_met()
  start_document_conversion()
  supports()


Class: core_files_converter_testcase  - X-Ref

PHPUnit tests for fileconverter API.

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

param: array   $mockedmethods A list of methods you intend to override
return: \core_files\converter

get_testable_conversion($mockedmethods = [])   X-Ref
Get a testable mock of the conversion.

param: array   $mockedmethods A list of methods you intend to override
return: \core_files\conversion

get_mocked_converter($mockedmethods = [])   X-Ref
Get a testable mock of the abstract files_converter class.

param: array   $mockedmethods A list of methods you intend to override
return: \core_files\converter_interface

get_stored_file($filecontent = 'content', $filename = null, $filerecord = [], $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

create_stored_file($filecontent = 'content', $filename = 'testfile.txt', $filerecord = [])   X-Ref
Helper to create a stored file object 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: string $filerecord Any overrides to the filerecord
return: stored_file

get_file_storage_mock($mockedmethods = [])   X-Ref
Get a mock of the file_storage API.

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

test_start_conversion_existing_single()   X-Ref
Test the start_conversion function.


test_start_conversion_existing_multiple()   X-Ref
Test the start_conversion function.


test_start_conversion_no_existing()   X-Ref
Test the start_conversion function.


test_get_document_converter_classes_no_plugins()   X-Ref
Test the get_document_converter_classes function with no enabled plugins.


test_get_document_converter_classes_plugin_class_not_found()   X-Ref
Test the get_document_converter_classes function when no class was found.


test_get_document_converter_classes_plugin_class_requirements_not_met()   X-Ref
Test the get_document_converter_classes function when the returned classes do not meet requirements.


test_get_document_converter_classes_plugin_class_met_not_supported()   X-Ref
Test the get_document_converter_classes function when the returned classes do not meet requirements.


test_get_document_converter_classes_plugin_class_met_and_supported()   X-Ref
Test the get_document_converter_classes function when the returned classes do not meet requirements.


test_can_convert_storedfile_to_directory()   X-Ref
Test the can_convert_storedfile_to function with a directory.


test_can_convert_storedfile_to_emptyfile()   X-Ref
Test the can_convert_storedfile_to function with an empty file.


test_can_convert_storedfile_to_no_mimetype()   X-Ref
Test the can_convert_storedfile_to function with a file with indistinguished mimetype.


test_can_convert_storedfile_to_docx()   X-Ref
Test the can_convert_storedfile_to function with a file with a known mimetype and extension.


test_can_convert_format_to_found()   X-Ref
Test the can_convert_format_to function.


test_can_convert_format_to_not_found()   X-Ref
Test the can_convert_format_to function.


test_poll_conversion_in_progress()   X-Ref
Test the can_convert_storedfile_to function with an empty file.


test_poll_conversion_in_progress_fail()   X-Ref
Test poll_conversion with an in-progress conversion where we are
unable to instantiate the converter instance.


test_poll_conversion_none_supported()   X-Ref
Test the can_convert_storedfile_to function with an empty file.


test_poll_conversion_pick_first()   X-Ref
Test the can_convert_storedfile_to function with an empty file.


test_poll_conversion_pick_subsequent()   X-Ref
Test the can_convert_storedfile_to function with an empty file.


test_start_conversion_one_supported_success()   X-Ref
Test the start_conversion with a single converter which succeeds.


test_start_conversion_one_supported_failure()   X-Ref
Test the start_conversion with a single converter which failes.


test_start_conversion_two_supported()   X-Ref
Test the start_conversion with two converters - fail, then succeed.


test_get_next_converter_no_converters()   X-Ref
Ensure that get_next_converter returns false when no converters are available.


test_get_next_converter_only_converters()   X-Ref
Ensure that get_next_converter returns false when already on the
only converter.


test_get_next_converter_last_converters()   X-Ref
Ensure that get_next_converter returns false when already on the
last converter.


test_get_next_converter_middle_converters()   X-Ref
Ensure that get_next_converter returns the next vlaue when in a
current converter.


test_get_next_converter_first()   X-Ref
Ensure that get_next_converter returns the next vlaue when in a
current converter.


Class: core_file_converter_requirements_test_base  - X-Ref

are_requirements_met()   X-Ref
Whether the plugin is configured and requirements are met.

return: bool

start_document_conversion(conversion $conversion)   X-Ref
Convert a document to a new format and return a conversion object relating to the conversion in progress.

param: conversion $conversion The file to be converted
return: conversion

poll_conversion_status(conversion $conversion)   X-Ref
Poll an existing conversion for status update.

param: conversion $conversion The file to be converted
return: conversion

supports($from, $to)   X-Ref
Whether a file conversion can be completed using this converter.

param: string $from The source type
param: string $to The destination type
return: bool

get_supported_conversions()   X-Ref
A list of the supported conversions.

return: string

Class: core_file_converter_requirements_not_met_test  - X-Ref

Test class for converter support with requirements are not met.

Class: core_file_converter_type_not_supported_test  - X-Ref

Test class for converter support with requirements met and conversion not supported.

are_requirements_met()   X-Ref
Whether the plugin is configured and requirements are met.

return: bool

Class: core_file_converter_type_supported_test  - X-Ref

Test class for converter support with requirements met and conversion supported.

are_requirements_met()   X-Ref
Whether the plugin is configured and requirements are met.

return: bool

supports($from, $to)   X-Ref
Whether a file conversion can be completed using this converter.

param: string $from The source type
param: string $to The destination type
return: bool

Class: core_file_converter_type_successful  - X-Ref

Test class for converter support with requirements met and successful conversion.

start_document_conversion(conversion $conversion)   X-Ref
Convert a document to a new format and return a conversion object relating to the conversion in progress.

param: conversion $conversion The file to be converted
return: conversion

supports($from, $to)   X-Ref
Whether a file conversion can be completed using this converter.

param: string $from The source type
param: string $to The destination type
return: bool

Class: core_file_converter_type_failed  - X-Ref

Test class for converter support with requirements met and failed conversion.

are_requirements_met()   X-Ref
Whether the plugin is configured and requirements are met.

return: bool

start_document_conversion(conversion $conversion)   X-Ref
Convert a document to a new format and return a conversion object relating to the conversion in progress.

param: conversion $conversion The file to be converted
return: conversion

supports($from, $to)   X-Ref
Whether a file conversion can be completed using this converter.

param: string $from The source type
param: string $to The destination type
return: bool