diff --git a/controller/thankslist.php b/controller/thankslist.php index 0d417fb..cee2ac1 100644 --- a/controller/thankslist.php +++ b/controller/thankslist.php @@ -364,7 +364,8 @@ public function main($mode, $author_id, $give) $sort_key = $default_key; } - $order_by .= $sort_key_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC'); + // Additionally order by u.username_clean ASC for possible equal other values + $order_by .= $sort_key_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC') . (($sort_key != 'a') ? ', u.username_clean ASC' : ''); // Build a relevant pagination_url $params = []; diff --git a/tests/functional/controller_test.php b/tests/functional/controller_test.php index 9786b5a..de96350 100644 --- a/tests/functional/controller_test.php +++ b/tests/functional/controller_test.php @@ -21,6 +21,10 @@ public function test_thanklist() { $this->create_user('user1'); $this->add_user_group('ADMINISTRATORS', ['user1']); + + $this->create_user('user2'); + $this->remove_user_group('NEWLY_REGISTERED', ['user2']); + $this->login('user1'); // Create 2 posts for user1 @@ -34,26 +38,46 @@ public function test_thanklist() // Logout user1 $this->logout(); + + // Login as user2 + $this->login('user2'); + + // Create thanks for every user1's post from user2 + $crawler = self::request('GET', "viewtopic.php?f=2&t={$topic['topic_id']}&sid={$this->sid}"); + $thanks_link1 = str_replace('./', '', html_entity_decode($crawler->filter('#lnk_thanks_post' . ((int) $post['post_id'] - 1))->attr('href'))); + $thanks_link2 = str_replace('./', '', html_entity_decode($crawler->filter('#lnk_thanks_post' . $post['post_id'])->attr('href'))); + + // Create thanks for every user1's post from user2 + self::request('GET', $thanks_link1); + self::request('GET', $thanks_link2); + + // Logout user2 + $this->logout(); + // Login as admin $this->login(); - // Create a thank for every user1's post + // Create thanks for every user1's post from admin $crawler = self::request('GET', "viewtopic.php?f=2&t={$topic['topic_id']}&sid={$this->sid}"); $thanks_link1 = str_replace('./', '', html_entity_decode($crawler->filter('#lnk_thanks_post' . ((int) $post['post_id'] - 1))->attr('href'))); - self::request('GET', $thanks_link1); $thanks_link2 = str_replace('./', '', html_entity_decode($crawler->filter('#lnk_thanks_post' . $post['post_id'])->attr('href'))); + self::request('GET', $thanks_link1); self::request('GET', $thanks_link2); $this->add_lang_ext('gfksx/thanksforposts', 'thanks_mod'); // At this point: // admin has: received thanks - 1, given thanks - 2 - // user1 has: received thanks - 2, given thanks - 1 + // user1 has: received thanks - 4, given thanks - 1 + // user2 has: received thanks - 0, given thanks - 2 $crawler = self::request('GET', 'app.php/thankslist'); $this->assertStringContainsString($this->lang('THANKS_USER'), $crawler->filter('h2')->text()); - $this->assertStringContainsString('2 users', $crawler->filter('div[class="pagination"]')->text()); - $this->assertStringContainsString('user1', $crawler->filter('a[class="username"]')->text()); - $this->assertStringContainsString('admin', $crawler->filter('a[class="username-coloured"]')->text()); + $this->assertStringContainsString('3 users', $crawler->filter('div.pagination')->text()); + + // default sorting order is 'u.username_clean DESC' + $this->assertStringContainsString('user2', $crawler->filter('a.username')->eq(0)->text()); + $this->assertStringContainsString('user1', $crawler->filter('a.username')->eq(1)->text()); + $this->assertStringContainsString('admin', $crawler->filter('a.username-coloured')->text()); } public function test_thanklist_sorting() @@ -64,18 +88,21 @@ public function test_thanklist_sorting() // Default sorting: username desc $crawler = self::request('GET', 'app.php/thankslist'); - $this->assertStringContainsString('user1', $crawler->filter('tbody')->filter('tr')->eq(0)->filter('td > a')->text()); - $this->assertStringContainsString('admin', $crawler->filter('tbody')->filter('tr')->eq(1)->filter('td > a')->text()); + $this->assertStringContainsString('user2', $crawler->filter('tbody')->filter('tr')->eq(0)->filter('td > a')->text()); + $this->assertStringContainsString('user1', $crawler->filter('tbody')->filter('tr')->eq(1)->filter('td > a')->text()); + $this->assertStringContainsString('admin', $crawler->filter('tbody')->filter('tr')->eq(2)->filter('td > a')->text()); // Sorting by `Has thanked` desc $crawler = self::request('GET', 'app.php/thankslist?sk=f&sd=d'); $this->assertStringContainsString('admin', $crawler->filter('tbody')->filter('tr')->eq(0)->filter('td > a')->text()); - $this->assertStringContainsString('user1', $crawler->filter('tbody')->filter('tr')->eq(1)->filter('td > a')->text()); + $this->assertStringContainsString('user2', $crawler->filter('tbody')->filter('tr')->eq(1)->filter('td > a')->text()); + $this->assertStringContainsString('user1', $crawler->filter('tbody')->filter('tr')->eq(2)->filter('td > a')->text()); // Sorting by `Has thanked` asc $crawler = self::request('GET', 'app.php/thankslist?sk=f&sd=a'); $this->assertStringContainsString('user1', $crawler->filter('tbody')->filter('tr')->eq(0)->filter('td > a')->text()); $this->assertStringContainsString('admin', $crawler->filter('tbody')->filter('tr')->eq(1)->filter('td > a')->text()); + $this->assertStringContainsString('user2', $crawler->filter('tbody')->filter('tr')->eq(2)->filter('td > a')->text()); // Sorting by `Been thanked` desc $crawler = self::request('GET', 'app.php/thankslist?sk=e&sd=d'); diff --git a/tests/functional/thanking_test.php b/tests/functional/thanking_test.php index ac0a140..105ee70 100644 --- a/tests/functional/thanking_test.php +++ b/tests/functional/thanking_test.php @@ -37,7 +37,7 @@ public function test_toplist_on_index() $this->assertStringContainsString($this->lang('REPUT_TOPLIST', 5), $crawler->filter('div[class="stat-block thanks-list"] > h3')->text()); // From controller test: - // user1 has: received thanks - 2 + // user1 has: received thanks - 4 // admin has: received thanks - 1 $this->assertEquals('user1', $crawler->filter('div[class="stat-block thanks-list"] > p > a')->eq(0)->text()); $this->assertEquals('admin', $crawler->filter('div[class="stat-block thanks-list"] > p > a')->eq(1)->text()); @@ -47,15 +47,15 @@ public function test_profile_info() { $this->login(); - // Test if user profile info displayed + // Test if user1 profile info displayed $this->add_lang_ext('gfksx/thanksforposts', 'thanks_mod'); $crawler = self::request('GET', "memberlist.php?mode=viewprofile&un=user1"); $this->assertStringContainsString($this->lang('GRATITUDES'), $crawler->filter('div[class="panel bg1"] > div > h3')->text()); - $this->assertStringContainsString(html_entity_decode($this->lang('RECEIVED')) . ': 2 times', $crawler->filter('div[class="panel bg1"] > div > div[class="column2"] > dl > dt')->text()); + $this->assertStringContainsString(html_entity_decode($this->lang('RECEIVED')) . ': 4 times', $crawler->filter('div[class="panel bg1"] > div > div[class="column2"] > dl > dt')->text()); $this->assertStringContainsString($this->lang('THANKS_LIST'), $crawler->filter('div[class="panel bg1"] > div > div[class="column2"] > dl > dd > a')->text()); - $this->assertStringContainsString('./memberlist.php?mode=viewprofile&u=2', $crawler->filter('div[id="show_thanked"] > span > a')->attr('href')); - $this->assertStringContainsString('admin', $crawler->filter('div[id="show_thanked"] > span > a')->text()); + $this->assertStringContainsString('./memberlist.php?mode=viewprofile&u=59', $crawler->filter('div[id="show_thanked"] > span > a')->attr('href')); + $this->assertStringContainsString('user2', $crawler->filter('div[id="show_thanked"] > span > a')->text()); $this->assertStringContainsString($this->lang('FOR_MESSAGE'), $crawler->filter('div[id="show_thanked"] > span > a')->eq(1)->text()); }