Skip to content

Commit 4535c31

Browse files
committed
restoring tests/
Accidentally left tests/ out, from the original codebase. Doesn't seem necessary for functionality after install but maybe the install process uses it.
1 parent 33a91e9 commit 4535c31

File tree

8 files changed

+2290
-0
lines changed

8 files changed

+2290
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?php
2+
/**
3+
*
4+
* @package phpBB Extension - RH Topic Tags
5+
* @copyright (c) 2014 Robet Heim
6+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7+
*/
8+
namespace robertheim\topictags\tests\functional\acp;
9+
10+
/**
11+
* @ignore
12+
*/
13+
use \robertheim\topictags\tests\functional\topictags_functional_test_base;
14+
use \robertheim\topictags\prefixes;
15+
16+
/**
17+
* @group functional
18+
*/
19+
class manage_tags_controller_test extends topictags_functional_test_base
20+
{
21+
22+
/**
23+
* Tests changing tags in ACP manage tags.
24+
*/
25+
public function test_handle_edit()
26+
{
27+
// == setup specific to this test ==
28+
29+
$this->login();
30+
$this->admin_login();
31+
32+
// enable tagging in forum used for testing
33+
$forum_id = 2;
34+
$this->enable_topictags_in_forum($forum_id);
35+
36+
$this->auth->expects($this->exactly(4))
37+
->method('acl_getf')
38+
->with($this->equalTo('f_read'))
39+
->willReturn(array(
40+
$forum_id => array(
41+
'f_read' => true
42+
)
43+
));
44+
45+
// create some topics to work with
46+
$tmp = $this->create_topic($forum_id, 'tag_edit_functional_test', 'test topic for editing tag');
47+
$topic_id = $tmp['topic_id'];
48+
$tmp = $this->create_topic($forum_id, 'tag_edit_functional_test2', 'test topic for editing tag (2)');
49+
$topic_id2 = $tmp['topic_id'];
50+
51+
// add tags
52+
$tagname = 'tag1091723409837401993874';
53+
$valid_tags = array($tagname);
54+
$this->tags_manager->assign_tags_to_topic($topic_id, $valid_tags);
55+
56+
$tagname2 = 'tag210739481730498403981';
57+
$valid_tags = array($tagname2);
58+
$this->tags_manager->assign_tags_to_topic($topic_id2, $valid_tags);
59+
60+
$this->assertEquals(2, sizeof($this->tags_manager->get_existing_tags(array($tagname, $tagname2), true)));
61+
62+
// ensure both tags exist
63+
$crawler = $this->goto_manage_tags_page();
64+
$this->assertGreaterThanOrEqual(2, $crawler->filter('.topictags_editable_tag')->count());
65+
66+
$displayed_tags = $crawler->filter('.topictags_editable_tag')->each(
67+
function (\Symfony\Component\DomCrawler\Crawler $node, $i)
68+
{
69+
return $node->text();
70+
}
71+
);
72+
$this->assertContains($tagname, $displayed_tags);
73+
$this->assertContains($tagname2, $displayed_tags);
74+
75+
// == actual tests ==
76+
77+
// empty old_tag_name
78+
$tagname_new = 'tagnew';
79+
$url = "adm/index.php?i=-robertheim-topictags-acp-topictags_module&mode=tags&action=edit&sid={$this->sid}";
80+
$params = array(
81+
'old_tag_name' => base64_encode(rawurlencode('')),
82+
'new_tag_name' => base64_encode(rawurlencode($tagname_new))
83+
);
84+
85+
$response = $this->ajax($url, $params);
86+
$this->assertEquals(false, $response['success']);
87+
$this->assertEquals($this->lang('TOPICTAGS_MISSING_TAG_NAMES', $tagname_new), rawurldecode(base64_decode($response['error_msg'])));
88+
89+
// empty new_tag_name
90+
$tagname_new = '';
91+
$url = "adm/index.php?i=-robertheim-topictags-acp-topictags_module&mode=tags&action=edit&sid={$this->sid}";
92+
$params = array(
93+
'old_tag_name' => base64_encode(rawurlencode($tagname)),
94+
'new_tag_name' => base64_encode(rawurlencode($tagname_new))
95+
);
96+
97+
$response = $this->ajax($url, $params);
98+
$this->assertEquals(false, $response['success']);
99+
$this->assertEquals($this->lang('TOPICTAGS_MISSING_TAG_NAMES', $tagname_new), rawurldecode(base64_decode($response['error_msg'])));
100+
101+
// old tag does not exist
102+
$tagname_new = 'tagnew';
103+
$url = "adm/index.php?i=-robertheim-topictags-acp-topictags_module&mode=tags&action=edit&sid={$this->sid}";
104+
$params = array(
105+
'old_tag_name' => base64_encode(rawurlencode('not_existing_tag')),
106+
'new_tag_name' => base64_encode(rawurlencode($tagname_new))
107+
);
108+
109+
$response = $this->ajax($url, $params);
110+
$this->assertEquals(false, $response['success']);
111+
$this->assertEquals($this->lang('TOPICTAGS_TAG_DOES_NOT_EXIST', 'not_existing_tag'), rawurldecode(base64_decode($response['error_msg'])));
112+
113+
// invalid tag name
114+
$tagname_new = 'tag_invalid';
115+
$url = "adm/index.php?i=-robertheim-topictags-acp-topictags_module&mode=tags&action=edit&sid={$this->sid}";
116+
$params = array(
117+
'old_tag_name' => base64_encode(rawurlencode($tagname)),
118+
'new_tag_name' => base64_encode(rawurlencode($tagname_new))
119+
);
120+
121+
$response = $this->ajax($url, $params);
122+
$this->assertEquals(false, $response['success']);
123+
$this->assertEquals($this->lang('TOPICTAGS_TAG_INVALID', $tagname_new), rawurldecode(base64_decode($response['error_msg'])));
124+
125+
// same tagname
126+
$tagname_new = $tagname;
127+
$url = "adm/index.php?i=-robertheim-topictags-acp-topictags_module&mode=tags&action=edit&sid={$this->sid}";
128+
$params = array(
129+
'old_tag_name' => base64_encode(rawurlencode($tagname)),
130+
'new_tag_name' => base64_encode(rawurlencode($tagname_new))
131+
);
132+
133+
$response = $this->ajax($url, $params);
134+
$this->assertEquals(false, $response['success']);
135+
$this->assertEquals($this->lang('TOPICTAGS_NO_MODIFICATION', $tagname_new), rawurldecode(base64_decode($response['error_msg'])));
136+
137+
// new tagname already exists -> must be merged
138+
$tagname_new = $tagname2;
139+
$url = "adm/index.php?i=-robertheim-topictags-acp-topictags_module&mode=tags&action=edit&sid={$this->sid}";
140+
$params = array(
141+
'old_tag_name' => base64_encode(rawurlencode($tagname)),
142+
'new_tag_name' => base64_encode(rawurlencode($tagname_new))
143+
);
144+
$response = $this->ajax($url, $params);
145+
$this->assertEquals(true, $response['success']);
146+
$this->assertEquals(true, $response['merged']);
147+
$this->assertEquals($this->lang('TOPICTAGS_TAG_MERGED', $tagname_new), rawurldecode(base64_decode($response['msg'])));
148+
$this->assertEquals(2, $response['new_tag_count'], 'The tag must be assigned to two topics.');
149+
$existing_tags = $this->tags_manager->get_existing_tags(array($tagname, $tagname2));
150+
$this->assertEquals(1, sizeof($existing_tags), 'One of the test\'s tags must exist.');
151+
$this->assertEquals($tagname2, $existing_tags[0]['tag'], 'The 2nd of the test\'s tags must exist.');
152+
$topics = $this->tags_manager->get_topics_by_tags(array($tagname), 0, 2);
153+
$this->assertEquals(0, sizeof($topics), 'There should be no topics assigned to the tag.');
154+
$topics = $this->tags_manager->get_topics_by_tags(array($tagname2), 0, 2);
155+
$this->assertEquals(2, sizeof($topics), 'There should be two topics assigned to the tag.');
156+
157+
// new tag does not yet exist -> rename tag
158+
$tagname_new = 'tagvalid';
159+
$url = "adm/index.php?i=-robertheim-topictags-acp-topictags_module&mode=tags&action=edit&sid={$this->sid}";
160+
$params = array(
161+
// tagname has been renamed to tagname2 before
162+
'old_tag_name' => base64_encode(rawurlencode($tagname2)),
163+
'new_tag_name' => base64_encode(rawurlencode($tagname_new))
164+
);
165+
$response = $this->ajax($url, $params);
166+
$this->assertEquals(true, $response['success']);
167+
$this->assertEquals($this->lang('TOPICTAGS_TAG_CHANGED'), rawurldecode(base64_decode($response['msg'])));
168+
$existing_tags = $this->tags_manager->get_existing_tags(array($tagname2, $tagname_new));
169+
$this->assertEquals(1, sizeof($existing_tags), 'One of the test\'s tags must exist.');
170+
$this->assertEquals($tagname_new, $existing_tags[0]['tag'], 'The 2nd of the test\'s tags must exist.');
171+
$topics = $this->tags_manager->get_topics_by_tags(array($tagname2), 0, 2);
172+
$this->assertEquals(0, sizeof($topics), 'There should be no topics assigned to the tag.');
173+
$topics = $this->tags_manager->get_topics_by_tags(array($tagname_new), 0, 2);
174+
$this->assertEquals(2, sizeof($topics), 'There should be two topics assigned to the tag.');
175+
176+
// == cleanup ==
177+
178+
// delete the created tags
179+
$existing_tags = $this->tags_manager->get_existing_tags(array($tagname, $tagname2, $tagname_new));
180+
foreach ($existing_tags as $tag)
181+
{
182+
$this->tags_manager->delete_tag($tag['id']);
183+
}
184+
185+
// delete the created topics
186+
$this->delete_topic($topic_id);
187+
$this->delete_topic($topic_id2);
188+
}
189+
}

0 commit comments

Comments
 (0)