ILIAS  release_8 Revision v8.24
ilBuddySystemRelationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 private const RELATION_OWNER_ID = -1;
28 private const RELATION_BUDDY_ID = -2;
29
31 {
32 $stateMock = $this->getMockBuilder(ilBuddySystemRelationState::class)->getMock();
33 $relation = new ilBuddySystemRelation(
34 $stateMock,
35 self::RELATION_OWNER_ID,
36 self::RELATION_OWNER_ID,
37 false,
38 time()
39 );
40 $this->assertNull($relation->getPriorState());
41 }
42
44 {
45 $stateMock = $this->getMockBuilder(ilBuddySystemRelationState::class)->getMock();
46 $furtherStateMock = $this->getMockBuilder(ilBuddySystemRelationState::class)->getMock();
47 $finishStateMock = $this->getMockBuilder(ilBuddySystemRelationState::class)->getMock();
48 $stateMock->method('link');
49
50 $relation = new ilBuddySystemRelation(
51 $stateMock,
52 self::RELATION_OWNER_ID,
53 self::RELATION_OWNER_ID,
54 false,
55 time()
56 );
57 $relation->setState($furtherStateMock);
58 $this->assertEquals($stateMock, $relation->getPriorState());
59 $relation->setState($finishStateMock);
60 $this->assertEquals($stateMock, $relation->getPriorState());
61 }
62
64 {
65 $stateMock = $this->getMockBuilder(ilBuddySystemRelationState::class)->getMock();
66 $ts = time();
67 $relation = new ilBuddySystemRelation(
68 $stateMock,
69 self::RELATION_OWNER_ID,
70 self::RELATION_OWNER_ID,
71 false,
72 time()
73 );
74
75 $relation = $relation->withUsrId(1);
76 $this->assertSame(1, $relation->getUsrId());
77
78 $relation = $relation->withBuddyUsrId(2);
79 $this->assertSame(2, $relation->getBuddyUsrId());
80
81 $relation = $relation->withTimestamp($ts + 1);
82 $this->assertSame($ts + 1, $relation->getTimestamp());
83
84 $relation = $relation->withIsOwnedByActor(true);
85 $this->assertTrue($relation->isOwnedByActor());
86 }
87
89 {
90 $this->expectException(ilBuddySystemRelationStateException::class);
91 $stateMock = $this->getMockBuilder(ilBuddySystemUnlinkedRelationState::class)->getMock();
92 $expectedRelation = new ilBuddySystemRelation(
93 $stateMock,
94 self::RELATION_OWNER_ID,
95 self::RELATION_OWNER_ID,
96 false,
97 time()
98 );
99
100 $expectedRelation = $expectedRelation->withUsrId(self::RELATION_OWNER_ID);
101 $expectedRelation = $expectedRelation->withBuddyUsrId(self::RELATION_OWNER_ID);
102
103 $expectedRelation->request();
104 }
105
107 {
108 $this->expectException(ilBuddySystemRelationStateException::class);
109 $stateMock = $this->getMockBuilder(ilBuddySystemLinkedRelationState::class)->getMock();
110 $expectedRelation = new ilBuddySystemRelation(
111 $stateMock,
112 self::RELATION_OWNER_ID,
113 self::RELATION_OWNER_ID,
114 false,
115 time()
116 );
117 $expectedRelation = $expectedRelation->withUsrId(self::RELATION_OWNER_ID);
118 $expectedRelation = $expectedRelation->withBuddyUsrId(self::RELATION_OWNER_ID);
119
120 $expectedRelation->unlink();
121 }
122
124 {
125 $this->expectException(ilBuddySystemRelationStateException::class);
126 $stateMock = $this->getMockBuilder(ilBuddySystemRequestedRelationState::class)->getMock();
127 $expectedRelation = new ilBuddySystemRelation(
128 $stateMock,
129 self::RELATION_OWNER_ID,
130 self::RELATION_OWNER_ID,
131 false,
132 time()
133 );
134 $expectedRelation = $expectedRelation->withUsrId(self::RELATION_OWNER_ID);
135 $expectedRelation = $expectedRelation->withBuddyUsrId(self::RELATION_OWNER_ID);
136
137 $expectedRelation->link();
138 }
139
141 {
142 $this->expectException(ilBuddySystemRelationStateException::class);
143 $stateMock = $this->getMockBuilder(ilBuddySystemRequestedRelationState::class)->getMock();
144 $expectedRelation = new ilBuddySystemRelation(
145 $stateMock,
146 self::RELATION_OWNER_ID,
147 self::RELATION_OWNER_ID,
148 false,
149 time()
150 );
151 $expectedRelation = $expectedRelation->withUsrId(self::RELATION_OWNER_ID);
152 $expectedRelation = $expectedRelation->withBuddyUsrId(self::RELATION_OWNER_ID);
153
154 $expectedRelation->ignore();
155 }
156}
Class ilBuddySystemRelationTest.
Class ilBuddySystemRelation.