33namespace lloc \MslsTests ;
44
55use Brain \Monkey \Functions ;
6+ use Brain \Monkey \Filters ;
67
78use 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