Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
core_privacy\tests\request\content_writer Class Reference

An implementation of the content_writer for use in unit tests. More...

Inheritance diagram for core_privacy\tests\request\content_writer:
core_privacy\local\request\content_writer

Public Member Functions

 __construct (\core_privacy\local\request\writer $writer)
 Constructor for the content writer. More...
 
 export_area_files (array $subcontext, $component, $filearea, $itemid)
 Export all files within the specified component, filearea, itemid combination. More...
 
 export_custom_file (array $subcontext, $filename, $filecontent)
 Export a piece of data in a custom format. More...
 
 export_data (array $subcontext, stdClass $data)
 Export the supplied data within the current context, at the supplied subcontext. More...
 
 export_file (array $subcontext, stored_file $file)
 Export the specified file in the target location. More...
 
 export_metadata (array $subcontext, string $key, $value, string $description)
 Export metadata about the supplied subcontext. More...
 
 export_related_data (array $subcontext, $name, $data)
 Export a piece of related data. More...
 
 export_user_preference (string $component, string $key, string $value, string $description)
 Export the specified user preference. More...
 
 finalise_content ()
 Perform any required finalisation steps and return the location of the finalised export. More...
 
 get_all_metadata (array $subcontext=[])
 Get all metadata within the subcontext. More...
 
 get_current_context ()
 Return the current context. More...
 
 get_custom_file (array $subcontext=[], $filename=null)
 Get the specified custom file within the subcontext. More...
 
 get_data (array $subcontext=[])
 Get all data within the subcontext. More...
 
 get_files (array $subcontext=[])
 Get all files in the specfied subcontext. More...
 
 get_metadata (array $subcontext=[], $key, $valueonly=true)
 Get the specified metadata within the subcontext. More...
 
 get_related_data (array $subcontext=[], $filename=null)
 Get all data within the subcontext. More...
 
 get_user_context_preferences (string $component)
 Get all user preferences for the specified component. More...
 
 get_user_preferences (string $component)
 Get all user preferences for the specified component. More...
 
 has_any_data ($subcontext=[])
 Whether any data has been exported at all within the current context. More...
 
 has_any_data_in_any_context ()
 Whether any data has been exported for any context. More...
 
 rewrite_pluginfile_urls (array $subcontext, $component, $filearea, $itemid, $text)
 Prepare a text area by processing pluginfile URLs within it. More...
 
 set_context (\context $context)
 Set the context for the current item being processed. More...
 

Protected Member Functions

 fetch_data_root ($base, $subcontext)
 Fetch the data region of the specified root. More...
 
 fetch_root ($base, $subcontext, $temporarycontextid=null)
 Fetch the entire root record at the specified location type, creating it if required. More...
 

Protected Attributes

context $context
 The context currently being exported.
 
stdClass $customfiles
 The custom files which have been exported.
 
stdClass $data
 The data which has been exported.
 
stdClass $files
 The list of stored files which have been exported.
 
stdClass $metadata
 The collection of metadata which has been exported.
 
stdClass $relateddata
 The related data which has been exported.
 
stdClass $userprefs
 The user preferences which have been exported.
 

Detailed Description

An implementation of the content_writer for use in unit tests.

This implementation does not export any data but instead stores it in structures within the instance which can be easily queried for use during unit tests.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core_privacy\tests\request\content_writer::__construct ( \core_privacy\local\request\writer  $writer)

Constructor for the content writer.

Note: The writer_factory must be passed.

Parameters
core_privacy\local\request\writer$writerThe writer factory.

Member Function Documentation

◆ export_area_files()

core_privacy\tests\request\content_writer::export_area_files ( array  $subcontext,
  $component,
  $filearea,
  $itemid 
)

Export all files within the specified component, filearea, itemid combination.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$componentThe name of the component that the files belong to.
string$fileareaThe filearea within that component.
string$itemidWhich item those files belong to.

Implements core_privacy\local\request\content_writer.

◆ export_custom_file()

core_privacy\tests\request\content_writer::export_custom_file ( array  $subcontext,
  $filename,
  $filecontent 
)

Export a piece of data in a custom format.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$filenameThe name of the file to be exported.
string$filecontentThe content to be exported.

Implements core_privacy\local\request\content_writer.

◆ export_data()

core_privacy\tests\request\content_writer::export_data ( array  $subcontext,
stdClass  $data 
)

Export the supplied data within the current context, at the supplied subcontext.

Parameters
array$subcontextThe location within the current context that this data belongs.
stdClass$dataThe data to be exported

Implements core_privacy\local\request\content_writer.

◆ export_file()

core_privacy\tests\request\content_writer::export_file ( array  $subcontext,
stored_file  $file 
)

Export the specified file in the target location.

Parameters
array$subcontextThe location within the current context that this data belongs.
stored_file$fileThe file to be exported.

Implements core_privacy\local\request\content_writer.

◆ export_metadata()

core_privacy\tests\request\content_writer::export_metadata ( array  $subcontext,
string  $key,
  $value,
string  $description 
)

Export metadata about the supplied subcontext.

Metadata consists of a key/value pair and a description of the value.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$keyThe metadata name.
string$valueThe metadata value.
string$descriptionThe description of the value.
Return values
$this

Implements core_privacy\local\request\content_writer.

◆ export_related_data()

core_privacy\tests\request\content_writer::export_related_data ( array  $subcontext,
  $name,
  $data 
)

Export a piece of related data.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$nameThe name of the file to be exported.
stdClass$dataThe related data to export.

Implements core_privacy\local\request\content_writer.

◆ export_user_preference()

core_privacy\tests\request\content_writer::export_user_preference ( string  $component,
string  $key,
string  $value,
string  $description 
)

Export the specified user preference.

Parameters
string$componentThe name of the component.
string$keyThe name of th key to be exported.
string$valueThe value of the preference
string$descriptionA description of the value
Return values
core_privacy

Implements core_privacy\local\request\content_writer.

◆ fetch_data_root()

core_privacy\tests\request\content_writer::fetch_data_root (   $base,
  $subcontext 
)
protected

Fetch the data region of the specified root.

Parameters
stdClass$baseThe base to use - e.g. $this->data
array$subcontextThe subcontext to fetch
Return values
array

◆ fetch_root()

core_privacy\tests\request\content_writer::fetch_root (   $base,
  $subcontext,
  $temporarycontextid = null 
)
protected

Fetch the entire root record at the specified location type, creating it if required.

Parameters
stdClass$baseThe base to use - e.g. $this->data
array$subcontextThe subcontext to fetch
int$temporarycontextidA temporary context ID to use for the fetch.
Return values
array

◆ finalise_content()

core_privacy\tests\request\content_writer::finalise_content ( )

Perform any required finalisation steps and return the location of the finalised export.

Return values
string

Implements core_privacy\local\request\content_writer.

◆ get_all_metadata()

core_privacy\tests\request\content_writer::get_all_metadata ( array  $subcontext = [])

Get all metadata within the subcontext.

Parameters
array$subcontextThe location within the current context that this data belongs.
Return values
arrayThe metadata as a series of keys to value + descrition objects.

◆ get_current_context()

core_privacy\tests\request\content_writer::get_current_context ( )

Return the current context.

Return values
context

◆ get_custom_file()

core_privacy\tests\request\content_writer::get_custom_file ( array  $subcontext = [],
  $filename = null 
)

Get the specified custom file within the subcontext.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$filenameThe name of the file to be fetched within the context + subcontext.
Return values
stringThe content of the file.

◆ get_data()

core_privacy\tests\request\content_writer::get_data ( array  $subcontext = [])

Get all data within the subcontext.

Parameters
array$subcontextThe location within the current context that this data belongs.
Return values
arrayThe metadata as a series of keys to value + descrition objects.

◆ get_files()

core_privacy\tests\request\content_writer::get_files ( array  $subcontext = [])

Get all files in the specfied subcontext.

Parameters
array$subcontextThe location within the current context that this data belongs.
Return values
stored_file[]The list of stored_files in this context + subcontext.

◆ get_metadata()

core_privacy\tests\request\content_writer::get_metadata ( array  $subcontext = [],
  $key,
  $valueonly = true 
)

Get the specified metadata within the subcontext.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$keyThe metadata to be fetched within the context + subcontext.
boolean$valueonlyWhether to fetch only the value, rather than the value + description.
Return values
arrayThe metadata as a series of keys to value + descrition objects.

◆ get_related_data()

core_privacy\tests\request\content_writer::get_related_data ( array  $subcontext = [],
  $filename = null 
)

Get all data within the subcontext.

Parameters
array$subcontextThe location within the current context that this data belongs.
string$filenameThe name of the intended filename.
Return values
arrayThe metadata as a series of keys to value + descrition objects.

◆ get_user_context_preferences()

core_privacy\tests\request\content_writer::get_user_context_preferences ( string  $component)

Get all user preferences for the specified component.

Parameters
string$componentThe name of the component.
Return values
stdClass

◆ get_user_preferences()

core_privacy\tests\request\content_writer::get_user_preferences ( string  $component)

Get all user preferences for the specified component.

Parameters
string$componentThe name of the component.
Return values
stdClass

◆ has_any_data()

core_privacy\tests\request\content_writer::has_any_data (   $subcontext = [])

Whether any data has been exported at all within the current context.

Parameters
array$subcontextThe location within the current context that this data belongs - in this method it can be partial subcontext path (or none at all to check presence of any data anywhere). User preferences never have subcontext, if $subcontext is specified, user preferences are not checked.
Return values
bool

◆ has_any_data_in_any_context()

core_privacy\tests\request\content_writer::has_any_data_in_any_context ( )

Whether any data has been exported for any context.

Return values
bool

◆ rewrite_pluginfile_urls()

core_privacy\tests\request\content_writer::rewrite_pluginfile_urls ( array  $subcontext,
  $component,
  $filearea,
  $itemid,
  $text 
)

Prepare a text area by processing pluginfile URLs within it.

Note that this method does not implement the pluginfile URL rewriting. Such a job tightly depends on how the actual writer exports files so it can be reliably tested only in real writers such as core_privacy\local\request\moodle_content_writer.

However we have to remove @PLUGINFILE@ since otherwise format_text() shows debugging messages

Parameters
array$subcontextThe location within the current context that this data belongs.
string$componentThe name of the component that the files belong to.
string$fileareaThe filearea within that component.
string$itemidWhich item those files belong to.
string$textThe text to be processed
Return values
stringThe processed string

Implements core_privacy\local\request\content_writer.

◆ set_context()

core_privacy\tests\request\content_writer::set_context ( \context  $context)

Set the context for the current item being processed.

Parameters
context$contextThe context to use

Implements core_privacy\local\request\content_writer.


The documentation for this class was generated from the following file: