/
AnnotationsTableIntegrationTest.php
112 lines (85 loc) · 3.27 KB
/
AnnotationsTableIntegrationTest.php
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
<?php
namespace Elgg\Database;
use Elgg\IntegrationTestCase;
class AnnotationsTableIntegrationTest extends IntegrationTestCase {
/**
* @var AnnotationsTable
*/
protected $service;
/**
* @var \ElggUser
*/
protected $owner;
/**
* {@inheritDoc}
*/
public function up() {
$this->service = _elgg_services()->annotationsTable;
$this->owner = $this->createUser();
_elgg_services()->session->setLoggedInUser($this->owner);
}
public function testCreateAnnotation() {
$entity = $this->createObject();
$annotation = new \ElggAnnotation();
$annotation->owner_guid = $this->owner->guid;
$annotation->name = 'foo';
$annotation->value = 'bar';
$annotation_id = $this->service->create($annotation, $entity);
$this->assertIsInt($annotation_id);
$annotation = elgg_get_annotation_from_id($annotation_id);
$this->assertInstanceOf(\ElggAnnotation::class, $annotation);
$this->assertEquals($this->owner->guid, $annotation->owner_guid);
$this->assertEquals('foo', $annotation->name);
$this->assertEquals('bar', $annotation->value);
}
public function testCreateAnnotationWithEmptyContent() {
$entity = $this->createObject();
$annotation = new \ElggAnnotation();
$this->assertFalse($this->service->create($annotation, $entity));
}
public function testUpdateAnnotationUsingUpdate() {
$entity = $this->createObject();
$annotation = new \ElggAnnotation();
$annotation->owner_guid = $this->owner->guid;
$annotation->name = 'foo';
$annotation->value = 'bar';
$annotation_id = $this->service->create($annotation, $entity);
$this->assertIsInt($annotation_id);
$annotation = elgg_get_annotation_from_id($annotation_id);
$this->assertInstanceOf(\ElggAnnotation::class, $annotation);
$annotation->value = 'bar2';
$annotation_save_id = $this->service->update($annotation);
$this->assertEquals($annotation_id, $annotation_save_id);
$annotation = elgg_get_annotation_from_id($annotation_id);
$this->assertEquals('bar2', $annotation->value);
}
public function testUpdateAnnotationUsingCreate() {
$entity = $this->createObject();
$annotation = new \ElggAnnotation();
$annotation->owner_guid = $this->owner->guid;
$annotation->name = 'foo';
$annotation->value = 'bar';
$annotation_id = $this->service->create($annotation, $entity);
$this->assertIsInt($annotation_id);
$annotation = elgg_get_annotation_from_id($annotation_id);
$this->assertInstanceOf(\ElggAnnotation::class, $annotation);
$annotation->value = 'bar2';
$annotation_save_id = $this->service->create($annotation, $entity);
$this->assertEquals($annotation_id, $annotation_save_id);
$annotation = elgg_get_annotation_from_id($annotation_id);
$this->assertEquals('bar2', $annotation->value);
}
public function testUpdateAnnotationWithEmptyContent() {
$entity = $this->createObject();
$annotation = new \ElggAnnotation();
$annotation->owner_guid = $this->owner->guid;
$annotation->name = 'foo';
$annotation->value = 'bar';
$annotation_id = $this->service->create($annotation, $entity);
$this->assertIsInt($annotation_id);
$annotation = elgg_get_annotation_from_id($annotation_id);
$this->assertInstanceOf(\ElggAnnotation::class, $annotation);
unset($annotation->value);
$this->assertFalse($this->service->update($annotation));
}
}