-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathTestMslsBlog.php
169 lines (131 loc) · 5.27 KB
/
TestMslsBlog.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php declare( strict_types=1 );
namespace lloc\MslsTests;
use Brain\Monkey\Functions;
use lloc\Msls\MslsBlog;
use lloc\Msls\MslsBlogCollection;
use lloc\Msls\MslsOptions;
class TestMslsBlog extends MslsUnitTestCase {
public function get_blog(): MslsBlog {
Functions\expect( 'get_blog_option' )->once()->andReturn( 'it_IT' );
Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 2 ) . '/' );
$blog = new \stdClass();
$blog->userblog_id = 1;
$blog->blogname = 'Test';
return new MslsBlog( $blog, 'Italiano' );
}
public function test_get_userblog_id(): void {
$this->assertEquals( 1, $this->get_blog()->userblog_id );
}
public function test_get_description(): void {
$this->assertEquals( 'Italiano', $this->get_blog()->get_description() );
}
public function test_get_url_current(): void {
$url = 'https://msls.co/';
$option = \Mockery::mock( MslsOptions::class );
$option->shouldReceive( 'get_current_link' )->andReturn( $url );
$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get_current_blog_id' )->andReturn( 1 );
Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection );
$this->assertEquals( $url, $this->get_blog()->get_url( $option ) );
}
public function test_get_frontpage(): void {
$url = 'https://msls.co/';
$option = \Mockery::mock( MslsOptions::class );
$option->shouldReceive( 'get_permalink' )->once()->andReturn( $url );
$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get_current_blog_id' )->andReturn( 2 );
Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection );
Functions\expect( 'is_front_page' )->once()->andReturn( true );
Functions\expect( 'switch_to_blog' )->once();
Functions\expect( 'restore_current_blog' )->once();
$this->assertEquals( $url, $this->get_blog()->get_url( $option ) );
}
public function test_get_url(): void {
$url = 'https://msls.co/';
$option = \Mockery::mock( MslsOptions::class );
$option->shouldReceive( 'get_permalink' )->once()->andReturn( $url );
$option->shouldReceive( 'has_value' )->once()->andReturn( true );
$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get_current_blog_id' )->andReturn( 2 );
Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection );
Functions\expect( 'is_front_page' )->once()->andReturn( false );
Functions\expect( 'switch_to_blog' )->once();
Functions\expect( 'restore_current_blog' )->once();
$this->assertEquals( $url, $this->get_blog()->get_url( $option ) );
}
public function test_get_language(): void {
$this->assertEquals( 'it_IT', $this->get_blog()->get_language() );
}
public function test_get_alpha2(): void {
$this->assertEquals( 'it', $this->get_blog()->get_alpha2() );
}
public function test_get_title(): void {
Functions\expect( 'add_query_arg' )->once()->andReturn( 'https://msls.co/added-args' );
$this->assertEquals(
'Test <span class="msls-icon-wrapper flag"><span class="flag-icon flag-icon-it">it_IT</span></span>',
$this->get_blog()->get_title()
);
}
/**
* Dataprovider
*
* @return array[]
*/
public function compareProvider() {
return array(
array( 0, 0, 0 ),
array( 0, 1, - 1 ),
array( 1, 0, 1 ),
array( - 1, - 2, 1 ),
array( - 2, - 1, - 1 ),
);
}
/**
* Verify the _cmp-method
*
* @dataProvider compareProvider
*/
public function test__cmp_method( int $a, int $b, int $expected ): void {
$this->assertEquals( $expected, MslsBlog::_cmp( $a, $b ) );
$obj = new MslsBlog( null, null );
$this->assertEquals( $expected, $obj->_cmp( $a, $b ) );
}
/**
* Verify the language-method
*/
public function test_language_cmp(): void {
$a = new MslsBlog( null, null );
$b = new MslsBlog( null, null );
$this->assertEquals( 0, $a->language( $a, $b ) );
}
/**
* Verify the description-method
*/
public function test_description_cmp(): void {
$a = new MslsBlog( null, null );
$b = new MslsBlog( null, null );
$this->assertEquals( 0, $a->description( $a, $b ) );
}
public function test_get_blavatar_lazy(): void {
Functions\expect( 'switch_to_blog' )->once();
Functions\expect( 'restore_current_blog' )->once();
Functions\expect( 'has_site_icon' )->once()->andReturn( true );
Functions\expect( 'get_site_icon_url' )->twice()->andReturn( 'https://msls.co/icons/abc.png' );
Functions\expect( 'wp_lazy_loading_enabled' )->once()->andReturn( true );
$this->assertEquals(
'<img class="blavatar" src="https://msls.co/icons/abc.png" srcset="https://msls.co/icons/abc.png 2x" alt="" width="16" height="16" loading="lazy" />',
$this->get_blog()->get_blavatar()
);
}
public function test_get_blavatar(): void {
Functions\expect( 'switch_to_blog' )->once();
Functions\expect( 'restore_current_blog' )->once();
Functions\expect( 'has_site_icon' )->once()->andReturn( true );
Functions\expect( 'get_site_icon_url' )->twice()->andReturn( 'https://msls.co/icons/abc.png' );
Functions\expect( 'wp_lazy_loading_enabled' )->once()->andReturn( false );
$this->assertEquals(
'<img class="blavatar" src="https://msls.co/icons/abc.png" srcset="https://msls.co/icons/abc.png 2x" alt="" width="16" height="16" />',
$this->get_blog()->get_blavatar()
);
}
}