-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathtest-hreflang.php
68 lines (51 loc) · 1.8 KB
/
test-hreflang.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
<?php
namespace lloc\MslsTests;
use Brain\Monkey\Functions;
use Brain\Monkey\Filters;
use lloc\Msls\Map\HrefLang;
use lloc\Msls\MslsBlog;
use lloc\Msls\MslsBlogCollection;
class WP_Test_HrefLang extends Msls_UnitTestCase {
public function get_sut() {
$map = [
'de_DE' => 'de',
'de_DE_formal' => 'de',
'fr_FR' => 'fr',
'es_ES' => 'es',
'cat' => 'cat',
'en_US' => 'en',
'en_GB' => 'en',
];
$i = 1;
foreach ( $map as $locale => $alpha2 ) {
$blog = \Mockery::mock( MslsBlog::class );
$blog->shouldReceive( [
'get_language' => $locale,
'get_alpha2' => $alpha2,
] );
$blog->userblog_id = $i++;
$blogs[] = $blog;
}
$collection = \Mockery::mock( MslsBlogCollection::class );
$collection->shouldReceive( 'get_objects' )->andReturn( $blogs );
return new HrefLang( $collection );
}
public function test_get() {
$obj = $this->get_sut();
Functions\expect( 'has_filter' )->with( 'msls_head_hreflang' )->times( 8 )->andReturn( false );
$this->assertEquals( 'de-DE', $obj->get( 'de_DE', 1 ) );
$this->assertEquals( 'de-DE', $obj->get( 'de_DE_formal', 2 ) );
$this->assertEquals( 'fr', $obj->get( 'fr_FR', 3 ) );
$this->assertEquals( 'es', $obj->get( 'es_ES', 4 ) );
$this->assertEquals( 'cat', $obj->get( 'cat', 5 ) );
$this->assertEquals( 'en-US', $obj->get( 'en_US', 6 ) );
$this->assertEquals( 'en-GB', $obj->get( 'en_GB', 7 ) );
$this->assertEquals( 'en_US', $obj->get( 'en_US', 8 ) );
}
public function test_get_has_filter() {
$obj = $this->get_sut();
Functions\expect( 'has_filter' )->with( 'msls_head_hreflang' )->once()->andReturn( true );
Filters\expectApplied('msls_head_hreflang')->with( 'en_US')->once()->andReturn( 'en-US' );
$this->assertEquals( 'en-US', $obj->get( 'en_US', 8 ) );
}
}