Skip to content

Commit

Permalink
Merge branch 'MDL-64993-master' of git://github.com/aanabit/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols authored and abgreeve committed May 7, 2019
2 parents 606ac9b + c8d51ae commit 9862955
Show file tree
Hide file tree
Showing 13 changed files with 610 additions and 302 deletions.
62 changes: 31 additions & 31 deletions favourites/tests/repository_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ public function test_find_all() {

$favouritesrepo = new favourite_repository($user1context);

// Verify that for an empty repository, find_all returns an empty array.
$this->assertEquals([], $favouritesrepo->find_all());
// Verify that only two self-conversations are found.
$this->assertCount(2, $favouritesrepo->find_all());

// Save a favourite for 2 courses, in different areas.
$favourite = new favourite(
Expand All @@ -233,9 +233,9 @@ public function test_find_all() {
$favouritesrepo->add($favourite);
$favouritesrepo->add($favourite2);

// Verify that find_all returns both of our favourites.
// Verify that find_all returns both of our favourites + two self-conversations.
$favourites = $favouritesrepo->find_all();
$this->assertCount(2, $favourites);
$this->assertCount(4, $favourites);
foreach ($favourites as $fav) {
$this->assertInstanceOf(favourite::class, $fav);
$this->assertObjectHasAttribute('id', $fav);
Expand All @@ -251,11 +251,11 @@ public function test_find_all_pagination() {

$favouritesrepo = new favourite_repository($user1context);

// Verify that for an empty repository, find_all with any combination of page options returns an empty array.
$this->assertEquals([], $favouritesrepo->find_all(0, 0));
$this->assertEquals([], $favouritesrepo->find_all(0, 10));
$this->assertEquals([], $favouritesrepo->find_all(1, 0));
$this->assertEquals([], $favouritesrepo->find_all(1, 10));
// Verify that for an empty repository, find_all with any combination of page options returns only self-conversations.
$this->assertCount(2, $favouritesrepo->find_all(0, 0));
$this->assertCount(2, $favouritesrepo->find_all(0, 10));
$this->assertCount(1, $favouritesrepo->find_all(1, 0));
$this->assertCount(1, $favouritesrepo->find_all(1, 10));

// Save 10 arbitrary favourites to the repo.
foreach (range(1, 10) as $i) {
Expand All @@ -269,19 +269,19 @@ public function test_find_all_pagination() {
$favouritesrepo->add($favourite);
}

// Verify we have 10 favourites.
$this->assertEquals(10, $favouritesrepo->count());
// Verify we have 10 favourites + 2 self-conversations.
$this->assertEquals(12, $favouritesrepo->count());

// Verify we can fetch the first page of 5 records.
$favourites = $favouritesrepo->find_all(0, 5);
$this->assertCount(5, $favourites);
// Verify we can fetch the first page of 5 records+ 2 self-conversations.
$favourites = $favouritesrepo->find_all(0, 6);
$this->assertCount(6, $favourites);

// Verify we can fetch the second page.
$favourites = $favouritesrepo->find_all(5, 5);
$this->assertCount(5, $favourites);
$favourites = $favouritesrepo->find_all(6, 6);
$this->assertCount(6, $favourites);

// Verify the third page request ends with an empty array.
$favourites = $favouritesrepo->find_all(10, 5);
$favourites = $favouritesrepo->find_all(12, 6);
$this->assertCount(0, $favourites);
}

Expand Down Expand Up @@ -321,11 +321,11 @@ public function test_find_by_pagination() {

$favouritesrepo = new favourite_repository($user1context);

// Verify that for an empty repository, find_all with any combination of page options returns an empty array.
$this->assertEquals([], $favouritesrepo->find_by([], 0, 0));
$this->assertEquals([], $favouritesrepo->find_by([], 0, 10));
$this->assertEquals([], $favouritesrepo->find_by([], 1, 0));
$this->assertEquals([], $favouritesrepo->find_by([], 1, 10));
// Verify that by default, find_all with any combination of page options returns only self-conversations.
$this->assertCount(2, $favouritesrepo->find_by([], 0, 0));
$this->assertCount(2, $favouritesrepo->find_by([], 0, 10));
$this->assertCount(1, $favouritesrepo->find_by([], 1, 0));
$this->assertCount(1, $favouritesrepo->find_by([], 1, 10));

// Save 10 arbitrary favourites to the repo.
foreach (range(1, 10) as $i) {
Expand All @@ -339,12 +339,12 @@ public function test_find_by_pagination() {
$favouritesrepo->add($favourite);
}

// Verify we have 10 favourites.
$this->assertEquals(10, $favouritesrepo->count());
// Verify we have 10 favourites + 2 self-conversations.
$this->assertEquals(12, $favouritesrepo->count());

// Verify a request for a page, when no criteria match, results in an empty array.
// Verify a request for a page, when no criteria match, results in 2 self-conversations array.
$favourites = $favouritesrepo->find_by(['component' => 'core_message'], 0, 5);
$this->assertCount(0, $favourites);
$this->assertCount(2, $favourites);

// Verify we can fetch a the first page of 5 records.
$favourites = $favouritesrepo->find_by(['component' => 'core_course'], 0, 5);
Expand Down Expand Up @@ -546,8 +546,8 @@ public function test_delete_by() {
$favourite1 = $favouritesrepo->add($favourite);
$favourite2 = $favouritesrepo->add($favourite2);

// Verify we have 2 items in the repo.
$this->assertEquals(2, $favouritesrepo->count());
// Verify we have 2 items in the repo + 2 self-conversations.
$this->assertEquals(4, $favouritesrepo->count());

// Try to delete by a non-existent area, and confirm it doesn't remove anything.
$favouritesrepo->delete_by(
Expand All @@ -557,7 +557,7 @@ public function test_delete_by() {
'itemtype' => 'donaldduck'
]
);
$this->assertEquals(2, $favouritesrepo->count());
$this->assertEquals(4, $favouritesrepo->count());

// Try to delete by a non-existent area, and confirm it doesn't remove anything.
$favouritesrepo->delete_by(
Expand All @@ -567,7 +567,7 @@ public function test_delete_by() {
'itemtype' => 'cat'
]
);
$this->assertEquals(2, $favouritesrepo->count());
$this->assertEquals(4, $favouritesrepo->count());

// Delete by area, and confirm we have one record left, from the 'core_course/anothertype' area.
$favouritesrepo->delete_by(
Expand All @@ -577,7 +577,7 @@ public function test_delete_by() {
'itemtype' => 'course'
]
);
$this->assertEquals(1, $favouritesrepo->count());
$this->assertEquals(3, $favouritesrepo->count());
$this->assertFalse($favouritesrepo->exists($favourite1->id));
$this->assertTrue($favouritesrepo->exists($favourite2->id));
}
Expand Down
11 changes: 7 additions & 4 deletions group/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,15 @@ public function test_get_contexts_for_userid() {
$coursecontext1 = context_course::instance($course1->id);
$coursecontext2 = context_course::instance($course2->id);

// User1 is member of some groups in course1 and course2.
// User1 is member of some groups in course1 and course2 + self-conversation.
$contextlist = provider::get_contexts_for_userid($user1->id);
$this->assertCount(2, $contextlist);
$contextids = $contextlist->get_contextids();
// First user context is the one related to self-conversation. Let's test group contexts.
array_pop($contextids);
$this->assertCount(3, $contextlist);
$this->assertEquals(
[$coursecontext1->id, $coursecontext2->id],
$contextlist->get_contextids(),
$contextids,
'', 0.0, 10, true);
}

Expand Down Expand Up @@ -757,7 +760,7 @@ public function test_get_contexts_for_userid_component() {
// User is member of some groups in course1 and course2,
// but only the membership in course1 is directly managed by core_group.
$contextlist = provider::get_contexts_for_userid($user->id);
$this->assertEquals([$coursecontext1->id], $contextlist->get_contextids());
$this->assertEquals($coursecontext1->id, $contextlist->get_contextids()[0]);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion lib/behat/classes/partial_named_selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function __construct() {
'table_row' => 'table_row',
'xpath_element' => 'xpath_element',
'form_row' => 'form_row',
'group_message_header' => 'group_message_header',
);

/**
Expand All @@ -93,6 +94,7 @@ public function __construct() {
'group_message_header' => 'group_message_header',
'group_message_member' => 'group_message_member',
'group_message_tab' => 'group_message_tab',
'group_message_list_area' => 'group_message_list_area',
'icon' => 'icon',
'link' => 'link',
'link_or_button' => 'link_or_button',
Expand Down Expand Up @@ -159,7 +161,7 @@ public function __construct() {
.//*[@data-region='message-drawer' and contains(., %locator%)]//div[@data-region='content-message-container']
XPATH
, 'group_message_header' => <<<XPATH
.//*[@data-region='message-drawer']//div[@data-region='header-container']//*[text()[contains(., %locator%)]]
.//*[@data-region='message-drawer']//div[@data-region='header-container' and contains(., %locator%)]
XPATH
, 'group_message_member' => <<<XPATH
.//*[@data-region='message-drawer']//div[@data-region='group-info-content-container']
Expand All @@ -169,6 +171,9 @@ public function __construct() {
XPATH
, 'group_message_tab' => <<<XPATH
.//*[@data-region='message-drawer']//button[@data-toggle='collapse' and contains(string(), %locator%)]
XPATH
, 'group_message_list_area' => <<<XPATH
.//*[@data-region='message-drawer']//*[contains(@data-region, concat('view-overview-', %locator%))]
XPATH
, 'icon' => <<<XPATH
.//*[contains(concat(' ', normalize-space(@class), ' '), ' icon ') and ( contains(normalize-space(@title), %locator%))]
Expand Down
7 changes: 7 additions & 0 deletions lib/testing/generator/data_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ public function create_user($record=null, array $options=null) {

if (!$record['deleted']) {
context_user::instance($userid);

// All new not deleted users must have a favourite self-conversation.
$selfconversation = \core_message\api::create_conversation(
\core_message\api::MESSAGE_CONVERSATION_TYPE_SELF,
[$userid]
);
\core_message\api::set_favourite_conversation($selfconversation->id, $userid);
}

$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
Expand Down
Loading

0 comments on commit 9862955

Please sign in to comment.