FacebookTest::testGetProfileUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OAuth\Unit\UserData\Extractor;
4
5
use OAuth\UserData\Extractor\Facebook;
6
7
/**
8
 * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-02-07 at 22:32:44.
9
 */
10
class FacebookTest extends \PHPUnit_Framework_TestCase
11
{
12
    const RESPONSE_PROFILE =
13
'{
14
  "id": "012345678",
15
  "name": "John Doe",
16
  "first_name": "John",
17
  "last_name": "Doe",
18
  "link": "https://www.facebook.com/johnnydonny",
19
  "birthday": "05/17/1987",
20
  "hometown": {
21
    "id": "111665038853258",
22
    "name": "Catania, Italy"
23
  },
24
  "location": {
25
    "id": "115353315143936",
26
    "name": "Rome, Italy"
27
  },
28
  "bio": "A life on the edge",
29
  "quotes": "fall seven times - stand up eight",
30
  "gender": "male",
31
  "email": "[email protected]",
32
  "website": "http://blog.foo.com Blog\nhttp://foo.com Portfolio",
33
  "timezone": 1,
34
  "locale": "it_IT",
35
  "verified": true,
36
  "updated_time": "2014-02-07T10:57:24+0000",
37
  "username": "johnnydonny"
38
}';
39
40
    const RESPONSE_IMAGE =
41
'{
42
  "data": {
43
    "url": "https://fbcdn-profile-a.akamaihd.net/something_n.jpg",
44
    "is_silhouette": false
45
  }
46
}';
47
48
    /**
49
     * @var Facebook
50
     */
51
    protected $extractor;
52
53
    /**
54
     * Sets up the fixture, for example, opens a network connection.
55
     * This method is called before a test is executed.
56
     */
57
    protected function setUp()
58
    {
59
        $this->extractor = new Facebook();
60
        $service = $this->getMockBuilder('\\OAuth\\OAuth2\\Service\\Facebook')
61
            ->disableOriginalConstructor()
62
            ->getMock();
63
        $service->expects($this->any())
64
            ->method('request')
65
            ->will($this->returnCallback(function ($arg) {
66
                if ($arg == Facebook::REQUEST_PROFILE) {
67
                    return FacebookTest::RESPONSE_PROFILE;
68
                } elseif ($arg == Facebook::REQUEST_IMAGE) {
69
                    return FacebookTest::RESPONSE_IMAGE;
70
                }
71
72
                return null;
73
            }));
74
        /**
75
         * @var \OAuth\Common\Service\ServiceInterface $service
76
         */
77
        $this->extractor->setService($service);
78
    }
79
80
    /**
81
     * Tears down the fixture, for example, closes a network connection.
82
     * This method is called after a test is executed.
83
     */
84
    protected function tearDown()
85
    {
86
    }
87
88
    public function testGetUniqueId()
89
    {
90
        $this->assertEquals('012345678', $this->extractor->getUniqueId());
91
    }
92
93
    public function testGetUsername()
94
    {
95
        $this->assertEquals('johnnydonny', $this->extractor->getUsername());
96
    }
97
98
    public function testGetFirstName()
99
    {
100
        $this->assertEquals('John', $this->extractor->getFirstName());
101
    }
102
103
    public function testGetLastName()
104
    {
105
        $this->assertEquals('Doe', $this->extractor->getLastName());
106
    }
107
108
    public function testGetFullName()
109
    {
110
        $this->assertEquals('John Doe', $this->extractor->getFullName());
111
    }
112
113
    public function testGetEmail()
114
    {
115
        $this->assertEquals('[email protected]', $this->extractor->getEmail());
116
    }
117
118
    public function testGetDescription()
119
    {
120
        $this->assertEquals('A life on the edge', $this->extractor->getDescription());
121
    }
122
123
    public function testGetProfileUrl()
124
    {
125
        $this->assertEquals('https://www.facebook.com/johnnydonny', $this->extractor->getProfileUrl());
126
    }
127
128
    public function testGetLocation()
129
    {
130
        $this->assertEquals('Rome, Italy', $this->extractor->getLocation());
131
    }
132
133
    public function testGetWebsites()
134
    {
135
        $expected = array(
136
            'http://blog.foo.com',
137
            'http://foo.com'
138
        );
139
        $this->assertEquals($expected, $this->extractor->getWebsites());
140
    }
141
142
    public function testGetImageUrl()
143
    {
144
        $this->assertEquals('https://fbcdn-profile-a.akamaihd.net/something_n.jpg', $this->extractor->getImageUrl());
145
    }
146
147
    public function testIsEmailVerified()
148
    {
149
        $this->assertTrue($this->extractor->isEmailVerified());
150
    }
151
152
    public function testGetExtra()
153
    {
154
        $extras = $this->extractor->getExtras();
155
        $this->assertArrayHasKey('birthday', $extras);
156
        $this->assertArrayHasKey('hometown', $extras);
157
        $this->assertArrayHasKey('quotes', $extras);
158
159
        $this->assertArrayNotHasKey('id', $extras);
160
        $this->assertArrayNotHasKey('name', $extras);
161
        $this->assertArrayNotHasKey('first_name', $extras);
162
    }
163
}
164