Skip to content

Commit

Permalink
MDL-63658 core_favourites: rename user_favourites_service and services
Browse files Browse the repository at this point in the history
Now: user_favourite_service (singular) and service_factory
  • Loading branch information
snake committed Oct 18, 2018
1 parent cb90b54 commit 0551ed3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Contains the user_favourites_service class, part of the service layer for the favourites subsystem.
* Contains the user_favourite_service class, part of the service layer for the favourites subsystem.
*
* @package core_favourites
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
Expand All @@ -37,7 +37,7 @@
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_favourites_service {
class user_favourite_service {

/** @var ifavourite_repository $repo the user favourites repository object. */
protected $repo;
Expand All @@ -46,7 +46,7 @@ class user_favourites_service {
protected $userid;

/**
* The user_favourites_service constructor.
* The user_favourite_service constructor.
*
* @param \context_user $usercontext The context of the user to which this service operations are scoped.
* @param \core_favourites\local\repository\ifavourite_repository $repository a user favourites repository.
Expand Down
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains the service locators for the favourites subsystem.
* Contains the service_factory, a locator for services for the favourites subsystem.
*
* Services encapsulate the business logic, and any data manipulation code, and are what clients should interact with.
*
Expand All @@ -27,23 +27,23 @@
defined('MOODLE_INTERNAL') || die();

/**
* Class services, providing functions for location of service objects for the favourites subsystem.
* Class service_factory, providing functions for location of service objects for the favourites subsystem.
*
* This class is responsible for providing service objects to clients only.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class services {
class service_factory {

/**
* Returns a basic service object providing operations for user favourites.
*
* @param \context_user $context the context of the user to which the service should be scoped.
* @return \core_favourites\local\service\user_favourites_service the service object.
* @return \core_favourites\local\service\user_favourite_service the service object.
*/
public static function get_service_for_user_context(\context_user $context) : local\service\user_favourites_service {
return new local\service\user_favourites_service($context, new local\repository\favourite_repository());
public static function get_service_for_user_context(\context_user $context) : local\service\user_favourite_service {
return new local\service\user_favourite_service($context, new local\repository\favourite_repository());
}
}

12 changes: 6 additions & 6 deletions favourites/tests/privacy_test.php
Expand Up @@ -62,8 +62,8 @@ public function test_add_contexts_for_userid() {
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users();

// Favourite 2 courses for user1 and 1 course for user2, all at the site context.
$ufservice1 = \core_favourites\services::get_service_for_user_context($user1context);
$ufservice2 = \core_favourites\services::get_service_for_user_context($user2context);
$ufservice1 = \core_favourites\service_factory::get_service_for_user_context($user1context);
$ufservice2 = \core_favourites\service_factory::get_service_for_user_context($user2context);
$systemcontext = context_system::instance();
$ufservice1->create_favourite('core_course', 'course', $course1context->instanceid, $systemcontext);
$ufservice1->create_favourite('core_course', 'course', $course2context->instanceid, $systemcontext);
Expand Down Expand Up @@ -94,8 +94,8 @@ public function test_delete_favourites_for_user() {
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users();

// Favourite 2 courses for user1 and 1 course for user2, all at the user context.
$ufservice1 = \core_favourites\services::get_service_for_user_context($user1context);
$ufservice2 = \core_favourites\services::get_service_for_user_context($user2context);
$ufservice1 = \core_favourites\service_factory::get_service_for_user_context($user1context);
$ufservice2 = \core_favourites\service_factory::get_service_for_user_context($user2context);
$ufservice1->create_favourite('core_course', 'course', $course1context->instanceid, $user1context);
$ufservice1->create_favourite('core_course', 'course', $course2context->instanceid, $user1context);
$ufservice2->create_favourite('core_course', 'course', $course2context->instanceid, $user2context);
Expand All @@ -115,8 +115,8 @@ public function test_delete_favourites_for_all_users() {
list($user1, $user2, $user1context, $user2context, $course1context, $course2context) = $this->set_up_courses_and_users();

// Favourite 2 course modules for user1 and 1 course module for user2 all in course 1 context.
$ufservice1 = \core_favourites\services::get_service_for_user_context($user1context);
$ufservice2 = \core_favourites\services::get_service_for_user_context($user2context);
$ufservice1 = \core_favourites\service_factory::get_service_for_user_context($user1context);
$ufservice2 = \core_favourites\service_factory::get_service_for_user_context($user2context);
$ufservice1->create_favourite('core_course', 'modules', 1, $course1context);
$ufservice1->create_favourite('core_course', 'modules', 2, $course1context);
$ufservice2->create_favourite('core_course', 'modules', 3, $course1context);
Expand Down
40 changes: 20 additions & 20 deletions favourites/tests/service_test.php
Expand Up @@ -26,12 +26,12 @@
defined('MOODLE_INTERNAL') || die();

/**
* Test class covering the user_favourites_service within the service layer of favourites.
* Test class covering the user_favourite_service within the service layer of favourites.
*
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_favourites_service_testcase extends advanced_testcase {
class user_favourite_service_testcase extends advanced_testcase {

public function setUp() {
$this->resetAfterTest();
Expand Down Expand Up @@ -140,12 +140,12 @@ protected function get_mock_repository(array $mockstore) {
}

/**
* Test getting a user_favourites_service from the static locator.
* Test getting a user_favourite_service from the static locator.
*/
public function test_get_service_for_user_context() {
list($user1context, $user2context, $course1context, $course2context) = $this->setup_users_and_courses();
$userservice = \core_favourites\services::get_service_for_user_context($user1context);
$this->assertInstanceOf(\core_favourites\local\service\user_favourites_service::class, $userservice);
$userservice = \core_favourites\service_factory::get_service_for_user_context($user1context);
$this->assertInstanceOf(\core_favourites\local\service\user_favourite_service::class, $userservice);
}

/**
Expand All @@ -154,9 +154,9 @@ public function test_get_service_for_user_context() {
public function test_create_favourite_basic() {
list($user1context, $user2context, $course1context, $course2context) = $this->setup_users_and_courses();

// Get a user_favourites_service for a user.
// Get a user_favourite_service for a user.
$repo = $this->get_mock_repository([]); // Mock repository, using the array as a mock DB.
$user1service = new \core_favourites\local\service\user_favourites_service($user1context, $repo);
$user1service = new \core_favourites\local\service\user_favourite_service($user1context, $repo);

// Favourite a course.
$favourite1 = $user1service->create_favourite('core_course', 'course', $course1context->instanceid, $course1context);
Expand All @@ -173,9 +173,9 @@ public function test_create_favourite_basic() {
public function test_create_favourite_nonexistent_component() {
list($user1context, $user2context, $course1context, $course2context) = $this->setup_users_and_courses();

// Get a user_favourites_service for the user.
// Get a user_favourite_service for the user.
$repo = $this->get_mock_repository([]); // Mock repository, using the array as a mock DB.
$user1service = new \core_favourites\local\service\user_favourites_service($user1context, $repo);
$user1service = new \core_favourites\local\service\user_favourite_service($user1context, $repo);

// Try to favourite something in a non-existent component.
$this->expectException('moodle_exception');
Expand All @@ -188,9 +188,9 @@ public function test_create_favourite_nonexistent_component() {
public function test_find_favourites_by_type_single_user() {
list($user1context, $user2context, $course1context, $course2context) = $this->setup_users_and_courses();

// Get a user_favourites_service for the user.
// Get a user_favourite_service for the user.
$repo = $this->get_mock_repository([]); // Mock repository, using the array as a mock DB.
$service = new \core_favourites\local\service\user_favourites_service($user1context, $repo);
$service = new \core_favourites\local\service\user_favourite_service($user1context, $repo);

// Favourite 2 courses, in separate areas.
$fav1 = $service->create_favourite('core_course', 'course', $course1context->instanceid, $course1context);
Expand All @@ -214,10 +214,10 @@ public function test_find_favourites_by_type_single_user() {
public function test_find_favourites_by_type_multiple_users() {
list($user1context, $user2context, $course1context, $course2context) = $this->setup_users_and_courses();

// Get a user_favourites_service for 2 users.
// Get a user_favourite_service for 2 users.
$repo = $this->get_mock_repository([]);
$user1service = new \core_favourites\local\service\user_favourites_service($user1context, $repo);
$user2service = new \core_favourites\local\service\user_favourites_service($user2context, $repo);
$user1service = new \core_favourites\local\service\user_favourite_service($user1context, $repo);
$user2service = new \core_favourites\local\service\user_favourite_service($user2context, $repo);

// Now, as each user, favourite the same course.
$fav1 = $user1service->create_favourite('core_course', 'course', $course1context->instanceid, $course1context);
Expand All @@ -241,9 +241,9 @@ public function test_find_favourites_by_type_multiple_users() {
public function test_find_favourites_by_type_nonexistent_component() {
list($user1context, $user2context, $course1context, $course2context) = $this->setup_users_and_courses();

// Get a user_favourites_service for the user.
// Get a user_favourite_service for the user.
$repo = $this->get_mock_repository([]);
$service = new \core_favourites\local\service\user_favourites_service($user1context, $repo);
$service = new \core_favourites\local\service\user_favourite_service($user1context, $repo);

// Verify we get an exception if we try to search for favourites in an invalid component.
$this->expectException('moodle_exception');
Expand All @@ -256,9 +256,9 @@ public function test_find_favourites_by_type_nonexistent_component() {
public function test_find_favourites_by_type_pagination() {
list($user1context, $user2context, $course1context, $course2context) = $this->setup_users_and_courses();

// Get a user_favourites_service for the user.
// Get a user_favourite_service for the user.
$repo = $this->get_mock_repository([]);
$service = new \core_favourites\local\service\user_favourites_service($user1context, $repo);
$service = new \core_favourites\local\service\user_favourite_service($user1context, $repo);

// Favourite 10 arbitrary items.
foreach (range(1, 10) as $i) {
Expand Down Expand Up @@ -287,9 +287,9 @@ public function test_find_favourites_by_type_pagination() {
public function test_delete_favourite_basic() {
list($user1context, $user2context, $course1context, $course2context) = $this->setup_users_and_courses();

// Get a user_favourites_service for the user.
// Get a user_favourite_service for the user.
$repo = $this->get_mock_repository([]);
$service = new \core_favourites\local\service\user_favourites_service($user1context, $repo);
$service = new \core_favourites\local\service\user_favourite_service($user1context, $repo);

// Favourite a course.
$fav1 = $service->create_favourite('core_course', 'course', $course1context->instanceid, $course1context);
Expand Down

0 comments on commit 0551ed3

Please sign in to comment.