-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathBotFrameworkImageDriverTest.php
115 lines (100 loc) · 3.56 KB
/
BotFrameworkImageDriverTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace Tests;
use Mockery as m;
use BotMan\BotMan\Http\Curl;
use PHPUnit_Framework_TestCase;
use BotMan\BotMan\Messages\Attachments\Image;
use Symfony\Component\HttpFoundation\Request;
use BotMan\Drivers\BotFramework\BotFrameworkImageDriver;
class BotFrameworkImageDriverTest extends PHPUnit_Framework_TestCase
{
private function getDriver($responseData, $htmlInterface = null)
{
$request = m::mock(Request::class.'[getContent]');
$request->shouldReceive('getContent')->andReturn(json_encode($responseData));
if ($htmlInterface === null) {
$htmlInterface = m::mock(Curl::class);
}
return new BotFrameworkImageDriver($request, [], $htmlInterface);
}
private function getResponseData()
{
return [
'type' => 'message',
'id' => '4IIOjFkzcYy1HbYO',
'timestamp' => '2016-11-29T21:58:31.879Z',
'serviceUrl' => 'https://skype.botframework.com',
'channelId' => 'skype',
'from' => [
'id' => '29:1zPNq1EP2_H-mik_1MQgKYp0nZu9tUljr2VEdTlGhEo7VlZ1YVDVSUZ0g70sk1',
'name' => 'Julia',
],
'conversation' => [
'id' => '29:1zPNq1EP2_H-mik_1MQgKYp0nZu9tUljr2VEdTlGhEo7VlZ1YVDVSUZ0g70sk1',
],
'recipient' => [
'id' => '28:a91af6d0-0e59-4adb-abcf-b6a1f728e3f3',
'name' => 'BotMan',
],
'text' => 'hey there',
'attachments' => [
[
'contentType' => 'image',
'contentUrl' => 'http://foo.bar/baz.png',
'name' => 'baz.png',
],
],
'entities' => [],
];
}
/** @test */
public function it_returns_the_driver_name()
{
$driver = $this->getDriver([]);
$this->assertSame('BotFrameworkImage', $driver->getName());
}
/** @test */
public function it_matches_the_request()
{
$driver = $this->getDriver([
'attachments' => [],
]);
$this->assertFalse($driver->matchesRequest());
$driver = $this->getDriver($this->getResponseData());
$this->assertTrue($driver->matchesRequest());
}
private function getRequest($responseData)
{
$request = m::mock(\Symfony\Component\HttpFoundation\Request::class.'[getContent]');
$request->shouldReceive('getContent')->andReturn(json_encode($responseData));
return $request;
}
/** @test */
public function it_returns_the_message_object()
{
$driver = $this->getDriver($this->getResponseData());
$this->assertTrue(is_array($driver->getMessages()));
}
/** @test */
public function it_returns_the_message_objects_as_reference()
{
$driver = $this->getDriver($this->getResponseData());
$message = $driver->getMessages()[0];
$hash = spl_object_hash($message);
$this->assertSame($hash, spl_object_hash($driver->getMessages()[0]));
}
/** @test */
public function it_returns_the_image()
{
$driver = $this->getDriver($this->getResponseData());
$message = $driver->getMessages()[0];
$this->assertSame(Image::PATTERN, $message->getText());
$image = $message->getImages()[0];
$this->assertSame('http://foo.bar/baz.png', $image->getUrl());
$this->assertSame([
'contentType' => 'image',
'contentUrl' => 'http://foo.bar/baz.png',
'name' => 'baz.png',
], $image->getPayload());
}
}