|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace VonageTest\Verify2\Request; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Vonage\Client; |
| 9 | +use Vonage\Verify2\Request\BaseVerifyRequest; |
| 10 | +use Vonage\Verify2\Request\SilentAuthRequest; |
| 11 | +use Vonage\Verify2\Request\SMSRequest; |
| 12 | +use Vonage\Verify2\VerifyObjects\VerificationLocale; |
| 13 | +use Vonage\Verify2\VerifyObjects\VerificationWorkflow; |
| 14 | + |
| 15 | +class SilentAuthRequestTest extends TestCase |
| 16 | +{ |
| 17 | + public function testIsValidSilentAuthRequest(): void |
| 18 | + { |
| 19 | + $silentAuthRequest = new SilentAuthRequest( |
| 20 | + '077377775555', |
| 21 | + 'VONAGE', |
| 22 | + 'https://silent-auth.example' |
| 23 | + ); |
| 24 | + |
| 25 | + $extraWorkflow = new VerificationWorkflow( |
| 26 | + VerificationWorkflow::WORKFLOW_SMS, |
| 27 | + '077377775555' |
| 28 | + ); |
| 29 | + |
| 30 | + $silentAuthRequest->addWorkflow($extraWorkflow); |
| 31 | + |
| 32 | + $client = new Client(new Client\Credentials\Basic('test', 'test2')); |
| 33 | + $this->assertTrue($client->verify2()::isSilentAuthRequest($silentAuthRequest)); |
| 34 | + $this->assertTrue(SilentAuthRequest::isValidWorkflow($silentAuthRequest->getWorkflows())); |
| 35 | + } |
| 36 | + |
| 37 | + public function testIsInvalidSilentAuthRequest(): void |
| 38 | + { |
| 39 | + $request = new SMSRequest( |
| 40 | + '077377775555', |
| 41 | + 'VONAGE', |
| 42 | + ); |
| 43 | + |
| 44 | + $extraWorkflow = new VerificationWorkflow( |
| 45 | + VerificationWorkflow::WORKFLOW_SILENT_AUTH, |
| 46 | + '077377775555' |
| 47 | + ); |
| 48 | + |
| 49 | + $request->addWorkflow($extraWorkflow); |
| 50 | + $client = new Client(new Client\Credentials\Basic('test', 'test2')); |
| 51 | + |
| 52 | + $this->assertTrue($client->verify2()::isSilentAuthRequest($request)); |
| 53 | + $this->assertFalse(SilentAuthRequest::isValidWorkflow($request->getWorkflows())); |
| 54 | + } |
| 55 | + |
| 56 | + public function testIsNotSilentAuthRequest(): void |
| 57 | + { |
| 58 | + $request = new SMSRequest( |
| 59 | + '077377775555', |
| 60 | + 'VONAGE', |
| 61 | + ); |
| 62 | + |
| 63 | + $extraWorkflow = new VerificationWorkflow( |
| 64 | + VerificationWorkflow::WORKFLOW_EMAIL, |
| 65 | + 'jim@jim.com' |
| 66 | + ); |
| 67 | + |
| 68 | + $request->addWorkflow($extraWorkflow); |
| 69 | + $client = new Client(new Client\Credentials\Basic('test', 'test2')); |
| 70 | + |
| 71 | + $this->assertFalse($client->verify2()::isSilentAuthRequest($request)); |
| 72 | + // No second test to see if the workflow is valid, why are you checking a workflow on a non SA request? |
| 73 | + } |
| 74 | +} |
0 commit comments