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