aboutsummaryrefslogtreecommitdiffstats
path: root/tests/migrator/get_callable_from_step_test.php
blob: af636f5d21654b449fad804a226779e9840d4cd6 (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
<?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 get_callable_from_step_test extends phpbb_database_test_case
{
	public function setUp()
	{
		global $phpbb_root_path, $php_ext, $table_prefix, $phpbb_log;

		parent::setUp();

		$phpbb_log = $this->getMockBuilder('\phpbb\log\log')->disableOriginalConstructor()->getMock();
		$db = $this->new_dbal();
		$factory = new \phpbb\db\tools\factory();
		$cache_service = $this->getMockBuilder('\phpbb\cache\service')->disableOriginalConstructor()->getMock();
		$user = $this->getMockBuilder('\phpbb\user')->disableOriginalConstructor()->getMock();
		$module_manager = new \phpbb\module\module_manager(
			$this->getMockBuilder('\phpbb\cache\driver\dummy')->disableOriginalConstructor()->getMock(),
			$db,
			new phpbb_mock_extension_manager($phpbb_root_path),
			'phpbb_modules',
			$phpbb_root_path,
			$php_ext
		);
		$module_tools = new \phpbb\db\migration\tool\module($db, $cache_service, $user, $module_manager, $phpbb_root_path, $php_ext, 'phpbb_modules');
		$this->migrator = new \phpbb\db\migrator(
			new phpbb_mock_container_builder(),
			new \phpbb\config\config(array()),
			$db,
			$factory->get($db),
			'phpbb_migrations',
			$phpbb_root_path,
			$php_ext,
			$table_prefix,
			array($module_tools),
			new \phpbb\db\migration\helper()
		);

		if (!$module_tools->exists('acp', 0, 'new_module_langname'))
		{
			$module_tools->add('acp', 0, array(
				'module_basename'	=> 'new_module_basename',
				'module_langname'	=> 'new_module_langname',
				'module_mode'		=> 'settings',
				'module_auth'		=> '',
				'module_display'	=> true,
				'before'			=> false,
				'after'				=> false,
			));
			$this->module_added = true;
		}
	}

	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__).'/../dbal/fixtures/migrator.xml');
	}

	public function get_callable_from_step_provider()
	{
		return array(
			array(
				array('if', array(
					false,
					array('permission.add', array('some_data')),
				)),
				true, // expects false
			),
			array(
				array('if', array(
					array('module.exists', array(
						'mcp',
						'RANDOM_PARENT',
						'RANDOM_MODULE'
					)),
					array('permission.add', array('some_data')),
				)),
				true, // expects false
			),
			array(
				array('if', array(
					array('module.exists', array(
						'acp',
						0,
						'new_module_langname'
					)),
					array('module.add', array(
						'acp',
						0,
						'module_basename'	=> 'new_module_basename2',
						'module_langname'	=> 'new_module_langname2',
						'module_mode'		=> 'settings',
						'module_auth'		=> '',
						'module_display'	=> true,
						'before'			=> false,
						'after'				=> false,
					)),
				)),
				false, // expects false
			),
		);
	}

	/**
	 * @dataProvider get_callable_from_step_provider
	 */
	public function test_get_callable_from_step($step, $expects_false)
	{
		if ($expects_false)
		{
			$this->assertFalse($this->call_get_callable_from_step($step));
		}
		else
		{
			$this->assertNotFalse($this->call_get_callable_from_step($step));
		}
	}

	protected function call_get_callable_from_step($step)
	{
		$class = new ReflectionClass($this->migrator);
		$method = $class->getMethod('get_callable_from_step');
		$method->setAccessible(true);
		return $method->invokeArgs($this->migrator, array($step));
	}
}