Skip to content

Commit

Permalink
MDL-65130 privacy: Add @Covers annotation to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 21, 2019
1 parent 09d02b3 commit bc01342
Show file tree
Hide file tree
Showing 20 changed files with 342 additions and 1 deletion.
6 changes: 6 additions & 0 deletions privacy/tests/approved_contextlist_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\request\approved_contextlist
*/
class approved_contextlist_test extends advanced_testcase {

/**
* The approved contextlist should not be modifiable once set.
*
* @covers ::__construct
* @covers ::<!public>
* @covers \core_privacy\local\request\approved_contextlist<extended>
*/
public function test_default_values_set() {
$testuser = \core_user::get_user_by_username('admin');
Expand Down
10 changes: 10 additions & 0 deletions privacy/tests/approved_userlist_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\request\approved_userlist
*/
class approved_userlist_test extends advanced_testcase {
/**
* The approved userlist should not be modifiable once set.
*
* @covers ::__construct
* @covers \core_privacy\local\request\approved_userlist<extended>
* @covers ::<!public>
*/
public function test_default_values_set() {
$this->resetAfterTest();
Expand Down Expand Up @@ -68,6 +73,11 @@ public function test_default_values_set() {
$this->assertEquals($expected, $result);
}

/**
* @covers ::create_from_userlist
* @covers \core_privacy\local\request\approved_userlist<extended>
* @covers ::<!public>
*/
public function test_create_from_userlist() {
$this->resetAfterTest();

Expand Down
28 changes: 27 additions & 1 deletion privacy/tests/collection_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\metadata\collection
*/
class core_privacy_metadata_collection extends advanced_testcase {


/**
* Test that adding an unknown type causes the type to be added to the collection.
*
* @covers ::add_type
* @covers ::<!public>
*/
public function test_add_type_generic_type() {
$collection = new collection('core_privacy');
Expand All @@ -56,6 +59,9 @@ public function test_add_type_generic_type() {

/**
* Test that adding a known type works as anticipated.
*
* @covers ::add_type
* @covers ::<!public>
*/
public function test_add_type_known_type() {
$collection = new collection('core_privacy');
Expand All @@ -70,6 +76,9 @@ public function test_add_type_known_type() {

/**
* Test that adding multiple types returns them all.
*
* @covers ::add_type
* @covers ::<!public>
*/
public function test_add_type_multiple() {
$collection = new collection('core_privacy');
Expand All @@ -86,6 +95,9 @@ public function test_add_type_multiple() {

/**
* Test that the add_database_table function adds a database table.
*
* @covers ::add_database_table
* @covers ::<!public>
*/
public function test_add_database_table() {
$collection = new collection('core_privacy');
Expand All @@ -107,6 +119,9 @@ public function test_add_database_table() {

/**
* Test that the add_user_preference function adds a single user preference.
*
* @covers ::add_user_preference
* @covers ::<!public>
*/
public function test_add_user_preference() {
$collection = new collection('core_privacy');
Expand All @@ -126,6 +141,9 @@ public function test_add_user_preference() {

/**
* Test that the link_external_location function links an external location.
*
* @covers ::link_external_location
* @covers ::<!public>
*/
public function test_link_external_location() {
$collection = new collection('core_privacy');
Expand All @@ -147,6 +165,9 @@ public function test_link_external_location() {

/**
* Test that the link_subsystem function links the subsystem.
*
* @covers ::link_subsystem
* @covers ::<!public>
*/
public function test_link_subsystem() {
$collection = new collection('core_privacy');
Expand All @@ -166,6 +187,9 @@ public function test_link_subsystem() {

/**
* Test that the link_plugintype function links the plugin.
*
* @covers ::link_plugintype
* @covers ::<!public>
*/
public function test_link_plugintype() {
$collection = new collection('core_privacy');
Expand Down Expand Up @@ -202,6 +226,8 @@ public function component_list_provider() {
*
* @dataProvider component_list_provider
* @param string $component The component to test
* @covers ::get_component
* @covers ::<!public>
*/
public function test_get_component($component) {
$collection = new collection($component);
Expand Down
27 changes: 27 additions & 0 deletions privacy/tests/contextlist_base_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\request\contextlist_base
*/
class contextlist_base_test extends advanced_testcase {
/**
Expand All @@ -43,6 +44,8 @@ class contextlist_base_test extends advanced_testcase {
* @param array $input List of context IDs
* @param array $expected list of contextids
* @param int $count Expected count
* @covers ::get_contextids
* @covers ::<!public>
*/
public function test_get_contextids($input, $expected, $count) {
$uit = new test_contextlist_base();
Expand Down Expand Up @@ -84,6 +87,9 @@ public function get_contextids_provider() {

/**
* Ensure that get_contexts returns the correct list of contexts.
*
* @covers ::get_contexts
* @covers ::<!public>
*/
public function test_get_contexts() {
global $DB;
Expand Down Expand Up @@ -114,6 +120,8 @@ public function test_get_contexts() {
* @param array $input List of context IDs
* @param array $expected list of contextids
* @param int $count Expected count
* @covers ::count
* @covers ::<!public>
*/
public function test_countable($input, $expected, $count) {
$uit = new test_contextlist_base();
Expand All @@ -124,6 +132,13 @@ public function test_countable($input, $expected, $count) {

/**
* Ensure that the contextlist_base iterates over the set of contexts.
*
* @covers ::current
* @covers ::key
* @covers ::next
* @covers ::rewind
* @covers ::valid
* @covers ::<!public>
*/
public function test_context_iteration() {
global $DB;
Expand All @@ -144,6 +159,9 @@ public function test_context_iteration() {

/**
* Test that deleting a context results in current returning nothing.
*
* @covers ::current
* @covers ::<!public>
*/
public function test_current_context_one_context() {
global $DB;
Expand Down Expand Up @@ -171,6 +189,9 @@ public function test_current_context_one_context() {

/**
* Test that deleting a context results in the next record being returned.
*
* @covers ::current
* @covers ::<!public>
*/
public function test_current_context_two_contexts() {
global $DB;
Expand Down Expand Up @@ -206,6 +227,9 @@ public function test_current_context_two_contexts() {

/**
* Test that if there are no non-deleted contexts that nothing is returned.
*
* @covers ::get_contexts
* @covers ::<!public>
*/
public function test_get_contexts_all_deleted() {
global $DB;
Expand All @@ -231,6 +255,9 @@ public function test_get_contexts_all_deleted() {

/**
* Test that get_contexts() returns only active contexts.
*
* @covers ::get_contexts
* @covers ::<!public>
*/
public function test_get_contexts_one_deleted() {
global $DB;
Expand Down
29 changes: 29 additions & 0 deletions privacy/tests/contextlist_collection_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\request\contextlist_collection
*/
class contextlist_collection_test extends advanced_testcase {
/**
* A contextlist_collection should support the contextlist type.
*
* @covers ::add_contextlist
* @covers ::<!public>
*/
public function test_supports_contextlist() {
$uit = new contextlist_collection(1);
Expand All @@ -52,6 +56,9 @@ public function test_supports_contextlist() {

/**
* A contextlist_collection should support the approved_contextlist type.
*
* @covers ::add_contextlist
* @covers ::<!public>
*/
public function test_supports_approved_contextlist() {
$uit = new contextlist_collection(1);
Expand All @@ -64,6 +71,9 @@ public function test_supports_approved_contextlist() {

/**
* Ensure that get_contextlist_for_component returns the correct contextlist.
*
* @covers ::get_contextlist_for_component
* @covers ::<!public>
*/
public function test_get_contextlist_for_component() {
$uit = new contextlist_collection(1);
Expand All @@ -83,6 +93,9 @@ public function test_get_contextlist_for_component() {

/**
* Ensure that get_contextlist_for_component does not die horribly when querying a non-existent component.
*
* @covers ::get_contextlist_for_component
* @covers ::<!public>
*/
public function test_get_contextlist_for_component_not_found() {
$uit = new contextlist_collection(1);
Expand All @@ -92,6 +105,9 @@ public function test_get_contextlist_for_component_not_found() {

/**
* Ensure that a duplicate contextlist in the collection throws an Exception.
*
* @covers ::add_contextlist
* @covers ::<!public>
*/
public function test_duplicate_addition_throws() {
$uit = new contextlist_collection(1);
Expand All @@ -106,6 +122,9 @@ public function test_duplicate_addition_throws() {

/**
* Ensure that the contextlist_collection is countable.
*
* @covers ::count
* @covers ::<!public>
*/
public function test_countable() {
$uit = new contextlist_collection(1);
Expand All @@ -123,6 +142,13 @@ public function test_countable() {

/**
* Ensure that the contextlist_collection iterates over the set of contextlists.
*
* @covers ::current
* @covers ::key
* @covers ::next
* @covers ::rewind
* @covers ::valid
* @covers ::<!public>
*/
public function test_iteration() {
$uit = new contextlist_collection(1);
Expand Down Expand Up @@ -156,6 +182,9 @@ public function test_iteration() {

/**
* Test that the userid is correctly returned.
*
* @covers ::get_userid
* @covers ::<!public>
*/
public function test_get_userid() {
$uit = new contextlist_collection(1);
Expand Down
15 changes: 15 additions & 0 deletions privacy/tests/contextlist_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \core_privacy\local\request\contextlist
*/
class contextlist_test extends advanced_testcase {

/**
* Ensure that valid SQL results in the relevant contexts being added.
*
* @covers ::add_from_sql
* @covers ::<!public>
*/
public function test_add_from_sql() {
global $DB;
Expand All @@ -55,6 +59,9 @@ public function test_add_from_sql() {

/**
* Ensure that valid system context id is added.
*
* @covers ::add_system_context
* @covers ::<!public>
*/
public function test_add_system_context() {
$cl = new contextlist();
Expand All @@ -69,6 +76,9 @@ public function test_add_system_context() {

/**
* Ensure that a valid user context id is added.
*
* @covers ::add_user_context
* @covers ::<!public>
*/
public function test_add_user_context() {
$this->resetAfterTest();
Expand All @@ -88,6 +98,9 @@ public function test_add_user_context() {

/**
* Ensure that valid user contexts are added.
*
* @covers ::add_user_contexts
* @covers ::<!public>
*/
public function test_add_user_contexts() {
$this->resetAfterTest();
Expand All @@ -112,6 +125,8 @@ public function test_add_user_contexts() {
* @dataProvider data_guess_id_field_from_sql
* @param string $sql Input SQL we try to extract the context id field name from.
* @param string $expected Expected detected value.
* @covers ::guess_id_field_from_sql
* @covers ::<!public>
*/
public function test_guess_id_field_from_sql($sql, $expected) {

Expand Down
Loading

0 comments on commit bc01342

Please sign in to comment.