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

StanzaMapperTest.php « db « integration « tests - github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4385b5d0b846b0765d3792a1953fa4261e18918 (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
<?php

namespace OCA\OJSXC\Db;

use OCA\OJSXC\Utility\MapperTestUtility;
use OCP\AppFramework\Db\DoesNotExistException;

/**
 * @group DB
 */
class StanzaMapperTest extends MapperTestUtility {

	/**
	 * @var StanzaMapper
	 */
	protected $mapper;

	protected function setUp() {
		$this->entityName = 'OCA\OJSXC\Db\Stanza';
		$this->mapperName = 'StanzaMapper';
		parent::setUp();
	}

	public function insertProvider() {
		return [
			[
				'john@localhost',
				'thomas@localhost',
				'abcd'
			]
		];
	}
	
	/**
	 * @dataProvider insertProvider
	 */
	public function testInsert($from, $to, $data) {
		$stanza = new Stanza();
		$stanza->setFrom($from);
		$stanza->setTo($to);
		$stanza->setStanza($data);

		$this->assertEquals($stanza->getFrom(), $from);
		$this->assertEquals($stanza->getTo(), $to);
		$this->assertEquals($stanza->getStanza(), $data);

		$this->mapper->insert($stanza);

		$result = $this->fetchAll();

		$this->assertCount(1, $result);
		$this->assertEquals($stanza->getFrom(), $result[0]->getFrom());
		$this->assertEquals($stanza->getTo(),  $result[0]->getTo());
		$this->assertEquals($stanza->getStanza(),  $result[0]->getStanza());
	}

	/**
	 * @expectedException \OCP\AppFramework\Db\DoesNotExistException
	 */
	public function testFindByToNotFound() {
		$this->mapper->findByTo('test');
	}

	/**
	 * @expectedException \OCP\AppFramework\Db\DoesNotExistException
	 */
	public function testFindByToNotFound2() {
		$stanza = new Stanza();
		$stanza->setFrom('john@localhost');
		$stanza->setTo('john@localhost');
		$stanza->setStanza('abcd');
		$this->mapper->insert($stanza);

		$this->mapper->findByTo('test');
	}

	public function testFindByToFound() {
		$stanza1 = new Stanza();
		$stanza1->setFrom('jan@localhost');
		$stanza1->setTo('john@localhost');
		$stanza1->setStanza('abcd1');
		$this->mapper->insert($stanza1);

		$stanza2 = new Stanza();
		$stanza2->setFrom('thomas@localhost');
		$stanza2->setTo('jan@localhost');
		$stanza2->setStanza('abcd2');
		$this->mapper->insert($stanza2);


		// check if two elements are inserted
		$result = $this->fetchAll();
		$this->assertCount(2, $result);

		// check findByTo
		$result = $this->mapper->findByTo('john@localhost');
		$this->assertCount(1, $result);
		$this->assertEquals($stanza1->getStanza(),  $result[0]->getStanza());

		// check if element is deleted
		$result = $this->fetchAll();
		$this->assertCount(1, $result);
		$this->assertEquals($stanza2->getFrom(), $result[0]->getFrom());
		$this->assertEquals($stanza2->getTo(),  $result[0]->getTo());
		$this->assertEquals($stanza2->getStanza(),  $result[0]->getStanza());

	}

}