Skip to content

Commit 08236cc

Browse files
authored
Merge pull request #342 from lloc/refactoring-2-9
Refactoring 2 9
2 parents 81c8d73 + 82bffb7 commit 08236cc

File tree

8 files changed

+150
-9
lines changed

8 files changed

+150
-9
lines changed

includes/Component/Input/Checkbox.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/**
88
* Class Checkbox
9+
*
910
* @package lloc\Msls\Component\Input
1011
*/
1112
class Checkbox implements InputInterface {
@@ -25,17 +26,18 @@ class Checkbox implements InputInterface {
2526
* @param string $value
2627
*/
2728
public function __construct( string $key, ?string $value ) {
28-
$this->key = esc_attr( $key );
29+
$this->key = esc_attr( $key );
2930
$this->selected = checked( 1, $value, false );
3031
}
3132

3233
/**
3334
* @return string
3435
*/
3536
public function render(): string {
36-
return sprintf( '<input type="checkbox" id="%1$s" name="msls[%1$s]" value="1" %2$s/>',
37+
return sprintf(
38+
'<input type="checkbox" id="%1$s" name="msls[%1$s]" value="1" %2$s/>',
3739
$this->key,
38-
$this->selected );
40+
$this->selected
41+
);
3942
}
40-
41-
}
43+
}

includes/Component/Input/Select.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public function __construct( string $key, array $arr, ?string $selected = null )
3636
public function render(): string {
3737
$name = apply_filters( 'msls_input_select_name', 'msls[' . $this->key . ']' );
3838

39-
return sprintf( '<select id="%1$s" name="%2$s">%3$s</select>', $this->key, $name, $this->options->render() );
39+
return sprintf( '<select id="%1$s" name="%2$s">%3$s</select>', $this->key, esc_attr( $name ), $this->options->render() );
4040
}
4141
}

includes/ContentImport/Service.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace lloc\Msls\ContentImport;
44

55
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
6-
use lloc\Msls\MslsOptions;
76
use lloc\Msls\MslsRegistryInstance;
87

98
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport;
4+
5+
use lloc\Msls\ContentImport\AttachmentPathFinder;
6+
use lloc\MslsTests\MslsUnitTestCase;
7+
use Brain\Monkey\Functions;
8+
9+
class TestAttachmentPathFinder extends MslsUnitTestCase {
10+
11+
public function setUp(): void {
12+
parent::setUp();
13+
14+
$this->test = new AttachmentPathFinder();
15+
}
16+
17+
public function dataprovider_filter_srcset() {
18+
$image_src = 'http://example.com/image.jpg';
19+
$msls_imported = array(
20+
'blog' => 1,
21+
'post' => 1,
22+
);
23+
$source_post = (object) array( 'guid' => 'http://example.com/image.jpg' );
24+
25+
return array(
26+
array( array(), $image_src, 0, array() ),
27+
array( array(), $image_src, '', array() ),
28+
array( array(), $image_src, null, array() ),
29+
array( array(), $image_src, 1, array(), null, 1, 1 ),
30+
array( array(), $image_src, 1, array(), array( 'random' => 'item' ), 1, 1 ),
31+
array( array( array( 'url' => $image_src ) ), $image_src, 1, array( array( 'url' => $image_src ) ), $msls_imported, 1, 0, 1 ),
32+
array( array( array( 'url' => $image_src ) ), $image_src, 1, array( array( 'url' => $image_src ) ), $msls_imported, 1, 0, 1, $source_post ),
33+
array( array( array( 'url' => 'http://example.com/image-300x300.jpg' ) ), $image_src, 1, array( array( 'url' => 'http://example.com/image-300x300.jpg' ) ), $msls_imported, 1, 0, 1, $source_post ),
34+
);
35+
}
36+
37+
/**
38+
* @dataProvider dataprovider_filter_srcset
39+
*/
40+
public function test_filter_srcset( $source, $imageSrc, $attachmentId, $expected, $msls_imported = null, $times_gpm = 0, $time_dpm = 0, $times_gbp = 0, $blog_post = false ) {
41+
Functions\expect( 'get_post_meta' )->times( $times_gpm )->andReturn( $msls_imported );
42+
Functions\expect( 'delete_post_meta' )->times( $time_dpm );
43+
Functions\expect( 'get_blog_post' )->times( $times_gbp )->andReturn( $blog_post );
44+
45+
$this->assertEquals( $expected, $this->test->filter_srcset( $source, null, $imageSrc, null, $attachmentId ) );
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport;
4+
5+
use lloc\Msls\ContentImport\ContentImporter;
6+
use lloc\Msls\ContentImport\ImportLogger;
7+
use lloc\Msls\ContentImport\Relations;
8+
use lloc\Msls\MslsMain;
9+
use lloc\MslsTests\MslsUnitTestCase;
10+
11+
class TestContentImporter extends MslsUnitTestCase {
12+
13+
14+
public function setUp(): void {
15+
parent::setUp();
16+
17+
$main = \Mockery::mock( MslsMain::class );
18+
19+
$this->test = new ContentImporter( $main );
20+
}
21+
22+
public function test_logger(): void {
23+
$this->test->set_logger( \Mockery::mock( ImportLogger::class ) );
24+
25+
$this->assertInstanceOf( ImportLogger::class, $this->test->get_logger() );
26+
}
27+
28+
public function test_relations(): void {
29+
$this->test->set_relations( \Mockery::mock( Relations::class ) );
30+
31+
$this->assertInstanceOf( Relations::class, $this->test->get_relations() );
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport;
4+
5+
use lloc\Msls\ContentImport\ImportCoordinates;
6+
use lloc\Msls\ContentImport\ImportLogger;
7+
use lloc\Msls\ContentImport\Service;
8+
use lloc\Msls\MslsOptions;
9+
use lloc\MslsTests\MslsUnitTestCase;
10+
use Brain\Monkey\Functions;
11+
12+
class TestImportLogger extends MslsUnitTestCase {
13+
14+
public function setUp(): void {
15+
parent::setUp();
16+
17+
$coordinates = \Mockery::mock( ImportCoordinates::class );
18+
19+
$this->test = new ImportLogger( $coordinates );
20+
}
21+
22+
public function provider_get_data(): array {
23+
return array(
24+
array( 'info' ),
25+
array( 'error' ),
26+
array( 'success' ),
27+
);
28+
}
29+
30+
/**
31+
* @dataProvider provider_get_data
32+
*/
33+
public function test_get_data( $key ): void {
34+
$this->assertArrayHasKey( $key, $this->test->get_data() );
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace lloc\MslsTests\ContentImport;
4+
5+
use lloc\Msls\ContentImport\ImportCoordinates;
6+
use lloc\Msls\ContentImport\Relations;
7+
use lloc\MslsTests\MslsUnitTestCase;
8+
9+
class TestRelations extends MslsUnitTestCase {
10+
11+
public function setUp(): void {
12+
parent::setUp();
13+
14+
$coordinates = \Mockery::mock( ImportCoordinates::class );
15+
16+
$this->test = new Relations( $coordinates );
17+
}
18+
19+
public function test_get_data(): void {
20+
$this->assertIsArray( $this->test->get_data() );
21+
}
22+
}

tests/phpunit/ContentImport/TestService.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
class TestService extends MslsUnitTestCase {
1111

1212
public function test_register_not_active_false(): void {
13-
$options = \Mockery::mock( MslsOptions::class );
13+
$options = \Mockery::mock( MslsOptions::class );
14+
1415
$options->activate_content_import = false;
1516

1617
Functions\expect( 'msls_options' )->once()->andReturn( $options );
@@ -19,7 +20,8 @@ public function test_register_not_active_false(): void {
1920
}
2021

2122
public function test_register_active_true(): void {
22-
$options = \Mockery::mock( MslsOptions::class );
23+
$options = \Mockery::mock( MslsOptions::class );
24+
2325
$options->activate_content_import = true;
2426

2527
Functions\expect( 'msls_options' )->once()->andReturn( $options );

0 commit comments

Comments
 (0)