@@ -1617,6 +1617,207 @@ public function testGetsExpiredArchive(): void
16171617 $ this ->assertEquals ("expired " , $ archive ->status );
16181618 }
16191619
1620+ public function testStartsArchiveWithTranscription (): void
1621+ {
1622+ // Arrange
1623+ $ this ->setupOTWithMocks ([[
1624+ 'code ' => 200 ,
1625+ 'headers ' => [
1626+ 'Content-Type ' => 'application/json '
1627+ ],
1628+ 'path ' => 'v2/project/APIKEY/archive/session_hasTranscription-true '
1629+ ]]);
1630+
1631+ // This sessionId was generated using a different apiKey, but this method doesn't do any
1632+ // decoding to check, so it's fine.
1633+ $ sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh- ' ;
1634+
1635+ // Act
1636+ $ archive = $ this ->opentok ->startArchive ($ sessionId , [
1637+ 'hasTranscription ' => true ,
1638+ 'transcriptionProperties ' => [
1639+ 'primaryLanguageCode ' => 'en-US ' ,
1640+ 'hasSummary ' => false
1641+ ]
1642+ ]);
1643+
1644+ // Assert
1645+ $ this ->assertCount (1 , $ this ->historyContainer );
1646+
1647+ $ request = $ this ->historyContainer [0 ]['request ' ];
1648+ $ this ->assertEquals ('POST ' , strtoupper ($ request ->getMethod ()));
1649+ $ this ->assertEquals ('/v2/project/ ' . $ this ->API_KEY . '/archive ' , $ request ->getUri ()->getPath ());
1650+ $ this ->assertEquals ('api.opentok.com ' , $ request ->getUri ()->getHost ());
1651+ $ this ->assertEquals ('https ' , $ request ->getUri ()->getScheme ());
1652+
1653+ $ contentType = $ request ->getHeaderLine ('Content-Type ' );
1654+ $ this ->assertNotEmpty ($ contentType );
1655+ $ this ->assertEquals ('application/json ' , $ contentType );
1656+
1657+ $ authString = $ request ->getHeaderLine ('X-OPENTOK-AUTH ' );
1658+ $ this ->assertEquals (true , TestHelpers::validateOpenTokAuthHeader ($ this ->API_KEY , $ this ->API_SECRET , $ authString ));
1659+
1660+ // Test request body contains transcription fields
1661+ $ body = json_decode ($ request ->getBody ());
1662+ $ this ->assertEquals (true , $ body ->hasTranscription );
1663+ $ this ->assertEquals ('en-US ' , $ body ->transcriptionProperties ->primaryLanguageCode );
1664+ $ this ->assertEquals (false , $ body ->transcriptionProperties ->hasSummary );
1665+
1666+ // Test response properties
1667+ $ this ->assertInstanceOf ('OpenTok\Archive ' , $ archive );
1668+ $ this ->assertEquals (true , $ archive ->hasTranscription );
1669+ $ this ->assertIsArray ($ archive ->transcription );
1670+ $ this ->assertEquals ('requested ' , $ archive ->transcription ['status ' ]);
1671+ $ this ->assertEquals ('en-US ' , $ archive ->transcription ['primaryLanguageCode ' ]);
1672+ $ this ->assertEquals (false , $ archive ->transcription ['hasSummary ' ]);
1673+ }
1674+
1675+ public function testStartsArchiveWithTranscriptionAndSummary (): void
1676+ {
1677+ // Arrange
1678+ $ this ->setupOTWithMocks ([[
1679+ 'code ' => 200 ,
1680+ 'headers ' => [
1681+ 'Content-Type ' => 'application/json '
1682+ ],
1683+ 'path ' => 'v2/project/APIKEY/archive/session_transcription-with-summary '
1684+ ]]);
1685+
1686+ $ sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh- ' ;
1687+
1688+ // Act
1689+ $ archive = $ this ->opentok ->startArchive ($ sessionId , [
1690+ 'hasTranscription ' => true ,
1691+ 'transcriptionProperties ' => [
1692+ 'primaryLanguageCode ' => 'es-ES ' ,
1693+ 'hasSummary ' => true
1694+ ]
1695+ ]);
1696+
1697+ // Assert
1698+ $ this ->assertCount (1 , $ this ->historyContainer );
1699+
1700+ $ request = $ this ->historyContainer [0 ]['request ' ];
1701+
1702+ // Test request body contains transcription fields
1703+ $ body = json_decode ($ request ->getBody ());
1704+ $ this ->assertEquals (true , $ body ->hasTranscription );
1705+ $ this ->assertEquals ('es-ES ' , $ body ->transcriptionProperties ->primaryLanguageCode );
1706+ $ this ->assertEquals (true , $ body ->transcriptionProperties ->hasSummary );
1707+
1708+ // Test response properties
1709+ $ this ->assertInstanceOf ('OpenTok\Archive ' , $ archive );
1710+ $ this ->assertEquals (true , $ archive ->hasTranscription );
1711+ $ this ->assertIsArray ($ archive ->transcription );
1712+ $ this ->assertEquals ('requested ' , $ archive ->transcription ['status ' ]);
1713+ $ this ->assertEquals ('es-ES ' , $ archive ->transcription ['primaryLanguageCode ' ]);
1714+ $ this ->assertEquals (true , $ archive ->transcription ['hasSummary ' ]);
1715+ }
1716+
1717+ public function testStartsArchiveWithoutTranscription (): void
1718+ {
1719+ // Arrange
1720+ $ this ->setupOTWithMocks ([[
1721+ 'code ' => 200 ,
1722+ 'headers ' => [
1723+ 'Content-Type ' => 'application/json '
1724+ ],
1725+ 'path ' => 'v2/project/APIKEY/archive/session '
1726+ ]]);
1727+
1728+ $ sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh- ' ;
1729+
1730+ // Act - explicitly set hasTranscription to false
1731+ $ archive = $ this ->opentok ->startArchive ($ sessionId , [
1732+ 'hasTranscription ' => false
1733+ ]);
1734+
1735+ // Assert
1736+ $ this ->assertCount (1 , $ this ->historyContainer );
1737+
1738+ $ request = $ this ->historyContainer [0 ]['request ' ];
1739+
1740+ // Test request body
1741+ $ body = json_decode ($ request ->getBody ());
1742+ $ this ->assertEquals (false , $ body ->hasTranscription );
1743+ $ this ->assertObjectNotHasAttribute ('transcriptionProperties ' , $ body );
1744+
1745+ // Test response properties (archive without transcription)
1746+ $ this ->assertInstanceOf ('OpenTok\Archive ' , $ archive );
1747+ // The hasTranscription property should not be set in response if transcription is disabled
1748+ }
1749+
1750+ public function testCannotStartArchiveWithInvalidTranscriptionProperties (): void
1751+ {
1752+ $ this ->expectException (InvalidArgumentException::class);
1753+ $ this ->expectExceptionMessage ('transcriptionProperties must be an array. ' );
1754+
1755+ // Set up the OpenTok instance first
1756+ $ this ->setupOTWithMocks ([]);
1757+
1758+ $ sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh- ' ;
1759+
1760+ // Act - pass invalid transcriptionProperties (not an array)
1761+ $ this ->opentok ->startArchive ($ sessionId , [
1762+ 'hasTranscription ' => true ,
1763+ 'transcriptionProperties ' => 'invalid '
1764+ ]);
1765+ }
1766+
1767+ public function testCannotStartArchiveWithInvalidHasTranscription (): void
1768+ {
1769+ $ this ->expectException (InvalidArgumentException::class);
1770+ $ this ->expectExceptionMessage ('hasTranscription must be either true or false. ' );
1771+
1772+ // Set up the OpenTok instance first
1773+ $ this ->setupOTWithMocks ([]);
1774+
1775+ $ sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh- ' ;
1776+
1777+ // Act - pass invalid hasTranscription (not a boolean)
1778+ $ this ->opentok ->startArchive ($ sessionId , [
1779+ 'hasTranscription ' => 'invalid '
1780+ ]);
1781+ }
1782+
1783+ public function testCannotStartArchiveWithInvalidPrimaryLanguageCode (): void
1784+ {
1785+ $ this ->setupOT ();
1786+
1787+ $ this ->expectException (InvalidArgumentException::class);
1788+ $ this ->expectExceptionMessage ('primaryLanguageCode must be a non-empty string in BCP-47 format. ' );
1789+
1790+ $ sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh- ' ;
1791+
1792+ // Act - pass empty primaryLanguageCode
1793+ $ this ->opentok ->startArchive ($ sessionId , [
1794+ 'hasTranscription ' => true ,
1795+ 'transcriptionProperties ' => [
1796+ 'primaryLanguageCode ' => '' ,
1797+ 'hasSummary ' => false
1798+ ]
1799+ ]);
1800+ }
1801+
1802+ public function testCannotStartArchiveWithInvalidHasSummary (): void
1803+ {
1804+ $ this ->setupOT ();
1805+
1806+ $ this ->expectException (InvalidArgumentException::class);
1807+ $ this ->expectExceptionMessage ('hasSummary must be either true or false. ' );
1808+
1809+ $ sessionId = '2_MX44NTQ1MTF-flR1ZSBOb3YgMTIgMDk6NDA6NTkgUFNUIDIwMTN-MC43NjU0Nzh- ' ;
1810+
1811+ // Act - pass invalid hasSummary (not a boolean)
1812+ $ this ->opentok ->startArchive ($ sessionId , [
1813+ 'hasTranscription ' => true ,
1814+ 'transcriptionProperties ' => [
1815+ 'primaryLanguageCode ' => 'en-US ' ,
1816+ 'hasSummary ' => 'invalid '
1817+ ]
1818+ ]);
1819+ }
1820+
16201821 public function testForceDisconnect (): void
16211822 {
16221823 // Arrange
0 commit comments