-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathTestMslsOptionsPost.php
57 lines (39 loc) · 1.81 KB
/
TestMslsOptionsPost.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
<?php declare( strict_types=1 );
namespace lloc\MslsTests;
use Brain\Monkey\Filters;
use Brain\Monkey\Functions;
use lloc\Msls\MslsOptionsPost;
class TestMslsOptionsPost extends MslsUnitTestCase {
protected function setUp(): void {
parent::setUp();
Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) );
$this->test = new MslsOptionsPost();
}
public function test_get_postlink_not_has_value() {
$this->assertEquals( '', $this->test->get_postlink( 'es_ES' ) );
}
public function test_get_postlink_post_is_null(): void {
Functions\expect( 'get_post' )->once()->andReturnNull();
$this->assertEquals( '', $this->test->get_postlink( 'de_DE' ) );
}
public function test_get_postlink_post_is_draft(): void {
$post = \Mockery::mock( '\WP_Post' );
$post->post_status = 'draft';
Functions\expect( 'get_post' )->once()->andReturn( $post );
$this->assertEquals( '', $this->test->get_postlink( 'de_DE' ) );
}
public function test_get_postlink_post_is_published(): void {
$post = \Mockery::mock( '\WP_Post' );
$post->post_status = 'publish';
$post->post_type = 'post';
Functions\expect( 'get_post' )->once()->andReturn( $post );
Functions\expect( 'get_post_type_object' )->once()->andReturn( (object) array( 'rewrite' => array( 'with_front' => true ) ) );
Functions\expect( 'get_permalink' )->once()->andReturn( 'https://example.de/a-post' );
Filters\expectApplied( 'check_url' )->once()->with( 'https://example.de/a-post', $this->test );
$this->assertEquals( 'https://example.de/a-post', $this->test->get_postlink( 'de_DE' ) );
}
public function test_get_current_link(): void {
Functions\expect( 'get_permalink' )->once()->andReturn( 'https://msls.co/a-post' );
$this->assertEquals( 'https://msls.co/a-post', $this->test->get_current_link() );
}
}