Skip to content

Commit 8bbed88

Browse files
committed
add more tests
1 parent a26e2a5 commit 8bbed88

1 file changed

Lines changed: 93 additions & 1 deletion

File tree

tests/unit/BigBlueButtonTest.php

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,24 @@
2020

2121
use BigBlueButton\Core\ApiMethod;
2222
use BigBlueButton\Exceptions\ConfigException;
23+
use BigBlueButton\Exceptions\NetworkException;
24+
use BigBlueButton\Exceptions\ParsingException;
25+
use BigBlueButton\Http\Transport\TransportInterface;
26+
use BigBlueButton\Http\Transport\TransportResponse;
2327
use BigBlueButton\Parameters\DeleteRecordingsParameters;
2428
use BigBlueButton\Parameters\GetRecordingsParameters;
2529
use BigBlueButton\Parameters\PublishRecordingsParameters;
30+
use PHPUnit\Framework\MockObject\MockObject;
2631

2732
/**
2833
* Class BigBlueButtonTest
2934
* @package BigBlueButton
3035
*/
3136
class BigBlueButtonTest extends TestCase
3237
{
38+
/** @var MockObject */
39+
private $transport;
40+
3341
/**
3442
* @var BigBlueButton
3543
*/
@@ -42,7 +50,8 @@ public function setUp(): void
4250
{
4351
parent::setUp();
4452

45-
$this->bbb = new BigBlueButton('http://localhost/');
53+
$this->transport = $this->createMock(TransportInterface::class);
54+
$this->bbb = new BigBlueButton('http://localhost/', null, $this->transport);
4655
}
4756

4857
public function testMissingUrl()
@@ -59,6 +68,89 @@ public function testMissingUrl()
5968
}
6069
}
6170

71+
public function testNetworkFailure()
72+
{
73+
$this->expectException(NetworkException::class);
74+
75+
$this->transport->method('request')->willThrowException(new NetworkException());
76+
77+
$params = $this->generateCreateParams();
78+
79+
$this->bbb->createMeeting($this->getCreateMock($params));
80+
}
81+
82+
public function testInvalidXMLResponse()
83+
{
84+
$this->expectException(ParsingException::class);
85+
86+
$this->transport->method('request')->willReturn(new TransportResponse('foobar', null));
87+
88+
$params = $this->generateCreateParams();
89+
90+
$this->bbb->createMeeting($this->getCreateMock($params));
91+
}
92+
93+
public function testJSessionId()
94+
{
95+
$id = 'foobar';
96+
$this->transport->method('request')->willReturn(new TransportResponse('<x></x>', $id));
97+
98+
$params = $this->generateCreateParams();
99+
100+
$this->bbb->createMeeting($this->getCreateMock($params));
101+
102+
$this->assertEquals($id, $this->bbb->getJSessionId());
103+
}
104+
105+
public function testApiVersion()
106+
{
107+
$apiVersion = '2.0';
108+
$xml = "<response>
109+
<returncode>SUCCESS</returncode>
110+
<version>2.0</version>
111+
<apiVersion>$apiVersion</apiVersion>
112+
<bbbVersion/>
113+
</response>";
114+
$this->transport->method('request')->willReturn(new TransportResponse($xml, null));
115+
116+
$response = $this->bbb->getApiVersion();
117+
118+
$this->assertEquals($apiVersion, $response->getVersion());
119+
}
120+
121+
public function testIsConnectionWorking()
122+
{
123+
$xmlSuccess = '<response>
124+
<returncode>SUCCESS</returncode>
125+
<running>false</running>
126+
</response>';
127+
$xmlFailure = '<response>
128+
<returncode>FAILED</returncode>
129+
<running>false</running>
130+
</response>';
131+
$xmlChecksumError = '<response>
132+
<returncode>FAILED</returncode>
133+
<messageKey>checksumError</messageKey>
134+
</response>';
135+
136+
$this->transport->method('request')->willReturnOnConsecutiveCalls(
137+
new TransportResponse($xmlSuccess, null),
138+
new TransportResponse($xmlFailure, null),
139+
new TransportResponse($xmlChecksumError, null),
140+
new TransportResponse('', null)
141+
);
142+
143+
$this->assertTrue($this->bbb->isConnectionWorking(), 'Connection is working');
144+
145+
$this->assertFalse($this->bbb->isConnectionWorking(), 'Connection is not working, because failure is returned');
146+
147+
$this->assertFalse($this->bbb->isConnectionWorking(), 'Connection is not working, because checksum error');
148+
$this->assertEquals(BigBlueButton::CONNECTION_ERROR_SECRET, $this->bbb->getConnectionError());
149+
150+
$this->assertFalse($this->bbb->isConnectionWorking(), 'Connection is not working, because XML is invalid');
151+
$this->assertEquals(BigBlueButton::CONNECTION_ERROR_BASEURL, $this->bbb->getConnectionError());
152+
}
153+
62154
/* Create Meeting */
63155

64156
/**

0 commit comments

Comments
 (0)