|
7 | 7 | use OpenTok\OpenTok; |
8 | 8 | use OpenTok\MediaMode; |
9 | 9 | use ArgumentCountError; |
| 10 | +use DomainException; |
| 11 | +use Exception; |
| 12 | +use GuzzleHttp\Exception\GuzzleException; |
10 | 13 | use OpenTok\OutputMode; |
11 | 14 | use OpenTok\ArchiveMode; |
12 | 15 | use OpenTok\Util\Client; |
13 | 16 | use GuzzleHttp\Middleware; |
14 | 17 | use GuzzleHttp\HandlerStack; |
15 | 18 | use PHPUnit\Framework\TestCase; |
16 | 19 | use GuzzleHttp\Handler\MockHandler; |
| 20 | +use InvalidArgumentException as GlobalInvalidArgumentException; |
| 21 | +use OpenTok\Exception\AuthenticationException; |
| 22 | +use OpenTok\Exception\DomainException as ExceptionDomainException; |
17 | 23 | use OpenTok\Exception\InvalidArgumentException; |
| 24 | +use RuntimeException; |
| 25 | +use OpenTok\Exception\UnexpectedValueException; |
18 | 26 |
|
19 | 27 | define('OPENTOK_DEBUG', true); |
20 | 28 |
|
@@ -1633,6 +1641,118 @@ public function testSipCallFrom() |
1633 | 1641 | $this->assertEquals($from, $body->sip->from); |
1634 | 1642 | } |
1635 | 1643 |
|
| 1644 | + public function testSipCallVideo() |
| 1645 | + { |
| 1646 | + // Arrange |
| 1647 | + $this->setupOTWithMocks([[ |
| 1648 | + 'code' => 200, |
| 1649 | + 'headers' => [ |
| 1650 | + 'Content-Type' => 'application/json' |
| 1651 | + ], |
| 1652 | + 'path' => 'v2/project/APIKEY/dial' |
| 1653 | + ]]); |
| 1654 | + |
| 1655 | + $sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI'; |
| 1656 | + $bogusToken = 'T1==TEST'; |
| 1657 | + $bogusSipUri = 'sip:[email protected]'; |
| 1658 | + |
| 1659 | + // Act |
| 1660 | + $sipCall = $this->opentok->dial($sessionId, $bogusToken, $bogusSipUri, ['video' => true]); |
| 1661 | + |
| 1662 | + // Assert |
| 1663 | + $this->assertInstanceOf('OpenTok\SipCall', $sipCall); |
| 1664 | + $this->assertNotNull($sipCall->id); |
| 1665 | + $this->assertNotNull($sipCall->connectionId); |
| 1666 | + $this->assertNotNull($sipCall->streamId); |
| 1667 | + |
| 1668 | + $this->assertCount(1, $this->historyContainer); |
| 1669 | + $request = $this->historyContainer[0]['request']; |
| 1670 | + |
| 1671 | + $body = json_decode($request->getBody()); |
| 1672 | + $this->assertEquals(true, $body->sip->video); |
| 1673 | + } |
| 1674 | + |
| 1675 | + public function testPlayDTMF() |
| 1676 | + { |
| 1677 | + $this->setupOTWithMocks([[ |
| 1678 | + 'code' => 200, |
| 1679 | + 'headers' => [ |
| 1680 | + 'Content-Type' => 'application/json' |
| 1681 | + ], |
| 1682 | + 'path' => 'v2/project/APIKEY/session/SESSIONID/play-dtmf' |
| 1683 | + ]]); |
| 1684 | + |
| 1685 | + $sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI'; |
| 1686 | + $digits = '1p713#'; |
| 1687 | + |
| 1688 | + $this->opentok->playDTMF($sessionId, $digits); |
| 1689 | + |
| 1690 | + $this->assertCount(1, $this->historyContainer); |
| 1691 | + $request = $this->historyContainer[0]['request']; |
| 1692 | + |
| 1693 | + $body = json_decode($request->getBody()); |
| 1694 | + $this->assertEquals($digits, $body->digits); |
| 1695 | + } |
| 1696 | + |
| 1697 | + public function testPlayDTMFIntoConnection() |
| 1698 | + { |
| 1699 | + $this->setupOTWithMocks([[ |
| 1700 | + 'code' => 200, |
| 1701 | + 'headers' => [ |
| 1702 | + 'Content-Type' => 'application/json' |
| 1703 | + ], |
| 1704 | + 'path' => 'v2/project/APIKEY/session/SESSIONID/play-dtmf' |
| 1705 | + ]]); |
| 1706 | + |
| 1707 | + $sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI'; |
| 1708 | + $connectionId = 'da9cb410-e29b-4c2d-ab9e-fe65bf83fcaf'; |
| 1709 | + $digits = '1p713#'; |
| 1710 | + |
| 1711 | + $this->opentok->playDTMF($sessionId, $digits, $connectionId); |
| 1712 | + |
| 1713 | + $this->assertCount(1, $this->historyContainer); |
| 1714 | + $request = $this->historyContainer[0]['request']; |
| 1715 | + |
| 1716 | + $body = json_decode($request->getBody()); |
| 1717 | + $this->assertEquals($digits, $body->digits); |
| 1718 | + } |
| 1719 | + |
| 1720 | + public function testDTMFFailsValidation() |
| 1721 | + { |
| 1722 | + $this->expectException(\InvalidArgumentException::class); |
| 1723 | + $this->expectExceptionMessage('DTMF digits can only support 0-9, p, #, and * characters'); |
| 1724 | + |
| 1725 | + $this->setupOT(); |
| 1726 | + $sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI'; |
| 1727 | + $this->opentok->playDTMF($sessionId, 'bob'); |
| 1728 | + } |
| 1729 | + |
| 1730 | + /** |
| 1731 | + * Tests that we properly handle a 400 error from the API |
| 1732 | + * Ideally with the validator we fail before the API request is even made, |
| 1733 | + * but this will make sure that we still properly handle a 400 error. For |
| 1734 | + * this to work we do send a valid DTMF string however, to satisfy the |
| 1735 | + * validator. |
| 1736 | + */ |
| 1737 | + public function testPlayDTMFThrows400(): void |
| 1738 | + { |
| 1739 | + $this->expectException(DomainException::class); |
| 1740 | + $this->expectExceptionMessage('The OpenTok API request failed: Invalid DTMF Digits'); |
| 1741 | + |
| 1742 | + $this->setupOTWithMocks([[ |
| 1743 | + 'code' => 400, |
| 1744 | + 'headers' => [ |
| 1745 | + 'Content-Type' => 'application/json' |
| 1746 | + ], |
| 1747 | + 'path' => 'v2/project/APIKEY/session/SESSIONID/play-dtmf-400' |
| 1748 | + ]]); |
| 1749 | + |
| 1750 | + $sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI'; |
| 1751 | + $digits = '1p713#'; |
| 1752 | + |
| 1753 | + $this->opentok->playDTMF($sessionId, $digits); |
| 1754 | + } |
| 1755 | + |
1636 | 1756 | public function testSignalData() |
1637 | 1757 | { |
1638 | 1758 | // Arrange |
|
0 commit comments