Skip to content

Commit 8c2ca38

Browse files
committed
Tests added
1 parent 23e5a1a commit 8c2ca38

File tree

1 file changed

+44
-51
lines changed

1 file changed

+44
-51
lines changed

tests/TestMslsOutput.php

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace lloc\MslsTests;
44

5+
use lloc\Msls\MslsBlog;
56
use lloc\Msls\MslsBlogCollection;
67
use lloc\Msls\MslsOutput;
78
use lloc\Msls\MslsOptions;
@@ -10,82 +11,74 @@
1011

1112
class TestMslsOutput extends MslsUnitTestCase {
1213

13-
function get_test() {
14-
$options = \Mockery::mock( MslsOptions::class );
14+
protected function setUp(): void {
15+
$options = \Mockery::mock( MslsOptions::class );
16+
1517
$collection = \Mockery::mock( MslsBlogCollection::class );
16-
$collection->shouldReceive( [
17-
'has_current_blog' => true,
18-
'get_current_blog' => 1,
19-
'get_filtered' => [],
20-
] );
18+
$collection->shouldReceive( 'has_current_blog' )->andReturn( true );
19+
$collection->shouldReceive( 'get_current_blog' )->andReturn( 1 );
20+
$collection->shouldReceive( 'get_filtered' )->andReturn( array() );
2121

22-
return new MslsOutput( $options, $collection );
22+
$this->test = new MslsOutput( $options, $collection );
2323
}
2424

25-
function test_get_method() {
26-
$obj = $this->get_test();
27-
28-
$this->assertIsArray( $obj->get( 0 ) );
25+
public function test_get_method(): void {
26+
$this->assertEquals( array(), $this->test->get( 0 ) );
2927
}
3028

31-
function test___toString_method() {
32-
$obj = $this->get_test();
29+
public function test_get_alternate_links() {
30+
$blog = \Mockery::mock( MslsBlog::class );
31+
$blog->shouldReceive( 'get_alpha2' )->andReturn( 'de' );
32+
$blog->shouldReceive( 'get_language' )->andReturn( 'de_DE' );
3333

34-
$this->assertIsSTring( $obj->__toString() );
35-
$this->assertIsSTring( strval( $obj ) );
36-
$this->assertEquals( $obj->__toString(), strval( $obj ) );
37-
}
34+
$collection = \Mockery::mock( MslsBlogCollection::class );
35+
$collection->shouldReceive( 'get_objects' )->andReturn( array( $blog ) );
3836

39-
function test_get_tags_method() {
40-
$obj = $this->get_test();
37+
Functions\expect( 'msls_blog_collection' )->once()->andReturn( $collection );
38+
Functions\expect( 'is_admin' )->once()->andReturn( false );
39+
Functions\expect( 'is_front_page' )->once()->andReturn( false );
40+
Functions\expect( 'is_search' )->once()->andReturn( false );
41+
Functions\expect( 'is_404' )->once()->andReturn( false );
4142

42-
$this->assertIsArray( $obj->get_tags() );
43+
$this->assertEquals( array(), $this->test->get_alternate_links() );
4344
}
4445

45-
function test_set_tags_method() {
46-
Functions\expect( 'wp_parse_args' )->once()->andReturn( [] );
47-
48-
$obj = $this->get_test();
46+
public function test___toString() {
47+
$this->assertIsSTring( $this->test->__toString() );
48+
$this->assertIsSTring( strval( $this->test ) );
49+
$this->assertEquals( $this->test->__toString(), strval( $this->test ) );
50+
}
4951

50-
$this->assertInstanceOf( MslsOutput::class, $obj->set_tags() );
52+
public function test_get_tags(): void {
53+
$this->assertIsArray( $this->test->get_tags() );
5154
}
5255

53-
function test_is_requirements_not_fulfilled_method_with_null() {
54-
$obj = $this->get_test();
56+
public function test_set_tags(): void {
57+
Functions\expect( 'wp_parse_args' )->once()->andReturn( array() );
5558

56-
$test = $obj->is_requirements_not_fulfilled( null, false, 'de_DE' );
57-
$this->assertFalse( $test );
59+
$this->assertInstanceOf( MslsOutput::class, $this->test->set_tags() );
60+
}
5861

59-
$test = $obj->is_requirements_not_fulfilled( null, true, 'de_DE' );
60-
$this->assertTrue( $test );
62+
public function test_is_requirements_not_fulfilled_with_null(): void {
63+
$this->assertFalse( $this->test->is_requirements_not_fulfilled( null, false, 'de_DE' ) );
64+
$this->assertTrue( $this->test->is_requirements_not_fulfilled( null, true, 'de_DE' ) );
6165
}
6266

63-
function test_is_requirements_not_fulfilled_method_with_mslsoptions() {
64-
Functions\expect( 'get_option' )->once()->andReturn( [] );
67+
public function test_is_requirements_not_fulfilled_with_mslsoptions(): void {
68+
Functions\expect( 'get_option' )->once()->andReturn( array() );
6569

6670
$mydata = new MslsOptions();
6771

68-
$obj = $this->get_test();
69-
70-
$test = $obj->is_requirements_not_fulfilled( $mydata, false, 'de_DE' );
71-
$this->assertFalse( $test );
72-
73-
$test = $obj->is_requirements_not_fulfilled( $mydata, true, 'de_DE' );
74-
$this->assertFalse( $test );
72+
$this->assertFalse( $this->test->is_requirements_not_fulfilled( $mydata, false, 'de_DE' ) );
73+
$this->assertFalse( $this->test->is_requirements_not_fulfilled( $mydata, true, 'de_DE' ) );
7574
}
7675

77-
function test_is_requirements_not_fulfilled_method_with_mslsoptionspost() {
78-
Functions\expect( 'get_option' )->once()->andReturn( [] );
76+
public function test_is_requirements_not_fulfilled_with_mslsoptionspost(): void {
77+
Functions\expect( 'get_option' )->once()->andReturn( array() );
7978

8079
$mydata = new MslsOptionsPost();
8180

82-
$obj = $this->get_test();
83-
84-
$test = $obj->is_requirements_not_fulfilled( $mydata, false, 'de_DE' );
85-
$this->assertFalse( $test );
86-
87-
$test = $obj->is_requirements_not_fulfilled( $mydata, true, 'de_DE' );
88-
$this->assertTrue( $test );
81+
$this->assertFalse( $this->test->is_requirements_not_fulfilled( $mydata, false, 'de_DE' ) );
82+
$this->assertTrue( $this->test->is_requirements_not_fulfilled( $mydata, true, 'de_DE' ) );
8983
}
90-
9184
}

0 commit comments

Comments
 (0)