. */ namespace Xibo\Tests\Xmds; use PHPUnit\Framework\Attributes\DataProvider; use Xibo\Tests\XmdsTestCase; /** * Various Notify Status tests */ final class NotifyStatusTest extends XmdsTestCase { use XmdsHelperTrait; public function setUp(): void { parent::setUp(); } public static function successCases(): array { return [ [7], [6], [5], [4], ]; } public static function failureCases(): array { return [ [3], ]; } #[DataProvider('successCases')] public function testCurrentLayout(int $version) { $request = $this->sendRequest('POST', $this->notifyStatus($version, '{"currentLayoutId":1}'), $version); $this->assertStringContainsString( 'true', $request->getBody()->getContents(), 'Notify Current Layout received incorrect response' ); } #[DataProvider('failureCases')] public function testCurrentLayoutFailure(int $version) { // disable exception on http_error in guzzle, so we can still check the response $request = $this->sendRequest( 'POST', $this->notifyStatus($version, '{"currentLayoutId":1}'), $version, false ); $this->assertSame(500, $request->getStatusCode()); // check the fault code $this->assertStringContainsString( 'SOAP-ENV:Server', $request->getBody(), 'Notify Current Layout received incorrect response' ); // check the fault string $this->assertStringContainsString( 'Procedure \'NotifyStatus\' not present', $request->getBody(), 'Notify Current Layout received incorrect response' ); } #[DataProvider('failureCases')] public function testCurrentLayoutExceptionFailure(int $version) { // we are expecting 500 Server Exception here for xmds 3 $this->expectException('GuzzleHttp\Exception\ServerException'); $this->expectExceptionCode(500); $request = $this->sendRequest('POST', $this->notifyStatus($version, '{"currentLayoutId":1}'), $version); } #[DataProvider('successCases')] public function testGeoLocation($version) { $request = $this->sendRequest( 'POST', $this->notifyStatus($version, '{"latitude":52.3676, "longitude":4.9041}'), $version ); $this->assertStringContainsString( 'true', $request->getBody()->getContents(), 'Notify Geo Location received incorrect response' ); } #[DataProvider('failureCases')] public function testGeoLocationFailure(int $version) { // disable exception on http_error in guzzle, so we can still check the response $request = $this->sendRequest( 'POST', $this->notifyStatus($version, '{"latitude":52.3676, "longitude":4.9041}'), $version, false ); $this->assertSame(500, $request->getStatusCode()); // check the fault code $this->assertStringContainsString( 'SOAP-ENV:Server', $request->getBody(), 'Notify Geo Location received incorrect response' ); // check the fault string $this->assertStringContainsString( 'Procedure \'NotifyStatus\' not present', $request->getBody(), 'Notify Geo Location received incorrect response' ); } #[DataProvider('failureCases')] public function testGeoLocationExceptionFailure(int $version) { // we are expecting 500 Server Exception here for xmds 3 $this->expectException('GuzzleHttp\Exception\ServerException'); $this->expectExceptionCode(500); $this->sendRequest( 'POST', $this->notifyStatus($version, '{"latitude":52.3676, "longitude":4.9041}'), $version, ); } #[DataProvider('successCases')] public function testOrientation(int $version) { $request = $this->sendRequest( 'POST', $this->notifyStatus($version, '{"width":7680, "height":4320}'), $version, ); $this->assertStringContainsString( 'true', $request->getBody()->getContents(), 'Notify Orientation received incorrect response' ); } #[DataProvider('failureCases')] public function testOrientationFailure(int $version) { // disable exception on http_error in guzzle, so we can still check the response $request = $this->sendRequest( 'POST', $this->notifyStatus($version, '{"width":7680, "height":4320}'), $version, false ); $this->assertSame(500, $request->getStatusCode()); // check the fault code $this->assertStringContainsString( 'SOAP-ENV:Server', $request->getBody(), 'Notify Orientation received incorrect response' ); // check the fault string $this->assertStringContainsString( 'Procedure \'NotifyStatus\' not present', $request->getBody(), 'Notify Orientation received incorrect response' ); } #[DataProvider('failureCases')] public function testOrientationExceptionFailure(int $version) { // we are expecting 500 Server Exception here for xmds 3 $this->expectException('GuzzleHttp\Exception\ServerException'); $this->expectExceptionCode(500); $this->sendRequest( 'POST', $this->notifyStatus($version, '{"width":7680, "height":4320}'), $version, ); } }