aboutsummaryrefslogtreecommitdiffstats
path: root/tests/event/md_exporter_test.php
blob: 2eeb48ea054208f54f0c5411335d089d657b1bd7 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?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.
*
*/

class phpbb_event_md_exporter_test extends phpbb_test_case
{
	static public function crawl_eventsmd_data()
	{
		return array(
			array('normal_events.md.test', null, null, array(
				'acp_bbcodes_actions_append' => array(
					'event' => 'acp_bbcodes_actions_append',
					'files' => array(
						'prosilver' => array(),
						'adm' => array('acp_bbcodes.html'),
					),
					'since' => '3.1.0-a3',
					'changed' => array(
						'3.1.0-a4' => '',
					),
					'description' => 'desc1' . "\n",
				),
				'acp_bbcodes_actions_prepend' => array(
					'event' => 'acp_bbcodes_actions_prepend',
					'files' => array(
						'prosilver' => array(),
						'adm' => array('acp_bbcodes.html'),
					),
					'since' => '3.1.0-a5',
					'changed' => array(),
					'description' => 'desc2' . "\n",
				),
				'acp_bbcodes_actions_prepend2' => array(
					'event' => 'acp_bbcodes_actions_prepend2',
					'files' => array(
						'prosilver' => array(),
						'adm' => array('acp_bbcodes.html'),
					),
					'since' => '3.1.0-a4',
					'changed' => array(
						'3.1.0-a5' => 'Moved up',
						'3.1.0-a6' => 'Moved down',
					),
					'description' => 'desc2' . "\n",
				),
			)),
			array('normal_events.md.test', '3.1.0-a5', '3.1.0-a5', array(
				'acp_bbcodes_actions_prepend' => array(
					'event' => 'acp_bbcodes_actions_prepend',
					'files' => array(
						'prosilver' => array(),
						'adm' => array('acp_bbcodes.html'),
					),
					'since' => '3.1.0-a5',
					'changed' => array(),
					'description' => 'desc2' . "\n",
				),
				'acp_bbcodes_actions_prepend2' => array(
					'event' => 'acp_bbcodes_actions_prepend2',
					'files' => array(
						'prosilver' => array(),
						'adm' => array('acp_bbcodes.html'),
					),
					'since' => '3.1.0-a4',
					'changed' => array(
						'3.1.0-a5' => 'Moved up',
						'3.1.0-a6' => 'Moved down',
					),
					'description' => 'desc2' . "\n",
				),
			)),
		);
	}

	/**
	 * @dataProvider crawl_eventsmd_data
	 *
	 * @param string $file
	 * @param string $min_version
	 * @param string $max_version
	 * @param array $events
	 */
	public function test_crawl_eventsmd($file, $min_version, $max_version, $events)
	{
		$exporter = new \phpbb\event\md_exporter(dirname(__FILE__) . '/fixtures/', null, $min_version, $max_version);
		$this->assertSame(count($events), $exporter->crawl_eventsmd($file, 'adm'));
		$this->assertEquals($events, $exporter->get_events());
	}

	static public function crawl_phpbb_eventsmd_data()
	{
		return array(
			array('styles'),
			array('adm'),
		);
	}

	/**
	 * @dataProvider crawl_phpbb_eventsmd_data
	 */
	public function test_crawl_phpbb_eventsmd($filter)
	{
		global $phpbb_root_path;
		$exporter = new \phpbb\event\md_exporter($phpbb_root_path);
		$this->assertGreaterThan(0, $exporter->crawl_eventsmd('docs/events.md', $filter));
	}

	static public function crawl_template_file_data()
	{
		global $phpbb_root_path;
		$exporter = new \phpbb\event\md_exporter($phpbb_root_path);
		$data_provider = array();

		$styles = array(
			'adm/style/' => 'adm',
			'styles/prosilver/template/' => 'styles',
		);
		foreach ($styles as $path => $filter)
		{
			$files = $exporter->get_recursive_file_list($phpbb_root_path . $path, $path);
			foreach ($files as $file)
			{
				$data_provider[] = array($filter, $path . $file);
			}
		}

		return $data_provider;
	}

	/**
	 * @dataProvider crawl_template_file_data
	 */
	public function test_crawl_template_file($filter, $file)
	{
		global $phpbb_root_path;
		$exporter = new \phpbb\event\md_exporter($phpbb_root_path);
		$exporter->crawl_eventsmd('docs/events.md', $filter);
		$events = $exporter->crawl_file_for_events($file);

		$this->assertGreaterThanOrEqual(0, count($events));
		$this->assertTrue($exporter->validate_events_from_file($file, $events));
	}
}