Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixure files (and other stuff) #234

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"name": "Ghazi Triki",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "Tim Korn",
"email": "[email protected]",
"role": "Developer"
}
],
"repositories": {
Expand Down
27 changes: 26 additions & 1 deletion src/Parameters/DocumentableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getPresentations(): array
return $this->presentations;
}

public function addPresentation(string $nameOrUrl, ?string $content = null, ?string $filename = null, DocumentOptions $documentOptions = null): self
public function addPresentation(string $nameOrUrl, ?string $content = null, ?string $filename = null, ?DocumentOptions $documentOptions = null): self
{
$this->presentations[$nameOrUrl] = [
'content' => $content ? base64_encode($content) : null,
Expand All @@ -58,6 +58,7 @@ public function getPresentationsAsXML(): string

foreach ($this->presentations as $nameOrUrl => $data) {
$presentation = $module->addChild('document');

if (0 === mb_strpos($nameOrUrl, 'http')) {
$presentation->addAttribute('url', $nameOrUrl);
} else {
Expand Down Expand Up @@ -89,4 +90,28 @@ public function getPresentationsAsXML(): string

return $result;
}

private function urlExists(string $url): bool
{
$ch = curl_init($url);

if (!$ch) {
throw new \RuntimeException('Unhandled curl error!');
}

curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if ($httpCode >= 200 && $httpCode < 400) {
return true;
}

return false;
}
}
11 changes: 8 additions & 3 deletions tests/BigBlueButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ public function testCreateMeetingWithDocumentUrlAndFileName(): void
*/
public function testCreateMeetingWithDocumentEmbedded(): void
{
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$content = file_get_contents(Fixtures::IMAGE_PATH . 'bbb_logo.png');
$this->assertIsString($content);

$params->addPresentation('bbb_logo.png', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'bbb_logo.png'));
$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$params->addPresentation('bbb_logo.png', $content);

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

Expand All @@ -165,9 +167,12 @@ public function testCreateMeetingWithDocumentEmbedded(): void
*/
public function testCreateMeetingWithMultiDocument(): void
{
$content = file_get_contents(Fixtures::IMAGE_PATH . 'bbb_logo.png');
$this->assertIsString($content);

$params = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$params->addPresentation('https://picsum.photos/3840/2160/?random', null, 'presentation.png');
$params->addPresentation('logo.png', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'bbb_logo.png'));
$params->addPresentation('logo.png', $content);

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

Expand Down
16 changes: 10 additions & 6 deletions tests/Parameters/CreateMeetingParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,25 @@ public function testCreateBreakoutMeeting(): void
public function testGetPresentationsAsXMLWithUrl(): void
{
$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$createMeetingParams->addPresentation('http://test-install.blindsidenetworks.com/default.pdf');
$this->assertXmlStringEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'presentation_with_url.xml', $createMeetingParams->getPresentationsAsXML());
$createMeetingParams->addPresentation('https://test-install.blindsidenetworks.com/default.pdf');
$this->assertXmlStringEqualsXmlFile(Fixtures::REQUEST_PATH . 'presentation_with_url.xml', $createMeetingParams->getPresentationsAsXML());
}

public function testGetPresentationsAsXMLWithUrlAndFilename(): void
{
$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$createMeetingParams->addPresentation('http://test-install.blindsidenetworks.com/default.pdf', null, 'presentation.pdf');
$this->assertXmlStringEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'presentation_with_filename.xml', $createMeetingParams->getPresentationsAsXML());
$createMeetingParams->addPresentation('https://test-install.blindsidenetworks.com/default.pdf', null, 'presentation.pdf');
$this->assertXmlStringEqualsXmlFile(Fixtures::REQUEST_PATH . 'presentation_with_filename.xml', $createMeetingParams->getPresentationsAsXML());
}

public function testGetPresentationsAsXMLWithFile(): void
{
$content = file_get_contents(Fixtures::IMAGE_PATH . 'bbb_logo.png');
$this->assertIsString($content);

$createMeetingParams = Fixtures::getCreateMeetingParametersMock(Fixtures::generateCreateParams());
$createMeetingParams->addPresentation('bbb_logo.png', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'bbb_logo.png'));
$this->assertXmlStringEqualsXmlFile(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'fixtures' . DIRECTORY_SEPARATOR . 'presentation_with_embedded_file.xml', $createMeetingParams->getPresentationsAsXML());
$createMeetingParams->addPresentation('bbb_logo.png', $content);

$this->assertXmlStringEqualsXmlFile(Fixtures::REQUEST_PATH . 'presentation_with_embedded_file.xml', $createMeetingParams->getPresentationsAsXML());
}
}
27 changes: 18 additions & 9 deletions tests/Parameters/InsertDocumentParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use BigBlueButton\Enum\DocumentOption;
use BigBlueButton\Parameters\Config\DocumentOptions;
use BigBlueButton\TestCase;
use BigBlueButton\TestServices\Fixtures;

/**
* @internal
Expand All @@ -33,16 +34,22 @@ final class InsertDocumentParametersTest extends TestCase
{
public function testInsertDocumentParameters(): void
{
$meetingId = $this->faker->uuid;
$params = new InsertDocumentParameters($meetingId);
$meetingId = $this->faker->uuid;
$insertDocumentParameters = new InsertDocumentParameters($meetingId);

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

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

$this->assertXmlStringEqualsXmlFile(dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'fixtures' . \DIRECTORY_SEPARATOR . 'insert_document_presentations.xml', $params->getPresentationsAsXML());
$this->assertXmlStringEqualsXmlFile(
Fixtures::REQUEST_PATH . 'insert_document_presentations.xml',
$insertDocumentParameters->getPresentationsAsXML()
);
}

public function testInsertDocumentWithOptions(): void
Expand All @@ -61,7 +68,9 @@ public function testInsertDocumentWithOptions(): void

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

$file = dirname(__DIR__) . \DIRECTORY_SEPARATOR . 'fixtures' . \DIRECTORY_SEPARATOR . 'insert_document_presentations_with_options.xml';
$this->assertXmlStringEqualsXmlFile($file, $insertDocumentParameters->getPresentationsAsXML());
$this->assertXmlStringEqualsXmlFile(
Fixtures::REQUEST_PATH . 'insert_document_presentations_with_options.xml',
$insertDocumentParameters->getPresentationsAsXML()
);
}
}
71 changes: 27 additions & 44 deletions tests/Responses/HooksCreateResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,22 @@
class HooksCreateResponseTest extends TestCase
{
private HooksCreateResponse $createResponseCreate;
private HooksCreateResponse $createResponseError;
private HooksCreateResponse $createResponseExisting;
private HooksCreateResponse $createResponseNoHookId;
private HooksCreateResponse $createResponseFailedError;
private HooksCreateResponse $createResponseCreateExisting;

public function setUp(): void
{
parent::setUp();

$fixtures = new Fixtures();

$xmlCreate = $fixtures->fromXmlFile('hooks_create.xml');
$xmlCreateError = $fixtures->fromXmlFile('hooks_create_error.xml');
$xmlCreateExisting = $fixtures->fromXmlFile('hooks_create_existing.xml');
$xmlCreateNoHookId = $fixtures->fromXmlFile('hooks_create_no_hook_id.xml');
$xmlCreate = $fixtures->fromXmlFile('hooks_create.xml');
$xmlCreateExisting = $fixtures->fromXmlFile('hooks_create_existing.xml');
$xmlCreateFailedError = $fixtures->fromXmlFile('hooks_create_failed_error.xml');

$this->createResponseCreate = new HooksCreateResponse($xmlCreate);
$this->createResponseError = new HooksCreateResponse($xmlCreateError);
$this->createResponseExisting = new HooksCreateResponse($xmlCreateExisting);
$this->createResponseNoHookId = new HooksCreateResponse($xmlCreateNoHookId);
$this->createResponseCreate = new HooksCreateResponse($xmlCreate);
$this->createResponseCreateExisting = new HooksCreateResponse($xmlCreateExisting);
$this->createResponseFailedError = new HooksCreateResponse($xmlCreateFailedError);
}

public function testHooksCreateResponseCreateContent(): void
Expand All @@ -63,35 +60,24 @@ public function testHooksCreateResponseCreateContent(): void

public function testHooksCreateResponseErrorContent(): void
{
$this->assertEquals('FAILED', $this->createResponseError->getReturnCode());
$this->assertEquals('createHookError', $this->createResponseError->getMessageKey());
$this->assertFalse($this->createResponseError->success());
$this->assertTrue($this->createResponseError->failed());
$this->assertNull($this->createResponseError->getHookId());
$this->assertNull($this->createResponseError->isPermanentHook());
$this->assertNull($this->createResponseError->hasRawData());
$this->assertEquals('FAILED', $this->createResponseFailedError->getReturnCode());
$this->assertEquals('createHookError', $this->createResponseFailedError->getMessageKey());
$this->assertFalse($this->createResponseFailedError->success());
$this->assertTrue($this->createResponseFailedError->failed());
$this->assertNull($this->createResponseFailedError->getHookId());
$this->assertNull($this->createResponseFailedError->isPermanentHook());
$this->assertNull($this->createResponseFailedError->hasRawData());
}

public function testHooksCreateResponseExistingContent(): void
{
$this->assertEquals('SUCCESS', $this->createResponseExisting->getReturnCode());
$this->assertEquals('duplicateWarning', $this->createResponseExisting->getMessageKey());
$this->assertTrue($this->createResponseExisting->success());
$this->assertFalse($this->createResponseExisting->failed());
$this->assertEquals(1, $this->createResponseExisting->getHookId());
$this->assertNull($this->createResponseExisting->isPermanentHook());
$this->assertNull($this->createResponseExisting->hasRawData());
}

public function testHooksCreateResponseNoHookIdContent(): void
{
$this->assertEquals('FAILED', $this->createResponseNoHookId->getReturnCode());
$this->assertEquals('missingParamHookID', $this->createResponseNoHookId->getMessageKey());
$this->assertFalse($this->createResponseNoHookId->success());
$this->assertTrue($this->createResponseNoHookId->failed());
$this->assertNull($this->createResponseNoHookId->getHookId());
$this->assertNull($this->createResponseNoHookId->isPermanentHook());
$this->assertNull($this->createResponseNoHookId->hasRawData());
$this->assertEquals('SUCCESS', $this->createResponseCreateExisting->getReturnCode());
$this->assertEquals('duplicateWarning', $this->createResponseCreateExisting->getMessageKey());
$this->assertTrue($this->createResponseCreateExisting->success());
$this->assertFalse($this->createResponseCreateExisting->failed());
$this->assertEquals(1, $this->createResponseCreateExisting->getHookId());
$this->assertNull($this->createResponseCreateExisting->isPermanentHook());
$this->assertNull($this->createResponseCreateExisting->hasRawData());
}

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

$this->assertEachGetterValueIsString($this->createResponseError, ['getReturnCode']);
$this->assertEachGetterValueIsNull($this->createResponseError, ['getHookId', 'isPermanentHook', 'hasRawData']);

$this->assertEachGetterValueIsString($this->createResponseExisting, ['getReturnCode']);
$this->assertEachGetterValueIsInteger($this->createResponseExisting, ['getHookId']);
$this->assertEachGetterValueIsNull($this->createResponseExisting, ['isPermanentHook', 'hasRawData']);
$this->assertEachGetterValueIsString($this->createResponseFailedError, ['getReturnCode']);
$this->assertEachGetterValueIsNull($this->createResponseFailedError, ['getHookId', 'isPermanentHook', 'hasRawData']);

$this->assertEachGetterValueIsString($this->createResponseNoHookId, ['getReturnCode']);
$this->assertEachGetterValueIsNull($this->createResponseNoHookId, ['getHookId', 'isPermanentHook', 'hasRawData']);
$this->assertEachGetterValueIsString($this->createResponseCreateExisting, ['getReturnCode']);
$this->assertEachGetterValueIsInteger($this->createResponseCreateExisting, ['getHookId']);
$this->assertEachGetterValueIsNull($this->createResponseCreateExisting, ['isPermanentHook', 'hasRawData']);
}
}
52 changes: 26 additions & 26 deletions tests/Responses/HooksDestroyResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@
class HooksDestroyResponseTest extends TestCase
{
private HooksDestroyResponse $destroyResponse;
private HooksDestroyResponse $destroyResponseError;
private HooksDestroyResponse $destroyResponseNotFound;
private HooksDestroyResponse $destroyResponseParamsNoId;
private HooksDestroyResponse $destroyResponseFailedError;
private HooksDestroyResponse $destroyResponseFailedNotFound;
private HooksDestroyResponse $destroyResponseFailedNoId;

public function setUp(): void
{
parent::setUp();

$fixtures = new Fixtures();

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

$this->destroyResponse = new HooksDestroyResponse($xml);
$this->destroyResponseError = new HooksDestroyResponse($xmlError);
$this->destroyResponseNotFound = new HooksDestroyResponse($xmlNotFound);
$this->destroyResponseParamsNoId = new HooksDestroyResponse($xmlParamsNoId);
$this->destroyResponse = new HooksDestroyResponse($xml);
$this->destroyResponseFailedError = new HooksDestroyResponse($xmlFailedError);
$this->destroyResponseFailedNoId = new HooksDestroyResponse($xmlFailedNoId);
$this->destroyResponseFailedNotFound = new HooksDestroyResponse($xmlFailedNotFound);
}

public function testHooksDestroyResponseContent(): void
Expand All @@ -59,37 +59,37 @@ public function testHooksDestroyResponseContent(): void

public function testHooksDestroyErrorResponseContent(): void
{
$this->assertEquals('FAILED', $this->destroyResponseError->getReturnCode());
$this->assertEquals('destroyHookError', $this->destroyResponseError->getMessageKey());
$this->assertNull($this->destroyResponseError->removed());
$this->assertEquals('FAILED', $this->destroyResponseFailedError->getReturnCode());
$this->assertEquals('destroyHookError', $this->destroyResponseFailedError->getMessageKey());
$this->assertNull($this->destroyResponseFailedError->removed());
}

public function testHooksDestroyNotFoundResponseContent(): void
{
$this->assertEquals('FAILED', $this->destroyResponseNotFound->getReturnCode());
$this->assertEquals('destroyMissingHook', $this->destroyResponseNotFound->getMessageKey());
$this->assertNull($this->destroyResponseNotFound->removed());
$this->assertEquals('FAILED', $this->destroyResponseFailedNotFound->getReturnCode());
$this->assertEquals('destroyMissingHook', $this->destroyResponseFailedNotFound->getMessageKey());
$this->assertNull($this->destroyResponseFailedNotFound->removed());
}

public function testHooksDestroyParamsNoIdContent(): void
{
$this->assertEquals('FAILED', $this->destroyResponseParamsNoId->getReturnCode());
$this->assertEquals('missingParamHookID', $this->destroyResponseParamsNoId->getMessageKey());
$this->assertNull($this->destroyResponseParamsNoId->removed());
$this->assertEquals('FAILED', $this->destroyResponseFailedNoId->getReturnCode());
$this->assertEquals('missingParamHookID', $this->destroyResponseFailedNoId->getMessageKey());
$this->assertNull($this->destroyResponseFailedNoId->removed());
}

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

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

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

$this->assertEachGetterValueIsString($this->destroyResponseParamsNoId, ['getReturnCode']);
$this->assertEachGetterValueIsNull($this->destroyResponseParamsNoId, ['removed']);
$this->assertEachGetterValueIsString($this->destroyResponseFailedNoId, ['getReturnCode']);
$this->assertEachGetterValueIsNull($this->destroyResponseFailedNoId, ['removed']);
}
}
Loading