Skip to content

Commit

Permalink
Tests cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
lloc committed Dec 15, 2024
1 parent ffea2b4 commit bd2fadf
Show file tree
Hide file tree
Showing 68 changed files with 555 additions and 460 deletions.
1 change: 0 additions & 1 deletion includes/MslsBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class MslsBlock {


protected MslsOptions $options;

public function __construct( MslsOptions $options ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Component/Icon/TestIconPng.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use lloc\Msls\Component\Icon\IconPng;
use lloc\MslsTests\MslsUnitTestCase;

class TestIconPng extends MslsUnitTestCase {
final class TestIconPng extends MslsUnitTestCase {

public function test_get(): void {
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 4 ) . '/' );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Component/Icon/TestIconSvg.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use lloc\Msls\Component\Icon\IconSvg;
use lloc\MslsTests\MslsUnitTestCase;

class TestIconSvg extends MslsUnitTestCase {
final class TestIconSvg extends MslsUnitTestCase {

public function test_get(): void {
Functions\when( 'plugin_dir_path' )->justReturn( dirname( __DIR__, 4 ) . '/' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use lloc\Msls\ContentImport\Importers\Attachments\Linking;
use lloc\MslsTests\MslsUnitTestCase;

class TestLinking extends MslsUnitTestCase {
final class TestLinking extends MslsUnitTestCase {

public function testImport(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use lloc\Msls\ContentImport\Importers\PostFields\Duplicating;
use lloc\MslsTests\MslsUnitTestCase;

class TestDuplicating extends MslsUnitTestCase {
final class TestDuplicating extends MslsUnitTestCase {

public function testImport(): void {
Functions\expect( 'wp_insert_post' )->once();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use function Brain\Monkey\Functions;

class TestDuplicating extends MslsUnitTestCase {
final class TestDuplicating extends MslsUnitTestCase {

public function testImport(): void {
Functions\expect( 'switch_to_blog' )->twice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use lloc\Msls\ContentImport\Importers\AttachmentsImporters;
use lloc\MslsTests\MslsUnitTestCase;

class TestAttachmentsImporters extends MslsUnitTestCase {
final class TestAttachmentsImporters extends MslsUnitTestCase {


public function testDetails(): void {
Expand Down
30 changes: 20 additions & 10 deletions tests/phpunit/ContentImport/Importers/TestBaseImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,44 @@
use lloc\Msls\ContentImport\Relations;
use lloc\MslsTests\MslsUnitTestCase;

class TestBaseImporter extends MslsUnitTestCase {

public function setUp(): void {
parent::setUp();
final class TestBaseImporter extends MslsUnitTestCase {

private function BaseImporterFactory(): BaseImporter {
$import_coordinates = \Mockery::mock( ImportCoordinates::class );
$this->test = new BaseImporter( $import_coordinates );

return new BaseImporter( $import_coordinates );
}

public function testImport(): void {
$this->assertEquals( array(), $this->test->import( array() ) );
$test = $this->BaseImporterFactory();

$this->assertEquals( array(), $test->import( array() ) );
}

public function testSetImportCoordinates(): void {
$import_coordinates = \Mockery::mock( ImportCoordinates::class );

$this->expectNotToPerformAssertions();
$this->test->set_import_coordinates( $import_coordinates );

$test = $this->BaseImporterFactory();

$test->set_import_coordinates( $import_coordinates );
}

public function testGetLogger(): void {
$this->assertInstanceOf( ImportLogger::class, $this->test->get_logger() );
$test = $this->BaseImporterFactory();

$this->assertInstanceOf( ImportLogger::class, $test->get_logger() );
}
public function testGetRelations(): void {
$this->assertInstanceOf( Relations::class, $this->test->get_relations() );
$test = $this->BaseImporterFactory();

$this->assertInstanceOf( Relations::class, $test->get_relations() );
}

public function testInfo(): void {
$this->assertInstanceOf( \stdClass::class, $this->test->info() );
$test = $this->BaseImporterFactory();

$this->assertInstanceOf( \stdClass::class, $test->info() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use lloc\MslsTests\MslsUnitTestCase;
use Mockery\Mock;

class TestImportersBaseFactory extends MslsUnitTestCase {
final class TestImportersBaseFactory extends MslsUnitTestCase {

public function testMake(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/ContentImport/Importers/TestMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use lloc\Msls\ContentImport\Importers\Map;
use lloc\MslsTests\MslsUnitTestCase;

class TestMap extends MslsUnitTestCase {
final class TestMap extends MslsUnitTestCase {

public function testMake(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use lloc\Msls\ContentImport\Importers\PostFieldsImporters;
use lloc\MslsTests\MslsUnitTestCase;

class TestPostFieldsImporters extends MslsUnitTestCase {
final class TestPostFieldsImporters extends MslsUnitTestCase {

public function testMake(): void {
$importer = \Mockery::mock( Duplicating::class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use lloc\Msls\ContentImport\Importers\PostMetaImporters;
use lloc\MslsTests\MslsUnitTestCase;

class TestPostMetaImporters extends MslsUnitTestCase {
final class TestPostMetaImporters extends MslsUnitTestCase {

public function testDetails(): void {
$test = new PostMetaImporters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use lloc\Msls\ContentImport\Importers\PostThumbnailImporters;
use lloc\MslsTests\MslsUnitTestCase;

class TestPostThumbnailImporters extends MslsUnitTestCase {
final class TestPostThumbnailImporters extends MslsUnitTestCase {

public function testDetails(): void {
$test = new PostThumbnailImporters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use lloc\Msls\ContentImport\Importers\TermsImporters;
use lloc\MslsTests\MslsUnitTestCase;

class TestTermsImporters extends MslsUnitTestCase {
final class TestTermsImporters extends MslsUnitTestCase {

public function testDetails(): void {
$test = new TermsImporters();
Expand Down
18 changes: 8 additions & 10 deletions tests/phpunit/ContentImport/LogWriters/TestAdminNoticeLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
use lloc\Msls\ContentImport\LogWriters\AdminNoticeLogger;
use lloc\MslsTests\MslsUnitTestCase;

class TestAdminNoticeLogger extends MslsUnitTestCase {

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

$this->test = new AdminNoticeLogger();
}
final class TestAdminNoticeLogger extends MslsUnitTestCase {

public function testGetTransient(): void {
$this->assertEquals( 'msls_last_import_log', $this->test->get_transient() );
$test = new AdminNoticeLogger();

$this->assertEquals( 'msls_last_import_log', $test->get_transient() );
}

public function testWrite(): void {
Expand All @@ -29,10 +25,12 @@ public function testWrite(): void {
$coordinates->dest_blog_id = 2;
$coordinates->dest_post_id = 13;

$this->test->set_import_coordinates( $coordinates );
$test = new AdminNoticeLogger();

$test->set_import_coordinates( $coordinates );

$data = array( 'info', array( 'foo' ) );
$this->test->write( $data );
$test->write( $data );

$this->expectNotToPerformAssertions();
}
Expand Down
16 changes: 7 additions & 9 deletions tests/phpunit/ContentImport/TestAttachmentPathFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Functions;

class TestAttachmentPathFinder extends MslsUnitTestCase {

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

$this->test = new AttachmentPathFinder();
}
final class TestAttachmentPathFinder extends MslsUnitTestCase {

public static function dataprovider_filter_srcset(): array {
$image_src = 'http://example.com/image.jpg';
Expand Down Expand Up @@ -42,7 +36,9 @@ public function test_filter_srcset( $source, $imageSrc, $attachmentId, $expected
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 ) );
$test = new AttachmentPathFinder();

$this->assertEquals( $expected, $test->filter_srcset( $source, null, $imageSrc, null, $attachmentId ) );
}

public static function dataprovider_filter_attachement_url(): array {
Expand Down Expand Up @@ -71,6 +67,8 @@ public function test_filter_attachment_url( string $image_src, $source_post, int
Functions\expect( 'delete_post_meta' )->zeroOrMoreTimes();
Functions\expect( 'get_blog_post' )->zeroOrMoreTimes()->andReturn( $source_post );

$this->assertEquals( $source_post->guid, $this->test->filter_attachment_url( $image_src, $attachment_id ) );
$test = new AttachmentPathFinder();

$this->assertEquals( $source_post->guid, $test->filter_attachment_url( $image_src, $attachment_id ) );
}
}
33 changes: 19 additions & 14 deletions tests/phpunit/ContentImport/TestContentImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,56 @@
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Actions;

class TestContentImporter extends MslsUnitTestCase {


public function setUp(): void {
parent::setUp();
final class TestContentImporter extends MslsUnitTestCase {

private function ContentImporterFactory(): ContentImporter {
$main = \Mockery::mock( MslsMain::class );
$main->shouldReceive( 'verify_nonce' )->andReturnTrue();

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

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

$test->set_logger( \Mockery::mock( ImportLogger::class ) );

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

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

$this->assertInstanceOf( Relations::class, $this->test->get_relations() );
$test->set_relations( \Mockery::mock( Relations::class ) );

$this->assertInstanceOf( Relations::class, $test->get_relations() );
}

public function test_handle_import(): void {
$this->assertEquals( array(), $this->test->handle_import() );
$test = $this->ContentImporterFactory();

$this->assertEquals( array(), $test->handle_import() );
}

public function test_parse_sources_no_post(): void {
$this->assertFalse( $this->test->parse_sources() );
$test = $this->ContentImporterFactory();

$this->assertFalse( $test->parse_sources() );
}

public function test_handle_false(): void {
$this->expectNotToPerformAssertions();

Actions\expectAdded( 'msls_main_save' )->once();

$this->test->handle( false );
$this->ContentImporterFactory()->handle( false );
}

public function test_handle_true(): void {
$this->expectNotToPerformAssertions();

Actions\expectRemoved( 'msls_main_save' )->once();

$this->test->handle( true );
$this->ContentImporterFactory()->handle( true );
}
}
43 changes: 24 additions & 19 deletions tests/phpunit/ContentImport/TestImportCoordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
use lloc\MslsTests\MslsUnitTestCase;
use Brain\Monkey\Functions;

class TestImportCoordinates extends MslsUnitTestCase {
final class TestImportCoordinates extends MslsUnitTestCase {

public function ImportCoordinatesFactory(): ImportCoordinates {
$test = new ImportCoordinates();

public function setUp(): void {
parent::setUp();
$test->source_blog_id = 1;
$test->source_post_id = 42;
$test->dest_blog_id = 2;
$test->dest_post_id = 13;
$test->source_post = \Mockery::mock( \WP_Post::class );
$test->source_lang = 'de_DE';
$test->dest_lang = 'it_IT';

$this->test = new ImportCoordinates();

$this->test->source_blog_id = 1;
$this->test->source_post_id = 42;
$this->test->dest_blog_id = 2;
$this->test->dest_post_id = 13;
$this->test->source_post = \Mockery::mock( \WP_Post::class );
$this->test->source_lang = 'de_DE';
$this->test->dest_lang = 'it_IT';
return $test;
}

public static function providerValidate(): array {
$post = \Mockery::mock( \WP_Post::class );

return array(
array( null, null, null, null, null, false ),
array( $post, null, null, null, null, false ),
Expand All @@ -42,9 +42,10 @@ public function testValidate( $post_a, $post_b, $source_post, $lang_a, $lang_b,
Functions\expect( 'get_blog_post' )->andReturn( $post_a, $post_b );
Functions\expect( 'get_blog_option' )->andReturn( $lang_a, $lang_b );

$this->test->source_post = $source_post;
$test = $this->ImportCoordinatesFactory();
$test->source_post = $source_post;

$this->assertEquals( $expected, $this->test->validate() );
$this->assertEquals( $expected, $test->validate() );
}

public function testParseImportersFromPost(): void {
Expand All @@ -61,16 +62,20 @@ public function testParseImportersFromPost(): void {
->with( INPUT_GET, ImportCoordinates::IMPORTERS_GLOBAL_KEY, FILTER_FORCE_ARRAY )
->andReturn( array( 'pagesType' => 'pagesSlug' ) );

$this->assertNull( $this->test->get_importer_for( 'pagesType' ) );
$test = $this->ImportCoordinatesFactory();

$this->test->parse_importers_from_request();
$this->assertNull( $test->get_importer_for( 'pagesType' ) );

$this->assertEquals( 'pagesSlug', $this->test->get_importer_for( 'pagesType' ) );
$test->parse_importers_from_request();

$this->assertEquals( 'pagesSlug', $test->get_importer_for( 'pagesType' ) );
}

public function testSetImporterFor(): void {
$this->test->set_importer_for( 'postsType', 'postsSlug' );
$test = $this->ImportCoordinatesFactory();

$test->set_importer_for( 'postsType', 'postsSlug' );

$this->assertEquals( 'postsSlug', $this->test->get_importer_for( 'postsType' ) );
$this->assertEquals( 'postsSlug', $test->get_importer_for( 'postsType' ) );
}
}
Loading

0 comments on commit bd2fadf

Please sign in to comment.