Skip to content

Commit

Permalink
Add user profile test
Browse files Browse the repository at this point in the history
  • Loading branch information
rxu committed Apr 30, 2020
1 parent 156bc3d commit c85b87c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
/**
* @group functional
*/
class thanks_acp_test extends \phpbb_functional_test_case
class acp_test extends \phpbb_functional_test_case
{
static protected function setup_extensions()
{
return array('gfksx/thanksforposts');
}

public function test_update_counters_module()
{
$this->login();
Expand All @@ -30,8 +35,8 @@ public function test_update_counters_module()

$form = $crawler->selectButton('Yes')->form();
$crawler = self::submit($form);
$this->assertContains('Notification', $crawler->filter('div[class="successbox"] > h3')->text());
$this->assertContains('Counters updated', $crawler->filter('div[class="successbox"] > p')->text());
$this->assertContains($this->lang('NOTIFY'), $crawler->filter('div[class="successbox"] > h3')->text());
$this->assertContains($this->lang('THANKS_REFRESHED_MSG'), $crawler->filter('div[class="successbox"] > p')->text());
}

public function test_clear_list_of_thanks_module()
Expand All @@ -40,16 +45,16 @@ public function test_clear_list_of_thanks_module()
$this->admin_login();

$crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=-gfksx-thanksforposts-acp-acp_thanks_truncate_module&mode=thanks");
$this->assertContains('Warning', $crawler->filter('div[class="errorbox"] > h3')->text());
$this->assertContains('This procedure completely clears all thanks counters (removes all issued thanks)', $crawler->filter('div[class="errorbox"] > p')->text());
$this->assertContains($this->lang('WARNING'), $crawler->filter('div[class="errorbox"] > h3')->text());
$this->assertContains($this->lang('TRUNCATE_THANKS_EXPLAIN'), $crawler->filter('div[class="errorbox"] > p')->text());

$form = $crawler->selectButton('Clear')->form();
$crawler = self::submit($form);
$this->assertContains('Clear the list of thanks', $crawler->filter('fieldset > h1')->text());
$this->assertContains($this->lang('ACP_THANKS_TRUNCATE'), $crawler->filter('fieldset > h1')->text());

$form = $crawler->selectButton('Yes')->form();
$crawler = self::submit($form);
$this->assertContains('Notification', $crawler->filter('div[class="successbox"] > h3')->text());
$this->assertContains('Thanks counters cleared.', $crawler->filter('div[class="successbox"] > p')->text());
$this->assertContains($this->lang('NOTIFY'), $crawler->filter('div[class="successbox"] > h3')->text());
$this->assertContains($this->lang('TRUNCATE_THANKS_MSG'), $crawler->filter('div[class="successbox"] > p')->text());
}
}
5 changes: 0 additions & 5 deletions tests/functional/controller_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
*/
class controller_test extends \phpbb_functional_test_case
{
static protected function setup_extensions()
{
return array('gfksx/thanksforposts');
}

public function test_thanklist()
{
$this->create_user('user1');
Expand Down
45 changes: 38 additions & 7 deletions tests/functional/thanking_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,71 @@ public function test_toplist_on_index()
$this->assertContains($this->lang('CONFIG_UPDATED'), $crawler->filter('.successbox')->text());

// Now test toplist on index exists
$this->add_lang_ext('gfksx/thanksforposts', 'thanks_mod');
$crawler = self::request('GET', "index.php?sid={$this->sid}");
$this->assertContains('Thanks Toplist — 5', $crawler->filter('div[class="stat-block thanks-list"]')->text());
$this->assertContains($this->lang('REPUT_TOPLIST', 5), $crawler->filter('div[class="stat-block thanks-list"]')->text());
}

public function test_thanking()
public function test_profile_info()
{
$this->login('user1');

$this->get_db();
$sql = 'SELECT post_id, topic_id FROM ' . POSTS_TABLE . '
WHERE poster_id = 2
ORDER BY post_id DESC LIMIT 1';
$result = $this->db->sql_query($sql);
$post = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);

// Create a thank for the admin post
$crawler = self::request('GET', "viewtopic.php?f=2&t={$post['topic_id']}&sid={$this->sid}&p={$post['post_id']}#p{$post['post_id']}");
$thanks_link = str_replace('./', '', html_entity_decode($crawler->filter('#lnk_thanks_post' . $post['post_id'])->attr('href')));
$crawler = self::request('GET', $thanks_link);

// Test if user profile info displayed
$this->add_lang_ext('gfksx/thanksforposts', 'thanks_mod');
$crawler = self::request('GET', "memberlist.php?mode=viewprofile&un=user1");

$this->assertContains($this->lang('GRATITUDES'), $crawler->filter('div[class="panel bg1"] > div > h3')->text());
$this->assertContains($this->lang('RECEIVED') . ': 1 time', $crawler->filter('div[class="panel bg1"] > div > div[class="column2"] > dl > dt')->text());
$this->assertContains($this->lang('THANKS_LIST'), $crawler->filter('div[class="panel bg1"] > div > div[class="column2"] > dl > dd > a')->text());
$this->assertContains('./memberlist.php?mode=viewprofile&u=2', $crawler->filter('div[id="show_thanked"] > span > a')->attr('href'));
$this->assertContains('admin', $crawler->filter('div[id="show_thanked"] > span > a')->text());
$this->assertContains($this->lang('FOR_MESSAGE'), $crawler->filter('div[id="show_thanked"] > span > a')->eq(1)->text());
}

public function test_remove_thank()
{
// user1 account, its post and a thank should have been created in controller_test.php

$this->login();

$this->get_db();
$sql = 'SELECT post_id, topic_id FROM ' . POSTS_TABLE . '
ORDER BY post_id DESC LIMIT 1';
$result = $this->db->sql_query($sql);
$post = $this->db->sql_fetchrow($result);
$this->db->sql_freeresult($result);

// Now test thanks button exists
$this->add_lang_ext('gfksx/thanksforposts', 'thanks_mod');

$crawler = self::request('GET', "viewtopic.php?f=2&t={$post['topic_id']}&sid={$this->sid}&p={$post['post_id']}#p{$post['post_id']}");
$thanks_button_title = $crawler->filter('a[id="lnk_thanks_post' . $post['post_id'] . '"]')->attr('title');
$thanks_link = str_replace('./', '', html_entity_decode($crawler->filter('a[id="lnk_thanks_post' . $post['post_id'] . '"]')->attr('href')));
$this->assertContains('These users thanked the author', $crawler->filter('div[id="list_thanks' . $post['post_id'] . '"]')->text());
$this->assertEquals('Remove your thanks: user1', $thanks_button_title);
$this->assertContains($this->lang('THANK_TEXT_1'), $crawler->filter('div[id="list_thanks' . $post['post_id'] . '"]')->text());
$this->assertEquals($this->lang('REMOVE_THANKS') . 'user1', $thanks_button_title);

// Test thanking process
$crawler = self::request('GET', $thanks_link);
$this->assertContains('Remove your thanks:', $crawler->filter('h2')->text());
$this->assertContains($this->lang('REMOVE_THANKS'), $crawler->filter('h2')->text());

$form = $crawler->selectButton('Yes')->form();
$crawler = self::submit($form);

$crawler = self::request('GET', "viewtopic.php?f=2&t={$post['topic_id']}&sid={$this->sid}&p={$post['post_id']}#p{$post['post_id']}");

$thanks_button_title = $crawler->filter('#lnk_thanks_post' . $post['post_id'])->attr('title');
$this->assertEquals('Say Thanks to the author of the post: user1', $thanks_button_title);
$this->assertEquals($this->lang('THANK_POST') . ' user1', $thanks_button_title);
}
}

0 comments on commit c85b87c

Please sign in to comment.