|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Automattic\Jetpack\Connection; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class ManagerTest extends TestCase { |
|
8
|
|
|
public function setUp() { |
|
9
|
|
|
$this->manager = $this->getMockBuilder( 'Automattic\Jetpack\Connection\Manager' ) |
|
10
|
|
|
->setMethods( [ 'get_access_token' ] ) |
|
11
|
|
|
->getMock(); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function tearDown() { |
|
15
|
|
|
unset( $this->manager ); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
function test_class_implements_interface() { |
|
19
|
|
|
$manager = new Manager(); |
|
20
|
|
|
$this->assertInstanceOf( 'Automattic\Jetpack\Connection\Manager_Interface', $manager ); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @covers Automattic\Jetpack\Connection\Manager::is_active |
|
25
|
|
|
*/ |
|
26
|
|
|
public function test_is_active_when_connected() { |
|
27
|
|
|
$access_token = (object) [ |
|
28
|
|
|
'secret' => 'abcd1234', |
|
29
|
|
|
'external_user_id' => 1, |
|
30
|
|
|
]; |
|
31
|
|
|
$this->manager->expects( $this->once() ) |
|
32
|
|
|
->method( 'get_access_token' ) |
|
33
|
|
|
->will( $this->returnValue( $access_token ) ); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertTrue( $this->manager->is_active() ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @covers Automattic\Jetpack\Connection\Manager::is_active |
|
40
|
|
|
*/ |
|
41
|
|
|
public function test_is_active_when_not_connected() { |
|
42
|
|
|
$this->manager->expects( $this->once() ) |
|
43
|
|
|
->method( 'get_access_token' ) |
|
44
|
|
|
->will( $this->returnValue( false ) ); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertFalse( $this->manager->is_active() ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function test_api_url_defaults() { |
|
50
|
|
|
$this->assertEquals( |
|
51
|
|
|
'https://jetpack.wordpress.com/jetpack.something/1/', |
|
52
|
|
|
$this->manager->api_url( 'something' ) |
|
53
|
|
|
); |
|
54
|
|
|
$this->assertEquals( |
|
55
|
|
|
'https://jetpack.wordpress.com/jetpack.another_thing/1/', |
|
56
|
|
|
$this->manager->api_url( 'another_thing/' ) |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|