-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateConverterFacebookTest.php
141 lines (130 loc) · 5.74 KB
/
UpdateConverterFacebookTest.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
namespace Buffer\UpdateConverters;
use MongoDB\BSON\UTCDateTime;
use MongoDB\BSON\ObjectId;
class UpdateConverterFacebookTest extends \PHPUnit\Framework\TestCase
{
public function testFromFacebookStatus()
{
$fb_status = $this->makeFacebookStatus();
$update = UpdateConverterFacebook::convertFromSocialNetwork($fb_status);
$this->assertEquals('777687525604678_777698725603558', $update['service_update_id']);
$this->assertEquals($fb_status['message'], $update['text']);
$this->assertEquals(new UTCDateTime(1000*strtotime(1401970981)), $update['sent_at']);
$this->assertEquals(new UTCDateTime(1000*strtotime(1401970981)), $update['due_at']);
$this->assertEquals('facebook', $update['profile_service']);
$this->assertEquals('facebook', $update['via']);
$this->assertEquals('service', $update['status']);
}
public function testFromFacebookStatusImages()
{
$media_json = [
"attachments" => [
'data' => [
[
'media' => [
'image' => [
'src'=> 'https://fbcdn-photos-e-a.akamaihd.net/hphotos-ak-xpf1/t1.0-0/10446483_778288288877935_8375407983187109054_s.jpg',
]
]
]
]
]
];
$fb_status = $this->makeFacebookStatus($media_json);
$update = UpdateConverterFacebook::convertFromSocialNetwork($fb_status);
$this->assertNotNull($update['media']);
$this->assertEquals($fb_status['attachments']['data'][0]['media']['image']['src'], $update['media']['photo']);
$this->assertEquals($fb_status['attachments']['data'][0]['media']['image']['src'], $update['media']['thumbnail']);
}
/**
* @test
*/
public function fromFacebookGallery()
{
$media_json = [
"attachments" => [
'data' => [
[
'subattachments' => [
'data' => [
[
'media' => [
'image' => [
'src'=> 'https://fbcdn-photos-e-a.akamaihd.net/hphotos-ak-xpf1/t1.0-0/10446483_778288288877935_8375407983187109054_s.jpg',
]
]
],
[
'media' => [
'image' => [
'src'=> 'https://fbcdn-photos-e-a.akamaihd.net/hphotos-ak-xpf1/t1.0-0/10446483_778288288877935_8375407983187109054_s.jpg',
]
]
]
]
]
]
]
]
];
$fb_status = $this->makeFacebookStatus($media_json);
$update = UpdateConverterFacebook::convertFromSocialNetwork($fb_status);
$this->assertNotNull($update['media']);
$this->assertEquals($fb_status['attachments']['data'][0]['subattachments']['data'][0]['media']['image']['src'], $update['media']['photo']);
$this->assertEquals($fb_status['attachments']['data'][0]['subattachments']['data'][0]['media']['image']['src'], $update['media']['thumbnail']);
$this->assertEquals($fb_status['attachments']['data'][0]['subattachments']['data'][1]['media']['image']['src'], $update['extra_media'][0]['photo']);
$this->assertEquals($fb_status['attachments']['data'][0]['subattachments']['data'][1]['media']['image']['src'], $update['extra_media'][0]['thumbnail']);
$this->assertCount(1, $update['extra_media']);
}
public function testFromFacebookStatusUseDescriptionIfNoMessage()
{
$overrides = array('message' => '', 'description' => 'foo bar!');
$fb_status = $this->makeFacebookStatus($overrides);
$update = UpdateConverterFacebook::convertFromSocialNetwork($fb_status);
$this->assertEquals('foo bar!', $update['text']);
}
/**
* @test
*/
public function fromFacebookLinkAttachment()
{
$media_json = [
"attachments" => [
"data" => [
[
"type" => "share",
"target" => [
"url" => "http://buffer.com"
],
"title" => "Buffer",
"description" => "A better way to share on social media.",
"media" => [
"image" => [
"src" => "image_url"
]
]
]
]
]
];
$fb_status = $this->makeFacebookStatus($media_json);
$update = UpdateConverterFacebook::convertFromSocialNetwork($fb_status);
$this->assertEquals("Buffer", $update['media']['title']);
}
// Helpers
private function makeFacebookStatus($overrides = array())
{
return array_replace(array(
'id' => "777687525604678_777698725603558",
'created_time' => 1401970981,
'message' => 'Working hard on my next novel! Building a nice character sketch for my protagonist!',
'description' => '',
'attachment' => array('description' => ''),
'impressions' => null,
'like_info' => array('like_count' => 4),
'comment_info' => array( 'comment_count' => 1),
'share_count' => 0
), $overrides);
}
}