Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FixCollectedAddressesTest.php « Migration « Unit « tests - github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9c8d893ad3b5da4e31f5272130dfbaf4c5c9351d (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
<?php

/**
 * @author Christoph Wurst <christoph@winzerhof-wurst.at>
 *
 * Mail
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OCA\Mail\Tests\Unit\Migration;

use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Db\CollectedAddress;
use OCA\Mail\Db\CollectedAddressMapper;
use OCA\Mail\Migration\FixCollectedAddresses;
use OCP\Migration\IOutput;

/**
 * @group DB
 */
class FixCollectedAddressesTest extends TestCase {

	/** @var CollectedAddressMapper */
	private $mapper;

	/** @var IOutput */
	private $output;

	/** @var FixCollectedAddresses */
	private $repairStep;

	protected function setUp() {
		parent::setUp();

		$this->mapper = $this->createMock(CollectedAddressMapper::class);
		$this->output = $this->createMock(IOutput::class);
		$this->repairStep = new FixCollectedAddresses($this->mapper);
	}

	public function testRunNothingToMigrate() {
		$address1 = new CollectedAddress();
		$address1->setId(100);
		$address1->setEmail('user1@domain1.com');
		$address1->setDisplayName('User 1');
		$address2 = new CollectedAddress();
		$address2->setId(200);
		$address2->setEmail('user2@domain2.com');
		$address2->setDisplayName('User 2');

		$this->mapper->expects($this->exactly(2))
			->method('getChunk')
			->will($this->returnValueMap([
					[
						null, [
							$address1,
							$address2,
						]],
					[
						201, []]
		]));
		$this->mapper->expects($this->never())
			->method('update');

		$this->repairStep->run($this->output);
	}

	public function testRunMigrateOne() {
		$address1 = new CollectedAddress();
		$address1->setId(100);
		$address1->setEmail('"User 1" <user1@domain1.com>');
		$address1->setDisplayName(null);
		$address2 = new CollectedAddress();
		$address2->setId(200);
		$address2->setEmail('user2@domain2.com');
		$address2->setDisplayName('User 2');

		$this->mapper->expects($this->exactly(2))
			->method('getChunk')
			->will($this->returnValueMap([
					[
						null, [
							$address1,
							$address2,
						]],
					[
						201, []]
		]));
		$this->mapper->expects($this->once())
			->method('update')
			->with($address1);

		$this->repairStep->run($this->output);

		$this->assertEquals('user1@domain1.com', $address1->getEmail());
		$this->assertEquals('User 1', $address1->getDisplayName());
	}

	public function testRunDeleteFaulty() {
		$address1 = new CollectedAddress();
		$address1->setId(100);
		$address1->setEmail('"User 1 <user1@domain1.com>>>');
		$address1->setDisplayName(null);
		$address2 = new CollectedAddress();
		$address2->setId(200);
		$address2->setEmail('user2@domain2.com');
		$address2->setDisplayName('User 2');

		$this->mapper->expects($this->exactly(2))
			->method('getChunk')
			->will($this->returnValueMap([
					[
						null, [
							$address1,
							$address2,
						]],
					[
						201, []]
		]));
		$this->mapper->expects($this->once())
			->method('delete')
			->with($address1);

		$this->repairStep->run($this->output);
	}

}