aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/subforum_test.php
blob: 6ce4f53c200ffa20bb0b29e9630125bea81fbf0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
 *
 * This file is part of the phpBB Forum Software package.
 *
 * @copyright (c) phpBB Limited <https://www.phpbb.com>
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 * For full copyright and license information, please see
 * the docs/CREDITS.txt file.
 *
 */

/**
 * @group functional
 */
class phpbb_functional_subforum_test extends phpbb_functional_test_case
{
	public function test_setup_forums()
	{
		$this->login();
		$this->admin_login();

		$forum_name = 'Subforum Test #1';
		$crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}");
		$form = $crawler->selectButton('addforum')->form([
			'forum_name'	=> $forum_name,
		]);
		$crawler = self::submit($form);
		$form = $crawler->selectButton('update')->form([
			'forum_perm_from'	=> 2,
		]);
		self::submit($form);
		$forum_id = self::get_forum_id($forum_name);

		// 'Feeds #1.1' is a sub-forum of 'Feeds #1'
		$forum_name = 'Subforum Test #1.1';
		$crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$forum_id}");
		$form = $crawler->selectButton('addforum')->form([
			'forum_name'	=> $forum_name,
		]);
		$crawler = self::submit($form);
		$form = $crawler->selectButton('update')->form([
			'forum_perm_from'	=> 2,
		]);
		self::submit($form);
		$forum_id = self::get_forum_id('Subforum Test #1.1');

		// 'Feeds #news' will be used for feed.php?mode=news
		$crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=6&mode=manage&parent_id={$forum_id}");
		$form = $crawler->selectButton('addforum')->form([
			'forum_name'	=> 'Subforum Test #1.1.1',
		]);
		$crawler = self::submit($form);
		$form = $crawler->selectButton('update')->form([
			'forum_perm_from'	=> 2,
		]);
		self::submit($form);
	}

	/**
	 * @depends test_setup_forums
	 */
	public function test_display_subforums()
	{
		$crawler = self::request('GET', "index.php?sid={$this->sid}");
		$this->assertContains('Subforum Test #1.1', $crawler->html());
		$this->assertContains('Subforum Test #1.1.1', $crawler->html());
	}

	/**
	 * @depends test_display_subforums
	 */
	public function test_display_subforums_limit()
	{
		$this->login();
		$this->admin_login();

		// Disable listing subforums
		$forum_id = $this->get_forum_id('Subforum Test #1');
		$crawler = self::request('GET', "adm/index.php?i=acp_forums&sid={$this->sid}&icat=7&mode=manage&parent_id=0&f={$forum_id}&action=edit");
		$form = $crawler->selectButton('submit')->form([
			'display_subforum_limit' => 1,
		]);
		self::submit($form);

		$crawler = self::request('GET', "index.php?sid={$this->sid}");
		$this->assertContains('Subforum Test #1.1', $crawler->html());
		$this->assertNotContains('Subforum Test #1.1.1', $crawler->html());
	}

	protected function get_forum_id($forum_name)
	{
		$this->db = $this->get_db();
		$forum_id = 0;

		$sql = 'SELECT *
				FROM ' . FORUMS_TABLE . '
				WHERE ' . $this->db->sql_in_set('forum_name', $forum_name);
		$result = $this->db->sql_query($sql);
		while ($row = $this->db->sql_fetchrow($result))
		{
			if ($row['forum_name'] == $forum_name)
			{
				$forum_id = (int) $row['forum_id'];
				break;
			}
		}
		$this->db->sql_freeresult($result);

		return $forum_id;
	}
}