19 declare(strict_types=1);
27 $conversations_fixture = [
32 'participants' => json_encode([[
'id' => 1], [
'id' => 2], [
'id' => 3]], JSON_THROW_ON_ERROR)
37 'message' =>
'Hello World',
39 'timestamp' => (string) time()
47 'participants' => json_encode([[
'id' => 3], [
'id' => 4]], JSON_THROW_ON_ERROR)
52 'message' =>
'Hello World',
54 'timestamp' => (string) time()
62 'participants' => json_encode([[
'id' => 5], [
'id' => 1]], JSON_THROW_ON_ERROR)
67 'message' =>
'Hello World',
69 'timestamp' => (string) time()
77 'participants' => json_encode([[
'id' => 6], [
'id' => 1]], JSON_THROW_ON_ERROR)
83 $user = $this->getMockBuilder(ilObjUser::class)->onlyMethods([
'getId'])->disableOriginalConstructor()->getMock();
84 $user->method(
'getId')->willReturn(1);
85 $db = $this->createMock(ilDBInterface::class);
86 $resultMock = $this->createMock(ilDBStatement::class);
88 $db->expects($this->once())
90 ->with($this->stringContains(
'FROM osc_conversation'))
91 ->willReturn($resultMock);
93 $db->expects($this->exactly(count($conversations_fixture) - 1))
95 ->with($this->stringContains(
'FROM osc_messages'))
96 ->willReturn($resultMock);
98 $db->expects($this->exactly((count($conversations_fixture) * 2) - 1 + 1))->method(
'fetchAssoc')->with($resultMock)->willReturnOnConsecutiveCalls(
99 $conversations_fixture[0][
'conversation'],
100 $conversations_fixture[0][
'messages'][0],
101 $conversations_fixture[1][
'conversation'],
102 $conversations_fixture[2][
'conversation'],
103 $conversations_fixture[2][
'messages'][0],
104 $conversations_fixture[3][
'conversation'],
113 $conversations = $repository->findByIds(array_map(
static function (array $conversation):
string {
114 return $conversation[
'conversation'][
'id'];
115 }, $conversations_fixture));
117 self::assertCount(count($conversations_fixture) - 1, $conversations);
119 self::assertSame($conversations_fixture[0][
'conversation'][
'id'], $conversations[0]->
getId());
120 self::assertTrue($conversations[0]->isGroup());
121 self::assertSame($conversations_fixture[0][
'messages'][0][
'id'], $conversations[0]->getLastMessage()->
getId());
123 self::assertFalse($conversations[1]->isGroup());
124 self::assertSame($conversations_fixture[2][
'conversation'][
'id'], $conversations[1]->
getId());
125 self::assertSame($conversations_fixture[2][
'messages'][0][
'id'], $conversations[1]->getLastMessage()->
getId());
127 self::assertFalse($conversations[2]->isGroup());
128 self::assertSame($conversations_fixture[3][
'conversation'][
'id'], $conversations[2]->
getId());
129 self::assertSame(
'', $conversations[2]->getLastMessage()->
getId());
Class ilOnScreenChatBaseTest.
testConversationsCanBeRetrieved()