Skip to content

Commit f80a932

Browse files
authored
Merge pull request #8 from VSEphpbb/testing
Prep for alpha1 release
2 parents 93ba829 + b0c88e6 commit f80a932

3 files changed

Lines changed: 188 additions & 1 deletion

File tree

acp/topic_prefixes_module.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class topic_prefixes_module
1717
{
1818
/** @var string */
1919
public $u_action;
20+
public $tpl_name;
21+
public $page_title;
2022

2123
/**
2224
* Main ACP module

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "phpbb-extension",
44
"description": "A phpBB extension for topic prefixes.",
55
"homepage": "https://www.phpbb.com",
6-
"version": "1.0.0-dev",
6+
"version": "1.0.0-a1",
77
"license": "GPL-2.0",
88
"authors": [
99
{
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?php
2+
/**
3+
*
4+
* Topic Prefixes extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2016 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\topicprefixes\tests\functional;
12+
13+
use \Symfony\Component\DomCrawler\Crawler;
14+
15+
/**
16+
* @group functional
17+
*/
18+
class functional_test extends \phpbb_functional_test_case
19+
{
20+
const FORUM_ID = 2;
21+
22+
static protected function setup_extensions()
23+
{
24+
return array('phpbb/topicprefixes');
25+
}
26+
27+
public function setUp()
28+
{
29+
parent::setUp();
30+
31+
$this->add_lang_ext('phpbb/topicprefixes', [
32+
'acp_topic_prefixes',
33+
'info_acp_topic_prefixes',
34+
'topic_prefixes'
35+
]);
36+
}
37+
38+
public function test_acp_module_installation()
39+
{
40+
$this->login();
41+
$this->admin_login();
42+
43+
$crawler = self::request('GET', "adm/index.php?i=\\phpbb\\topicprefixes\\acp\\topic_prefixes_module&mode=manage&sid={$this->sid}");
44+
45+
// Assert module appears in sidebar
46+
$this->assertContainsLang('ACP_TOPIC_PREFIXES', $crawler->filter('.menu-block')->text());
47+
$this->assertContainsLang('ACP_MANAGE_PREFIXES', $crawler->filter('#activemenu')->text());
48+
49+
// Assert module content appears
50+
$this->assertContainsLang('TOPIC_PREFIXES', $crawler->filter('#main h1')->text());
51+
$this->assertContainsLang('TOPIC_PREFIXES_EXPLAIN', $crawler->filter('#main')->text());
52+
53+
// Jump to the create page
54+
$form = $crawler->selectButton($this->lang('GO'))->form(['forum_id' => self::FORUM_ID]);
55+
$crawler = self::submit($form);
56+
57+
// Assert we're on create page and prefixes are currently empty
58+
$this->assertContainsLang('TOPIC_PREFIXES_EMPTY', $crawler->text());
59+
}
60+
61+
public function test_acp_create_prefix()
62+
{
63+
$this->login();
64+
$this->admin_login();
65+
66+
$this->assertEquals(1, $this->create_prefix('[foo1]', self::FORUM_ID));
67+
}
68+
69+
public function test_acp_disable_prefix()
70+
{
71+
$this->login();
72+
$this->admin_login();
73+
74+
$prefix = $this->create_prefix('[foo2]', self::FORUM_ID);
75+
$hash = $this->mock_link_hash('edit' . $prefix);
76+
77+
// Disable the prefix
78+
$crawler = self::request('GET', 'adm/index.php?i=\phpbb\topicprefixes\acp\topic_prefixes_module&mode=manage&action=edit&forum_id=' . self::FORUM_ID . "&prefix_id={$prefix}&hash={$hash}&sid={$this->sid}");
79+
$this->assertCount(1, $crawler->filter('.never'));
80+
81+
// Enable the prefix
82+
$crawler = self::request('GET', 'adm/index.php?i=\phpbb\topicprefixes\acp\topic_prefixes_module&mode=manage&action=edit&forum_id=' . self::FORUM_ID . "&prefix_id={$prefix}&hash={$hash}&sid={$this->sid}");
83+
$this->assertCount(0, $crawler->filter('.never'));
84+
}
85+
86+
public function test_acp_delete_prefix()
87+
{
88+
$this->login();
89+
$this->admin_login();
90+
91+
$prefix = $this->create_prefix('[foo3]', self::FORUM_ID);
92+
93+
// Delete the prefix
94+
$crawler = self::request('GET', 'adm/index.php?i=\phpbb\topicprefixes\acp\topic_prefixes_module&mode=manage&action=delete&forum_id=' . self::FORUM_ID . "&prefix_id={$prefix}&sid={$this->sid}");
95+
96+
// Confirm delete
97+
$form = $crawler->selectButton('confirm')->form();
98+
$crawler = self::submit($form);
99+
100+
// Assert deletion was success
101+
$this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
102+
$this->assertContainsLang('TOPIC_PREFIX_DELETED', $crawler->text());
103+
}
104+
105+
/**
106+
* Create a new topic prefix
107+
*
108+
* @param string $prefix_tag The name of the tag
109+
* @param int $forum_id The forum identifier
110+
* @return int The new topic prefix identifier
111+
*/
112+
protected function create_prefix($prefix_tag, $forum_id)
113+
{
114+
$crawler = self::request('GET', 'adm/index.php?i=\phpbb\topicprefixes\acp\topic_prefixes_module&mode=manage&forum_id=' . self::FORUM_ID . "&sid={$this->sid}");
115+
116+
$form = $crawler->selectButton($this->lang('SUBMIT'))->form(array(
117+
'prefix_tag' => $prefix_tag,
118+
'forum_id' => $forum_id,
119+
));
120+
121+
/** @var Crawler $crawler */
122+
$crawler = self::submit($form);
123+
124+
// Assert new tag appears
125+
$this->assertContains($prefix_tag, $crawler->filter('table')->text());
126+
127+
// Get and return the new tag's id
128+
$crawler = $crawler
129+
->filter('table > tbody > tr')
130+
->reduce(function (Crawler $node) use ($prefix_tag) {
131+
return $node->filter('strong')->text() == $prefix_tag;
132+
});
133+
$url = $crawler->selectLink($this->lang('ENABLED'))->link()->getUri();
134+
135+
return (int) $this->get_parameter_from_link($url, 'prefix_id');
136+
}
137+
138+
/**
139+
* Create a link hash for the user 'admin'
140+
*
141+
* @param string $link_name The name of the link
142+
* @return string the hash
143+
*/
144+
protected function mock_link_hash($link_name)
145+
{
146+
$this->get_db();
147+
148+
$sql = "SELECT user_form_salt
149+
FROM phpbb_users
150+
WHERE username = 'admin'";
151+
$result = $this->db->sql_query($sql);
152+
$user_form_salt = $this->db->sql_fetchfield('user_form_salt');
153+
$this->db->sql_freeresult($result);
154+
155+
return substr(sha1($user_form_salt . $link_name), 0, 8);
156+
}
157+
158+
public function test_posting()
159+
{
160+
$this->login();
161+
162+
$prefix = [
163+
'id' => 1,
164+
'tag' => '[foo1]',
165+
];
166+
167+
// Check the new posting page
168+
$crawler = self::request('GET', 'posting.php?mode=post&f=' . self::FORUM_ID . "&sid={$this->sid}");
169+
$this->assertContainsLang('TOPIC_PREFIX', $crawler->filter('#postingbox')->text());
170+
171+
// Check posting a new topic
172+
$topic = $this->create_topic(
173+
self::FORUM_ID,
174+
"{$prefix['tag']} topic prefix test",
175+
'This is a test topic',
176+
['topic_prefix' => $prefix['id']]
177+
);
178+
179+
// Check editing the topic page
180+
$crawler = self::request('GET', 'posting.php?mode=edit&f=' . self::FORUM_ID . "&p={$topic['topic_id']}&sid={$this->sid}");
181+
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
182+
$values = $form->getValues();
183+
$this->assertEquals($prefix['id'], $values['topic_prefix']);
184+
}
185+
}

0 commit comments

Comments
 (0)