Skip to content

Commit c12892b

Browse files
committed
Cleanup & tests added
1 parent d28443b commit c12892b

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

includes/MslsOptionsPost.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ public function get_postlink( $language ) {
4545
$this->with_front = ! empty( $post_object->rewrite['with_front'] );
4646
}
4747

48-
global $current_site;
49-
$blog_id = msls_blog_collection()->get_blog_id( $language );
50-
if ( $current_site->blog_id != $blog_id ) {
51-
$option = get_blog_option( $blog_id, 'msls' );
52-
// error_log( print_r( $option, true ) );
53-
}
54-
5548
return apply_filters( 'check_url', get_permalink( $post ), $this );
5649
}
5750

tests/TestMslsOptionsPost.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace lloc\MslsTests;
44

55
use Brain\Monkey\Functions;
6+
use Brain\Monkey\Filters;
67

78
use lloc\Msls\MslsOptionsPost;
89

@@ -11,7 +12,7 @@ class TestMslsOptionsPost extends MslsUnitTestCase {
1112
protected function setUp(): void {
1213
parent::setUp();
1314

14-
Functions\expect( 'get_option' )->once()->andReturn( [ 'de_DE' => 42 ] );
15+
Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) );
1516

1617
$this->test = new MslsOptionsPost();
1718
}
@@ -26,10 +27,32 @@ public function test_get_postlink_post_is_null(): void {
2627
$this->assertEquals( '', $this->test->get_postlink( 'de_DE' ) );
2728
}
2829

30+
public function test_get_postlink_post_is_draft(): void {
31+
$post = \Mockery::mock( '\WP_Post' );
32+
$post->post_status = 'draft';
33+
34+
Functions\expect( 'get_post' )->once()->andReturn( $post );
35+
36+
$this->assertEquals( '', $this->test->get_postlink( 'de_DE' ) );
37+
}
38+
39+
public function test_get_postlink_post_is_published(): void {
40+
$post = \Mockery::mock( '\WP_Post' );
41+
$post->post_status = 'publish';
42+
$post->post_type = 'post';
43+
44+
Functions\expect( 'get_post' )->once()->andReturn( $post );
45+
Functions\expect( 'get_post_type_object' )->once()->andReturn( (object) array( 'rewrite' => array( 'with_front' => true ) ) );
46+
Functions\expect( 'get_permalink' )->once()->andReturn( 'https://example.de/a-post' );
47+
48+
Filters\expectApplied( 'check_url' )->once()->with( 'https://example.de/a-post', $this->test );
49+
50+
$this->assertEquals( 'https://example.de/a-post', $this->test->get_postlink( 'de_DE' ) );
51+
}
52+
2953
public function test_get_current_link(): void {
3054
Functions\expect( 'get_permalink' )->once()->andReturn( 'https://example.org/a-post' );
3155

3256
$this->assertEquals( 'https://example.org/a-post', $this->test->get_current_link() );
3357
}
34-
3558
}

0 commit comments

Comments
 (0)