Skip to content

Commit 15d87af

Browse files
authored
Merge pull request #234 from DigitalTimK/tests/fixtures
Test fixure files (and other stuff)
2 parents edc3b71 + d53c774 commit 15d87af

42 files changed

Lines changed: 928 additions & 127 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"name": "Ghazi Triki",
1515
"email": "ghazi.triki@riadvice.tn",
1616
"role": "Developer"
17+
},
18+
{
19+
"name": "Tim Korn",
20+
"email": "korn@aufKurs.de",
21+
"role": "Developer"
1722
}
1823
],
1924
"repositories": {

src/Parameters/DocumentableTrait.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function getPresentationsAsXML(): string
5858

5959
foreach ($this->presentations as $nameOrUrl => $data) {
6060
$presentation = $module->addChild('document');
61+
6162
if (0 === mb_strpos($nameOrUrl, 'http')) {
6263
$presentation->addAttribute('url', $nameOrUrl);
6364
} else {
@@ -89,4 +90,28 @@ public function getPresentationsAsXML(): string
8990

9091
return $result;
9192
}
93+
94+
private function urlExists(string $url): bool
95+
{
96+
$ch = curl_init($url);
97+
98+
if (!$ch) {
99+
throw new \RuntimeException('Unhandled curl error!');
100+
}
101+
102+
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
103+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
104+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
105+
106+
$data = curl_exec($ch);
107+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
108+
109+
curl_close($ch);
110+
111+
if ($httpCode >= 200 && $httpCode < 400) {
112+
return true;
113+
}
114+
115+
return false;
116+
}
92117
}

tests/BigBlueButtonTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,11 @@ public function testCreateMeetingWithDocumentUrlAndFileName(): void
149149
*/
150150
public function testCreateMeetingWithDocumentEmbedded(): void
151151
{
152-
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
153-
154-
$file = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'bbb_logo.png');
155-
$this->assertIsString($file);
152+
$content = file_get_contents(Fixtures::IMAGE_PATH . 'bbb_logo.png');
153+
$this->assertIsString($content);
156154

157-
$params->addPresentation('bbb_logo.png', $file);
155+
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
156+
$params->addPresentation('bbb_logo.png', $content);
158157

159158
$result = $this->bbb->createMeeting($params);
160159

@@ -168,13 +167,12 @@ public function testCreateMeetingWithDocumentEmbedded(): void
168167
*/
169168
public function testCreateMeetingWithMultiDocument(): void
170169
{
170+
$content = file_get_contents(Fixtures::IMAGE_PATH . 'bbb_logo.png');
171+
$this->assertIsString($content);
172+
171173
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
172174
$params->addPresentation('https://picsum.photos/3840/2160/?random', null, 'presentation.png');
173-
174-
$file = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'bbb_logo.png');
175-
$this->assertIsString($file);
176-
177-
$params->addPresentation('logo.png', $file);
175+
$params->addPresentation('logo.png', $content);
178176

179177
$result = $this->bbb->createMeeting($params);
180178

tests/Parameters/CreateMeetingParametersTest.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,30 @@ public function testCreateBreakoutMeeting(): void
132132
public function testGetPresentationsAsXMLWithUrl(): void
133133
{
134134
$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
135-
$createMeetingParams->addPresentation('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf');
136-
$this->assertXmlStringEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'presentation_with_url.xml', $createMeetingParams->getPresentationsAsXML());
135+
$createMeetingParams->addPresentation('https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_100KB_PDF.pdf');
136+
$this->assertXmlStringEqualsXmlFile(Fixtures::REQUEST_PATH . 'presentation_with_url.xml', $createMeetingParams->getPresentationsAsXML());
137137
}
138138

139139
public function testGetPresentationsAsXMLWithUrlAndFilename(): void
140140
{
141141
$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
142-
$createMeetingParams->addPresentation('https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf', null, 'presentation.pdf');
143-
$this->assertXmlStringEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'presentation_with_filename.xml', $createMeetingParams->getPresentationsAsXML());
142+
$createMeetingParams->addPresentation(
143+
'https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_100KB_PDF.pdf',
144+
null,
145+
'presentation.pdf'
146+
);
147+
$this->assertXmlStringEqualsXmlFile(
148+
Fixtures::REQUEST_PATH . 'presentation_with_filename.xml',
149+
$createMeetingParams->getPresentationsAsXML()
150+
);
144151
}
145152

146153
public function testGetPresentationsAsXMLWithFile(): void
147154
{
148-
$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
155+
$content = file_get_contents(Fixtures::IMAGE_PATH . 'bbb_logo.png');
156+
$this->assertIsString($content);
149157

150-
$file = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'bbb_logo.png');
151-
$this->assertIsString($file);
152-
$createMeetingParams->addPresentation('bbb_logo.png', $file);
153-
$this->assertXmlStringEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'presentation_with_embedded_file.xml', $createMeetingParams->getPresentationsAsXML());
158+
$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
154159
}
155160

156161
public function testParameterArray(): void

tests/Parameters/InsertDocumentParametersTest.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use BigBlueButton\Enum\DocumentOption;
2626
use BigBlueButton\Parameters\Config\DocumentOptions;
27+
use BigBlueButton\TestServices\Fixtures;
2728

2829
/**
2930
* @internal
@@ -32,16 +33,22 @@ final class InsertDocumentParametersTest extends ParameterTestCase
3233
{
3334
public function testInsertDocumentParameters(): void
3435
{
35-
$meetingId = $this->faker->uuid;
36-
$params = new InsertDocumentParameters($meetingId);
36+
$meetingId = $this->faker->uuid;
37+
$insertDocumentParameters = new InsertDocumentParameters($meetingId);
3738

38-
$params->addPresentation('https://demo.bigbluebutton.org/biglbuebutton.png');
39-
$params->addPresentation('https://demo.bigbluebutton.org/biglbuebutton.pdf');
40-
$params->addPresentation('https://demo.bigbluebutton.org/biglbuebutton.svg');
39+
$insertDocumentParameters
40+
->addPresentation('https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_100KB_PDF.pdf')
41+
->addPresentation('https://freetestdata.com/wp-content/uploads/2022/02/Free_Test_Data_117KB_JPG.jpg')
42+
->addPresentation('https://freetestdata.com/wp-content/uploads/2021/09/500kb.png')
43+
->addPresentation('https://freetestdata.com/wp-content/uploads/2021/09/1.svg')
44+
;
4145

42-
$this->assertEquals($meetingId, $params->getMeetingID());
46+
$this->assertEquals($meetingId, $insertDocumentParameters->getMeetingID());
4347

44-
$this->assertXmlStringEqualsXmlFile(dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'fixtures' . \DIRECTORY_SEPARATOR . 'insert_document_presentations.xml', $params->getPresentationsAsXML());
48+
$this->assertXmlStringEqualsXmlFile(
49+
Fixtures::REQUEST_PATH . 'insert_document_presentations.xml',
50+
$insertDocumentParameters->getPresentationsAsXML()
51+
);
4552
}
4653

4754
public function testInsertDocumentWithOptions(): void
@@ -60,8 +67,10 @@ public function testInsertDocumentWithOptions(): void
6067

6168
$this->assertEquals($meetingId, $insertDocumentParameters->getMeetingID());
6269

63-
$file = dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'fixtures' . \DIRECTORY_SEPARATOR . 'insert_document_presentations_with_options.xml';
64-
$this->assertXmlStringEqualsXmlFile($file, $insertDocumentParameters->getPresentationsAsXML());
70+
$this->assertXmlStringEqualsXmlFile(
71+
Fixtures::REQUEST_PATH . 'insert_document_presentations_with_options.xml',
72+
$insertDocumentParameters->getPresentationsAsXML()
73+
);
6574
}
6675

6776
public function testParameterArray(): void

tests/Responses/HooksCreateResponseTest.php

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,22 @@
2929
class HooksCreateResponseTest extends TestCase
3030
{
3131
private HooksCreateResponse $createResponseCreate;
32-
private HooksCreateResponse $createResponseError;
33-
private HooksCreateResponse $createResponseExisting;
34-
private HooksCreateResponse $createResponseNoHookId;
32+
private HooksCreateResponse $createResponseFailedError;
33+
private HooksCreateResponse $createResponseCreateExisting;
3534

3635
public function setUp(): void
3736
{
3837
parent::setUp();
3938

4039
$fixtures = new Fixtures();
4140

42-
$xmlCreate = $fixtures->fromXmlFile('hooks_create.xml');
43-
$xmlCreateError = $fixtures->fromXmlFile('hooks_create_error.xml');
44-
$xmlCreateExisting = $fixtures->fromXmlFile('hooks_create_existing.xml');
45-
$xmlCreateNoHookId = $fixtures->fromXmlFile('hooks_create_no_hook_id.xml');
41+
$xmlCreate = $fixtures->fromXmlFile('hooks_create.xml');
42+
$xmlCreateExisting = $fixtures->fromXmlFile('hooks_create_existing.xml');
43+
$xmlCreateFailedError = $fixtures->fromXmlFile('hooks_create_failed_error.xml');
4644

47-
$this->createResponseCreate = new HooksCreateResponse($xmlCreate);
48-
$this->createResponseError = new HooksCreateResponse($xmlCreateError);
49-
$this->createResponseExisting = new HooksCreateResponse($xmlCreateExisting);
50-
$this->createResponseNoHookId = new HooksCreateResponse($xmlCreateNoHookId);
45+
$this->createResponseCreate = new HooksCreateResponse($xmlCreate);
46+
$this->createResponseCreateExisting = new HooksCreateResponse($xmlCreateExisting);
47+
$this->createResponseFailedError = new HooksCreateResponse($xmlCreateFailedError);
5148
}
5249

5350
public function testHooksCreateResponseCreateContent(): void
@@ -63,35 +60,24 @@ public function testHooksCreateResponseCreateContent(): void
6360

6461
public function testHooksCreateResponseErrorContent(): void
6562
{
66-
$this->assertEquals('FAILED', $this->createResponseError->getReturnCode());
67-
$this->assertEquals('createHookError', $this->createResponseError->getMessageKey());
68-
$this->assertFalse($this->createResponseError->success());
69-
$this->assertTrue($this->createResponseError->failed());
70-
$this->assertNull($this->createResponseError->getHookId());
71-
$this->assertNull($this->createResponseError->isPermanentHook());
72-
$this->assertNull($this->createResponseError->hasRawData());
63+
$this->assertEquals('FAILED', $this->createResponseFailedError->getReturnCode());
64+
$this->assertEquals('createHookError', $this->createResponseFailedError->getMessageKey());
65+
$this->assertFalse($this->createResponseFailedError->success());
66+
$this->assertTrue($this->createResponseFailedError->failed());
67+
$this->assertNull($this->createResponseFailedError->getHookId());
68+
$this->assertNull($this->createResponseFailedError->isPermanentHook());
69+
$this->assertNull($this->createResponseFailedError->hasRawData());
7370
}
7471

7572
public function testHooksCreateResponseExistingContent(): void
7673
{
77-
$this->assertEquals('SUCCESS', $this->createResponseExisting->getReturnCode());
78-
$this->assertEquals('duplicateWarning', $this->createResponseExisting->getMessageKey());
79-
$this->assertTrue($this->createResponseExisting->success());
80-
$this->assertFalse($this->createResponseExisting->failed());
81-
$this->assertEquals(1, $this->createResponseExisting->getHookId());
82-
$this->assertNull($this->createResponseExisting->isPermanentHook());
83-
$this->assertNull($this->createResponseExisting->hasRawData());
84-
}
85-
86-
public function testHooksCreateResponseNoHookIdContent(): void
87-
{
88-
$this->assertEquals('FAILED', $this->createResponseNoHookId->getReturnCode());
89-
$this->assertEquals('missingParamHookID', $this->createResponseNoHookId->getMessageKey());
90-
$this->assertFalse($this->createResponseNoHookId->success());
91-
$this->assertTrue($this->createResponseNoHookId->failed());
92-
$this->assertNull($this->createResponseNoHookId->getHookId());
93-
$this->assertNull($this->createResponseNoHookId->isPermanentHook());
94-
$this->assertNull($this->createResponseNoHookId->hasRawData());
74+
$this->assertEquals('SUCCESS', $this->createResponseCreateExisting->getReturnCode());
75+
$this->assertEquals('duplicateWarning', $this->createResponseCreateExisting->getMessageKey());
76+
$this->assertTrue($this->createResponseCreateExisting->success());
77+
$this->assertFalse($this->createResponseCreateExisting->failed());
78+
$this->assertEquals(1, $this->createResponseCreateExisting->getHookId());
79+
$this->assertNull($this->createResponseCreateExisting->isPermanentHook());
80+
$this->assertNull($this->createResponseCreateExisting->hasRawData());
9581
}
9682

9783
public function testHooksCreateResponseTypes(): void
@@ -100,14 +86,11 @@ public function testHooksCreateResponseTypes(): void
10086
$this->assertEachGetterValueIsInteger($this->createResponseCreate, ['getHookId']);
10187
$this->assertEachGetterValueIsBoolean($this->createResponseCreate, ['isPermanentHook', 'hasRawData']);
10288

103-
$this->assertEachGetterValueIsString($this->createResponseError, ['getReturnCode']);
104-
$this->assertEachGetterValueIsNull($this->createResponseError, ['getHookId', 'isPermanentHook', 'hasRawData']);
105-
106-
$this->assertEachGetterValueIsString($this->createResponseExisting, ['getReturnCode']);
107-
$this->assertEachGetterValueIsInteger($this->createResponseExisting, ['getHookId']);
108-
$this->assertEachGetterValueIsNull($this->createResponseExisting, ['isPermanentHook', 'hasRawData']);
89+
$this->assertEachGetterValueIsString($this->createResponseFailedError, ['getReturnCode']);
90+
$this->assertEachGetterValueIsNull($this->createResponseFailedError, ['getHookId', 'isPermanentHook', 'hasRawData']);
10991

110-
$this->assertEachGetterValueIsString($this->createResponseNoHookId, ['getReturnCode']);
111-
$this->assertEachGetterValueIsNull($this->createResponseNoHookId, ['getHookId', 'isPermanentHook', 'hasRawData']);
92+
$this->assertEachGetterValueIsString($this->createResponseCreateExisting, ['getReturnCode']);
93+
$this->assertEachGetterValueIsInteger($this->createResponseCreateExisting, ['getHookId']);
94+
$this->assertEachGetterValueIsNull($this->createResponseCreateExisting, ['isPermanentHook', 'hasRawData']);
11295
}
11396
}

tests/Responses/HooksDestroyResponseTest.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@
2929
class HooksDestroyResponseTest extends TestCase
3030
{
3131
private HooksDestroyResponse $destroyResponse;
32-
private HooksDestroyResponse $destroyResponseError;
33-
private HooksDestroyResponse $destroyResponseNotFound;
34-
private HooksDestroyResponse $destroyResponseParamsNoId;
32+
private HooksDestroyResponse $destroyResponseFailedError;
33+
private HooksDestroyResponse $destroyResponseFailedNotFound;
34+
private HooksDestroyResponse $destroyResponseFailedNoId;
3535

3636
public function setUp(): void
3737
{
3838
parent::setUp();
3939

4040
$fixtures = new Fixtures();
4141

42-
$xml = $fixtures->fromXmlFile('hooks_destroy.xml');
43-
$xmlError = $fixtures->fromXmlFile('hooks_destroy_error.xml');
44-
$xmlNotFound = $fixtures->fromXmlFile('hooks_destroy_not_found.xml');
45-
$xmlParamsNoId = $fixtures->fromXmlFile('hooks_destroy_params_no_id.xml');
42+
$xml = $fixtures->fromXmlFile('hooks_destroy.xml');
43+
$xmlFailedError = $fixtures->fromXmlFile('hooks_destroy_failed_error.xml');
44+
$xmlFailedNoId = $fixtures->fromXmlFile('hooks_destroy_failed_no_id.xml');
45+
$xmlFailedNotFound = $fixtures->fromXmlFile('hooks_destroy_failed_not_found.xml');
4646

47-
$this->destroyResponse = new HooksDestroyResponse($xml);
48-
$this->destroyResponseError = new HooksDestroyResponse($xmlError);
49-
$this->destroyResponseNotFound = new HooksDestroyResponse($xmlNotFound);
50-
$this->destroyResponseParamsNoId = new HooksDestroyResponse($xmlParamsNoId);
47+
$this->destroyResponse = new HooksDestroyResponse($xml);
48+
$this->destroyResponseFailedError = new HooksDestroyResponse($xmlFailedError);
49+
$this->destroyResponseFailedNoId = new HooksDestroyResponse($xmlFailedNoId);
50+
$this->destroyResponseFailedNotFound = new HooksDestroyResponse($xmlFailedNotFound);
5151
}
5252

5353
public function testHooksDestroyResponseContent(): void
@@ -59,37 +59,37 @@ public function testHooksDestroyResponseContent(): void
5959

6060
public function testHooksDestroyErrorResponseContent(): void
6161
{
62-
$this->assertEquals('FAILED', $this->destroyResponseError->getReturnCode());
63-
$this->assertEquals('destroyHookError', $this->destroyResponseError->getMessageKey());
64-
$this->assertNull($this->destroyResponseError->removed());
62+
$this->assertEquals('FAILED', $this->destroyResponseFailedError->getReturnCode());
63+
$this->assertEquals('destroyHookError', $this->destroyResponseFailedError->getMessageKey());
64+
$this->assertNull($this->destroyResponseFailedError->removed());
6565
}
6666

6767
public function testHooksDestroyNotFoundResponseContent(): void
6868
{
69-
$this->assertEquals('FAILED', $this->destroyResponseNotFound->getReturnCode());
70-
$this->assertEquals('destroyMissingHook', $this->destroyResponseNotFound->getMessageKey());
71-
$this->assertNull($this->destroyResponseNotFound->removed());
69+
$this->assertEquals('FAILED', $this->destroyResponseFailedNotFound->getReturnCode());
70+
$this->assertEquals('destroyMissingHook', $this->destroyResponseFailedNotFound->getMessageKey());
71+
$this->assertNull($this->destroyResponseFailedNotFound->removed());
7272
}
7373

7474
public function testHooksDestroyParamsNoIdContent(): void
7575
{
76-
$this->assertEquals('FAILED', $this->destroyResponseParamsNoId->getReturnCode());
77-
$this->assertEquals('missingParamHookID', $this->destroyResponseParamsNoId->getMessageKey());
78-
$this->assertNull($this->destroyResponseParamsNoId->removed());
76+
$this->assertEquals('FAILED', $this->destroyResponseFailedNoId->getReturnCode());
77+
$this->assertEquals('missingParamHookID', $this->destroyResponseFailedNoId->getMessageKey());
78+
$this->assertNull($this->destroyResponseFailedNoId->removed());
7979
}
8080

8181
public function testHooksDestroyResponseTypes(): void
8282
{
8383
$this->assertEachGetterValueIsString($this->destroyResponse, ['getReturnCode']);
8484
$this->assertEachGetterValueIsBoolean($this->destroyResponse, ['removed']);
8585

86-
$this->assertEachGetterValueIsString($this->destroyResponseError, ['getReturnCode']);
87-
$this->assertEachGetterValueIsNull($this->destroyResponseError, ['removed']);
86+
$this->assertEachGetterValueIsString($this->destroyResponseFailedError, ['getReturnCode']);
87+
$this->assertEachGetterValueIsNull($this->destroyResponseFailedError, ['removed']);
8888

89-
$this->assertEachGetterValueIsString($this->destroyResponseNotFound, ['getReturnCode']);
90-
$this->assertEachGetterValueIsNull($this->destroyResponseNotFound, ['removed']);
89+
$this->assertEachGetterValueIsString($this->destroyResponseFailedNotFound, ['getReturnCode']);
90+
$this->assertEachGetterValueIsNull($this->destroyResponseFailedNotFound, ['removed']);
9191

92-
$this->assertEachGetterValueIsString($this->destroyResponseParamsNoId, ['getReturnCode']);
93-
$this->assertEachGetterValueIsNull($this->destroyResponseParamsNoId, ['removed']);
92+
$this->assertEachGetterValueIsString($this->destroyResponseFailedNoId, ['getReturnCode']);
93+
$this->assertEachGetterValueIsNull($this->destroyResponseFailedNoId, ['removed']);
9494
}
9595
}

0 commit comments

Comments
 (0)