forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocialTraitTest.php
More file actions
128 lines (116 loc) · 4.09 KB
/
Copy pathSocialTraitTest.php
File metadata and controls
128 lines (116 loc) · 4.09 KB
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
<?php
/**
* Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Users\Test\TestCase\Controller\Traits;
use Cake\Core\Configure;
use Cake\TestSuite\TestCase;
class SocialTraitTest extends TestCase
{
public function setUp()
{
parent::setUp();
$this->controller = $this->getMock(
'Cake\Controller\Controller',
['header', 'redirect', 'render', '_stop']
);
$this->controller->Trait = $this->getMockForTrait(
'Users\Controller\Traits\SocialTrait',
[],
'',
true,
true,
true,
['_getOpauthInstance', 'redirect', '_generateOpauthCompleteUrl']
);
}
public function tearDown()
{
parent::tearDown();
}
/**
* Test opauthInit with no callback
*
*/
public function testOpauthInitTest()
{
$Opauth = $this->getMock('Opauth\Opauth\Opauth', ['run'], [], '', false);
$Opauth->expects($this->once())
->method('run')
->will($this->returnValue('response'));
$this->controller->Trait->expects($this->once())
->method('_getOpauthInstance')
->will($this->returnValue($Opauth));
$this->controller->Trait->opauthInit();
}
/**
* Test opauthInit with callback
*
*/
public function testOpauthInitTestCallback()
{
$Opauth = $this->getMock('Opauth\Opauth\Opauth', ['run'], [], '', false);
$Opauth->expects($this->once())
->method('run')
->will($this->returnValue('response'));
$session = $this->getMock('Cake\Network\Session', ['write', 'check']);
$session->expects($this->once())
->method('write')
->with(Configure::read('Users.Key.Session.social'), 'response');
$this->controller->Trait->request = $this->getMock('Cake\Network\Request', ['session']);
$this->controller->Trait->request->expects($this->once())
->method('session')
->will($this->returnValue($session));
$this->controller->Trait->expects($this->once())
->method('_getOpauthInstance')
->will($this->returnValue($Opauth));
$this->controller->Trait->expects($this->once())
->method('_generateOpauthCompleteUrl')
->will($this->returnValue('url'));
$this->controller->Trait->expects($this->once())
->method('redirect')
->with('url');
$this->controller->Trait->opauthInit('callback');
}
/**
* Test socialEmail
*
*/
public function testSocialEmail()
{
$session = $this->getMock('Cake\Network\Session', ['check']);
$session->expects($this->once())
->method('check')
->with('Users.social')
->will($this->returnValue('social_key'));
$this->controller->Trait->request = $this->getMock('Cake\Network\Request', ['session']);
$this->controller->Trait->request->expects($this->once())
->method('session')
->will($this->returnValue($session));
$this->controller->Trait->socialEmail();
}
/**
* Test socialEmail
*
* @expectedException \Cake\Network\Exception\NotFoundException
*/
public function testSocialEmailInvalid()
{
$session = $this->getMock('Cake\Network\Session', ['check']);
$session->expects($this->once())
->method('check')
->with('Users.social')
->will($this->returnValue(null));
$this->controller->Trait->request = $this->getMock('Cake\Network\Request', ['session']);
$this->controller->Trait->request->expects($this->once())
->method('session')
->will($this->returnValue($session));
$this->controller->Trait->socialEmail();
}
}