| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
namespace Ratchet\WebSocket\Version;
|
|
|
3 |
use Ratchet\WebSocket\Version\HyBi10;
|
|
|
4 |
use Ratchet\WebSocket\Version\RFC6455\Frame;
|
|
|
5 |
|
|
|
6 |
/**
|
|
|
7 |
* @covers Ratchet\WebSocket\Version\Hybi10
|
|
|
8 |
*/
|
|
|
9 |
class HyBi10Test extends \PHPUnit_Framework_TestCase {
|
|
|
10 |
protected $_version;
|
|
|
11 |
|
|
|
12 |
public function setUp() {
|
|
|
13 |
$this->_version = new HyBi10();
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Is this useful?
|
|
|
18 |
*/
|
|
|
19 |
public function testClassImplementsVersionInterface() {
|
|
|
20 |
$constraint = $this->isInstanceOf('\\Ratchet\\WebSocket\\Version\\VersionInterface');
|
|
|
21 |
$this->assertThat($this->_version, $constraint);
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* @dataProvider HandshakeProvider
|
|
|
26 |
*/
|
|
|
27 |
public function testKeySigningForHandshake($key, $accept) {
|
|
|
28 |
$this->assertEquals($accept, $this->_version->sign($key));
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
public static function HandshakeProvider() {
|
|
|
32 |
return array(
|
|
|
33 |
array('x3JJHMbDL1EzLkh9GBhXDw==', 'HSmrc0sMlYUkAGmm5OPpG2HaGWk=')
|
|
|
34 |
, array('dGhlIHNhbXBsZSBub25jZQ==', 's3pPLMBiTxaQ9kYGzzhZRbK+xOo=')
|
|
|
35 |
);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* @dataProvider UnframeMessageProvider
|
|
|
40 |
*/
|
|
|
41 |
public function testUnframeMessage($message, $framed) {
|
|
|
42 |
// $decoded = $this->_version->unframe(base64_decode($framed));
|
|
|
43 |
$frame = new Frame;
|
|
|
44 |
$frame->addBuffer(base64_decode($framed));
|
|
|
45 |
|
|
|
46 |
$this->assertEquals($message, $frame->getPayload());
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public static function UnframeMessageProvider() {
|
|
|
50 |
return array(
|
|
|
51 |
array('Hello World!', 'gYydAIfa1WXrtvIg0LXvbOP7')
|
|
|
52 |
, array('!@#$%^&*()-=_+[]{}\|/.,<>`~', 'gZv+h96r38f9j9vZ+IHWrvOWoayF9oX6gtfRqfKXwOeg')
|
|
|
53 |
, array('ಠ_ಠ', 'gYfnSpu5B/g75gf4Ow==')
|
|
|
54 |
, array("The quick brown fox jumps over the lazy dog. All work and no play makes Chris a dull boy. I'm trying to get past 128 characters for a unit test here...", 'gf4Amahb14P8M7Kj2S6+4MN7tfHHLLmjzjSvo8IuuvPbe7j1zSn398A+9+/JIa6jzDSwrYh7lu/Ee6Ds2jD34sY/9+3He6fvySL37skwsvCIGL/xwSj34og/ou/Ee7Xs0XX3o+F8uqPcKa7qxjz398d7sObce6fi2y/3sppj9+DAOqXiyy+y8dt7sezae7aj3TW+94gvsvDce7/m2j75rYY=')
|
|
|
55 |
);
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public function testUnframeMatchesPreFraming() {
|
|
|
59 |
$string = 'Hello World!';
|
|
|
60 |
$framed = $this->_version->newFrame($string)->getContents();
|
|
|
61 |
|
|
|
62 |
$frame = new Frame;
|
|
|
63 |
$frame->addBuffer($framed);
|
|
|
64 |
|
|
|
65 |
$this->assertEquals($string, $frame->getPayload());
|
|
|
66 |
}
|
|
|
67 |
}
|