@@ -54,6 +54,50 @@ public function testFailsOnInvalidInitialization()
5454 // Assert
5555 }
5656
57+ public function testCreatesDefaultSession ()
58+ {
59+ // Arrange
60+ $ mock = new MockPlugin ();
61+ $ response = MockPlugin::getMockFile (
62+ self ::$ mockBasePath . 'session/create/relayed '
63+ );
64+ $ mock ->addResponse ($ response );
65+ $ this ->client ->addSubscriber ($ mock );
66+
67+ // Act
68+ $ session = $ this ->opentok ->createSession ();
69+
70+ // Assert
71+ $ requests = $ mock ->getReceivedRequests ();
72+ $ this ->assertCount (1 , $ requests );
73+
74+ $ request = $ requests [0 ];
75+ $ this ->assertEquals ('POST ' , strtoupper ($ request ->getMethod ()));
76+ $ this ->assertEquals ('/session/create ' , $ request ->getPath ());
77+ $ this ->assertEquals ('api.opentok.com ' , $ request ->getHost ());
78+ $ this ->assertEquals ('https ' , $ request ->getScheme ());
79+
80+ $ authString = $ request ->getHeader ('X-TB-PARTNER-AUTH ' );
81+ $ this ->assertNotEmpty ($ authString );
82+ $ this ->assertEquals ($ this ->API_KEY .': ' .$ this ->API_SECRET , $ authString );
83+
84+ // TODO: test the dynamically built User Agent string
85+ $ userAgent = $ request ->getHeader ('User-Agent ' );
86+ $ this ->assertNotEmpty ($ userAgent );
87+ $ this ->assertStringStartsWith ('OpenTok-PHP-SDK/2.2.1-alpha.1 ' , $ userAgent ->__toString ());
88+
89+ $ p2p_preference = $ request ->getPostField ('p2p.preference ' );
90+ $ this ->assertEquals ('enabled ' , $ p2p_preference );
91+
92+ $ this ->assertInstanceOf ('OpenTok\Session ' , $ session );
93+ // NOTE: this is an actual sessionId from the recorded response, this doesn't correspond to
94+ // the API Key and API Secret used to create the session.
95+ $ this ->assertEquals (
96+ '2_MX4xNzAxMjYzMX4xMjcuMC4wLjF-V2VkIEZlYiAyNiAxODo1NzoyNCBQU1QgMjAxNH4wLjU0MDU4ODc0fg ' ,
97+ $ session ->getSessionId ()
98+ );
99+ }
100+
57101 public function testCreatesMediaRoutedAndLocationSession ()
58102 {
59103 // Arrange
0 commit comments