ReadStatusMessageEventTest::testGetThread()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the MilioooMessageBundle package.
5
 *
6
 * (c) Michiel boeckaert <[email protected]>
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Miliooo\Messaging\Tests\Event;
12
13
use Miliooo\Messaging\Event\ReadStatusMessageEvent;
14
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper;
15
use Miliooo\Messaging\User\ParticipantInterface;
16
use Miliooo\Messaging\Model\MessageMetaInterface;
17
18
/**
19
 * Test file for ReadStatusMessageEvent
20
 *
21
 * @author Michiel Boeckaert <[email protected]>
22
 */
23
class ReadStatusMessageEventTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * The class under test
27
     * @var ReadStatusMessageEvent
28
     */
29
    private $event;
30
31
    /**
32
     * @var \PHPUnit_Framework_MockObject_MockObject
33
     */
34
    private $message;
35
36
    /**
37
     * @var \PHPUnit_Framework_MockObject_MockObject
38
     */
39
    private $messageMeta;
40
41
    /**
42
     * @var \PHPUnit_Framework_MockObject_MockObject
43
     */
44
    private $thread;
45
46
    /**
47
     * @var ParticipantInterface
48
     */
49
    private $participant;
50
51
    public function setUp()
52
    {
53
        $this->message = $this->getMock('Miliooo\Messaging\Model\MessageInterface');
54
        $this->messageMeta = $this->getMock('Miliooo\Messaging\Model\MessageMetaInterface');
55
        $this->thread = $this->getMock('Miliooo\Messaging\Model\ThreadInterface');
56
        $this->participant = new ParticipantTestHelper(1);
57
        $this->event = new ReadStatusMessageEvent($this->message, $this->participant);
58
    }
59
60
    public function testGetMessage()
61
    {
62
        $this->assertEquals($this->message, $this->event->getMessage());
63
    }
64
65
    public function testGetThread()
66
    {
67
        $this->message->expects($this->once())->method('getThread')->will($this->returnValue($this->thread));
68
        $this->assertEquals($this->thread, $this->event->getThread());
69
    }
70
71
    public function testGetPreviousReadStatus()
72
    {
73
        $this->message->expects($this->once())->method('getMessageMetaForParticipant')->with($this->participant)
74
            ->will($this->returnValue($this->messageMeta));
75
76
        $this->messageMeta->expects($this->once())->method('getPreviousReadStatus')
77
            ->will($this->returnValue(MessageMetaInterface::READ_STATUS_NEVER_READ));
78
79
        $this->assertSame(MessageMetaInterface::READ_STATUS_NEVER_READ, $this->event->getPreviousReadStatus());
80
    }
81
82
    public function testGetReadStatus()
83
    {
84
        $this->message->expects($this->once())->method('getMessageMetaForParticipant')->with($this->participant)
85
            ->will($this->returnValue($this->messageMeta));
86
87
        $this->messageMeta->expects($this->once())->method('getReadStatus')
88
            ->will($this->returnValue(MessageMetaInterface::READ_STATUS_READ));
89
90
        $this->assertSame(MessageMetaInterface::READ_STATUS_READ, $this->event->getReadStatus());
91
    }
92
93
    public function testGetParticipant()
94
    {
95
        $this->assertEquals($this->participant, $this->event->getParticipant());
96
    }
97
98
    public function testIsFirstTimeReadReturnsFalse()
99
    {
100
        $this->message->expects($this->any())->method('getMessageMetaForParticipant')->with($this->participant)
101
            ->will($this->returnValue($this->messageMeta));
102
103
        $this->messageMeta->expects($this->never())->method('getReadStatus');
104
105
        $this->messageMeta->expects($this->once())->method('getPreviousReadStatus')
106
            ->will($this->returnValue(MessageMetaInterface::READ_STATUS_MARKED_UNREAD));
107
108
        $this->assertFalse($this->event->isFirstTimeRead());
109
    }
110
111
    public function testIsFirstTimeReadReturnsTrue()
112
    {
113
        $this->message->expects($this->any())->method('getMessageMetaForParticipant')->with($this->participant)
114
            ->will($this->returnValue($this->messageMeta));
115
116
        $this->messageMeta->expects($this->once())->method('getPreviousReadStatus')
117
            ->will($this->returnValue(MessageMetaInterface::READ_STATUS_NEVER_READ));
118
119
        $this->messageMeta->expects($this->once())->method('getReadStatus')
120
            ->will($this->returnValue(MessageMetaInterface::READ_STATUS_READ));
121
122
        $this->assertTrue($this->event->isFirstTimeRead());
123
    }
124
}
125