aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal/migrator_tool_config_test.php
blob: 7d582f230b71abddd89da433f8114306a3fd21e6 (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
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php';

class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case
{
	public function setup()
	{
		$this->config = new phpbb_config(array());

		$this->tool = new phpbb_db_migration_tool_config($this->config);

		parent::setup();
	}

	public function test_add()
	{
		try
		{
			$this->tool->add('foo', 'bar');
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals('bar', $this->config['foo']);

		try
		{
			$this->tool->add('foo', 'bar');
			$this->fail('Exception not thrown');
		}
		catch (Exception $e) {}
	}

	public function test_update()
	{
		$this->config->set('foo', 'bar');
		try
		{
			$this->tool->update('foo', 'bar2');
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals('bar2', $this->config['foo']);
	}

	public function test_update_if_equals()
	{
		$this->config->set('foo', 'bar');

		try
		{
			$this->tool->update_if_equals('', 'foo', 'bar2');
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals('bar', $this->config['foo']);

		try
		{
			$this->tool->update_if_equals('bar', 'foo', 'bar2');
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals('bar2', $this->config['foo']);
	}

	public function test_remove()
	{
		$this->config->set('foo', 'bar');

		try
		{
			$this->tool->remove('foo');
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertFalse(isset($this->config['foo']));
	}

	public function test_reverse()
	{
		$this->config->set('foo', 'bar');

		try
		{
			$this->tool->reverse('add', 'foo');
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertFalse(isset($this->config['foo']));

		$this->config->set('foo', 'bar');

		try
		{
			$this->tool->reverse('update_if_equals', 'test', 'foo', 'bar');
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals('test', $this->config['foo']);
	}
}