Skip to content
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

Importer base classes tested #401

Merged
merged 1 commit into from
Nov 15, 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
4 changes: 1 addition & 3 deletions includes/ContentImport/Importers/ImportersBaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public function make( ImportCoordinates $import_coordinates ) {
$slug = $import_coordinates->get_importer_for( $type ) ?: $first;

// if there is some incoherence return the null-doing base importer
$class = ! empty( $slug ) && isset( $map[ $slug ] )
? $map[ $slug ]
: BaseImporter::class;
$class = ! empty( $slug ) && isset( $map[ $slug ] ) ? $map[ $slug ] : BaseImporter::class;

return new $class( $import_coordinates );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace lloc\MslsTests\ContentImport\Importers\PostFields;

use Brain\Monkey\Functions;
use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\ContentImport\Importers\PostFields\Duplicating;
use lloc\MslsTests\MslsUnitTestCase;

class TestDuplicating extends MslsUnitTestCase {

public function testImport(): void {
Functions\expect( 'wp_insert_post' )->once();

$post = \Mockery::mock( \WP_Post::class );
$post->post_excerpt = 'excerpt';
$post->post_title = 'title';
$post->post_content = 'content';
$post->post_content_filtered = 'content_filtered';

$coordinates = \Mockery::mock( ImportCoordinates::class );
$coordinates->source_post = $post;

$result = array(
'post_type' => 'post',
'post_content' => 'content',
'post_content_filtered' => 'content_filtered',
'post_title' => 'title',
'post_excerpt' => 'excerpt',
);

$this->assertEquals( $result, ( new Duplicating( $coordinates ) )->import( array() ) );
}

public function testFilterFields(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );

$test = new Duplicating( $coordinates );

$result = array(
'post_content',
'post_content_filtered',
'post_title',
'post_excerpt',
);

$this->assertEquals( $result, $test->filter_fields() );
}
}
28 changes: 28 additions & 0 deletions tests/phpunit/ContentImport/Importers/TestImportersBaseFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace lloc\MslsTests\ContentImport\Importers;

use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\ContentImport\Importers\ImportersBaseFactory;
use lloc\MslsTests\MslsUnitTestCase;
use Mockery\Mock;

class TestImportersBaseFactory extends MslsUnitTestCase {

public function testMake(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
$coordinates->shouldReceive( 'get_importer_for' )->andReturn( 'post-fields' );

$test = \Mockery::mock( ImportersBaseFactory::class )->makePartial();

$this->expectException( \RuntimeException::class );

$test->make( $coordinates );
}

public function testDetails(): void {
$test = \Mockery::mock( ImportersBaseFactory::class )->makePartial();

$this->assertNotEmpty( $test->details() );
}
}
19 changes: 19 additions & 0 deletions tests/phpunit/ContentImport/Importers/TestMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace lloc\MslsTests\ContentImport\Importers;

use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\ContentImport\Importers\Map;
use lloc\MslsTests\MslsUnitTestCase;

class TestMap extends MslsUnitTestCase {

public function testMake(): void {
$coordinates = \Mockery::mock( ImportCoordinates::class );
$coordinates->shouldReceive( 'get_importer_for' )->andReturn( 'post-fields' );

$result = ( new Map() )->make( $coordinates );

$this->assertNotEmpty( $result );
}
}
13 changes: 13 additions & 0 deletions tests/phpunit/ContentImport/Importers/TestPostFieldsImporters.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

namespace lloc\MslsTests\ContentImport\Importers;

use brain\Monkey\Filters;
use lloc\Msls\ContentImport\ImportCoordinates;
use lloc\Msls\ContentImport\Importers\PostFields\Duplicating;
use lloc\Msls\ContentImport\Importers\PostFieldsImporters;
use lloc\MslsTests\MslsUnitTestCase;

class TestPostFieldsImporters extends MslsUnitTestCase {

public function testMake(): void {
$importer = \Mockery::mock( Duplicating::class );

$test = new PostFieldsImporters();

Filters\expectApplied( 'msls_content_import_post-fields_importer' )->once()->andReturn( $importer );

$this->assertEquals( $importer, $test->make( new ImportCoordinates() ) );
}

public function testDetails(): void {
$test = new PostFieldsImporters();

Expand Down
Loading