Skip to content

Refactoring 2 9 #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions includes/Component/Input/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* Class Checkbox
*
* @package lloc\Msls\Component\Input
*/
class Checkbox implements InputInterface {
Expand All @@ -25,17 +26,18 @@ class Checkbox implements InputInterface {
* @param string $value
*/
public function __construct( string $key, ?string $value ) {
$this->key = esc_attr( $key );
$this->key = esc_attr( $key );
$this->selected = checked( 1, $value, false );
}

/**
* @return string
*/
public function render(): string {
return sprintf( '<input type="checkbox" id="%1$s" name="msls[%1$s]" value="1" %2$s/>',
return sprintf(
'<input type="checkbox" id="%1$s" name="msls[%1$s]" value="1" %2$s/>',
$this->key,
$this->selected );
$this->selected
);
}

}
}
2 changes: 1 addition & 1 deletion includes/Component/Input/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function __construct( string $key, array $arr, ?string $selected = null )
public function render(): string {
$name = apply_filters( 'msls_input_select_name', 'msls[' . $this->key . ']' );

return sprintf( '<select id="%1$s" name="%2$s">%3$s</select>', $this->key, $name, $this->options->render() );
return sprintf( '<select id="%1$s" name="%2$s">%3$s</select>', $this->key, esc_attr( $name ), $this->options->render() );
}
}
1 change: 0 additions & 1 deletion includes/ContentImport/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace lloc\Msls\ContentImport;

use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
use lloc\Msls\MslsOptions;
use lloc\Msls\MslsRegistryInstance;

/**
Expand Down
47 changes: 47 additions & 0 deletions tests/phpunit/ContentImport/TestAttachmentPathFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace lloc\MslsTests\ContentImport;

use lloc\Msls\ContentImport\AttachmentPathFinder;
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Functions;

class TestAttachmentPathFinder extends MslsUnitTestCase {

public function setUp(): void {
parent::setUp();

$this->test = new AttachmentPathFinder();
}

public function dataprovider_filter_srcset() {
$image_src = 'http://example.com/image.jpg';
$msls_imported = array(
'blog' => 1,
'post' => 1,
);
$source_post = (object) array( 'guid' => 'http://example.com/image.jpg' );

return array(
array( array(), $image_src, 0, array() ),
array( array(), $image_src, '', array() ),
array( array(), $image_src, null, array() ),
array( array(), $image_src, 1, array(), null, 1, 1 ),
array( array(), $image_src, 1, array(), array( 'random' => 'item' ), 1, 1 ),
array( array( array( 'url' => $image_src ) ), $image_src, 1, array( array( 'url' => $image_src ) ), $msls_imported, 1, 0, 1 ),
array( array( array( 'url' => $image_src ) ), $image_src, 1, array( array( 'url' => $image_src ) ), $msls_imported, 1, 0, 1, $source_post ),
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 ),
);
}

/**
* @dataProvider dataprovider_filter_srcset
*/
public function test_filter_srcset( $source, $imageSrc, $attachmentId, $expected, $msls_imported = null, $times_gpm = 0, $time_dpm = 0, $times_gbp = 0, $blog_post = false ) {
Functions\expect( 'get_post_meta' )->times( $times_gpm )->andReturn( $msls_imported );
Functions\expect( 'delete_post_meta' )->times( $time_dpm );
Functions\expect( 'get_blog_post' )->times( $times_gbp )->andReturn( $blog_post );

$this->assertEquals( $expected, $this->test->filter_srcset( $source, null, $imageSrc, null, $attachmentId ) );
}
}
33 changes: 33 additions & 0 deletions tests/phpunit/ContentImport/TestContentImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace lloc\MslsTests\ContentImport;

use lloc\Msls\ContentImport\ContentImporter;
use lloc\Msls\ContentImport\ImportLogger;
use lloc\Msls\ContentImport\Relations;
use lloc\Msls\MslsMain;
use lloc\MslsTests\MslsUnitTestCase;

class TestContentImporter extends MslsUnitTestCase {


public function setUp(): void {
parent::setUp();

$main = \Mockery::mock( MslsMain::class );

$this->test = new ContentImporter( $main );
}

public function test_logger(): void {
$this->test->set_logger( \Mockery::mock( ImportLogger::class ) );

$this->assertInstanceOf( ImportLogger::class, $this->test->get_logger() );
}

public function test_relations(): void {
$this->test->set_relations( \Mockery::mock( Relations::class ) );

$this->assertInstanceOf( Relations::class, $this->test->get_relations() );
}
}
36 changes: 36 additions & 0 deletions tests/phpunit/ContentImport/TestImportLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace lloc\MslsTests\ContentImport;

use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\ContentImport\ImportLogger;
use lloc\Msls\ContentImport\Service;
use lloc\Msls\MslsOptions;
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Functions;

class TestImportLogger extends MslsUnitTestCase {

public function setUp(): void {
parent::setUp();

$coordinates = \Mockery::mock( ImportCoordinates::class );

$this->test = new ImportLogger( $coordinates );
}

public function provider_get_data(): array {
return array(
array( 'info' ),
array( 'error' ),
array( 'success' ),
);
}

/**
* @dataProvider provider_get_data
*/
public function test_get_data( $key ): void {
$this->assertArrayHasKey( $key, $this->test->get_data() );
}
}
22 changes: 22 additions & 0 deletions tests/phpunit/ContentImport/TestRelations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace lloc\MslsTests\ContentImport;

use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\ContentImport\Relations;
use lloc\MslsTests\MslsUnitTestCase;

class TestRelations extends MslsUnitTestCase {

public function setUp(): void {
parent::setUp();

$coordinates = \Mockery::mock( ImportCoordinates::class );

$this->test = new Relations( $coordinates );
}

public function test_get_data(): void {
$this->assertIsArray( $this->test->get_data() );
}
}
6 changes: 4 additions & 2 deletions tests/phpunit/ContentImport/TestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
class TestService extends MslsUnitTestCase {

public function test_register_not_active_false(): void {
$options = \Mockery::mock( MslsOptions::class );
$options = \Mockery::mock( MslsOptions::class );

$options->activate_content_import = false;

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

public function test_register_active_true(): void {
$options = \Mockery::mock( MslsOptions::class );
$options = \Mockery::mock( MslsOptions::class );

$options->activate_content_import = true;

Functions\expect( 'msls_options' )->once()->andReturn( $options );
Expand Down
Loading