This repository has been archived by the owner on Nov 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#41 add integrations test for attachment fetching
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
tests/phpunit/WpIntegration/Import/Service/WpAttachmentImporterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace W2M\Test\Unit\Import\Service; | ||
|
||
use Brain; | ||
use W2M\Import\Service; | ||
use W2M\Test\Helper; | ||
|
||
class WpAttachmentImporterTest extends Helper\MonkeyTestCase { | ||
|
||
private $fs_helper; | ||
|
||
/** | ||
* runs before each test | ||
*/ | ||
public function setUp() { | ||
|
||
if ( ! $this->fs_helper ) { | ||
$this->fs_helper = new Helper\FileSystem; | ||
} | ||
|
||
parent::setUp(); | ||
|
||
} | ||
|
||
/** | ||
* @group import | ||
*/ | ||
public function test_import_post() { | ||
|
||
$id_mapper_mock = $this->mock_builder->data_multi_type_id_mapper(); | ||
|
||
$testee = new Service\WpPostImporter( $id_mapper_mock, $http_mock ); | ||
|
||
$post_mock = $this->getMockBuilder( 'W2M\Import\Type\ImportPostInterface' ) | ||
->getMock(); | ||
|
||
$postmeta_mock_single = $this->mock_builder->type_wp_import_meta(); | ||
$postmeta_mock_single->method( 'key' )->willReturn( 'mocky' ); | ||
$postmeta_mock_single->method( 'value' )->willReturn( 'mocky' ); | ||
$postmeta_mock_single->method( 'is_single' )->willReturn( TRUE ); | ||
|
||
$postmeta_mock_array = $this->mock_builder->type_wp_import_meta(); | ||
$postmeta_mock_array->method( 'key' )->willReturn( 'mocky' ); | ||
$postmeta_mock_array->method( 'value' )->willReturn( array( 'mocky', 'mreed' ) ); | ||
$postmeta_mock_array->method( 'is_single' )->willReturn( FALSE ); | ||
|
||
$term_mock = $this->mock_builder->type_wp_term_reference(); | ||
$term_mock->method( 'origin_id' )->willReturn( 113 ); | ||
$term_mock->method( 'taxonomy' )->willReturn( 'category' ); | ||
|
||
/** | ||
* Now define the behaviour of the mock object. Each of the specified | ||
* methods ( @see ImportPostInterface ) should return a proper value! | ||
*/ | ||
$postdata = array( | ||
'title' => 'Mocky test fight', | ||
'origin_author_id' => 12, | ||
'status' => 'draft', | ||
'guid' => 'mocky', | ||
'date' => ( new \DateTime( 'NOW' ) )->format( 'Y-m-d H:i:s' ), | ||
'comment_status' => 'open', | ||
'ping_status' => 'open', | ||
'type' => 'attachment', | ||
'excerpt' => 'Mocky the fighter', | ||
'content' => 'Mock will go for a greate fight.', | ||
'name' => 'mocky', | ||
'origin_parent_post_id' => 42, | ||
'menu_order' => 1, | ||
'password' => 'mocky', | ||
'origin_link' => 'http://wpml2mlp.test/mocky', | ||
'terms' => array( $term_mock ), | ||
'meta' => array( $postmeta_mock_single, $postmeta_mock_array ), | ||
'origin_attachment_url' => 'http://inpsyde.com/wp-content/themes/i/assets/img/logo.png' | ||
); | ||
|
||
$new_parent_id = 15; | ||
$new_author_id = 1; | ||
|
||
$id_mapper_mock->expects( $this->atLeast( 2 ) ) | ||
->method( 'local_id' ) | ||
->withConsecutive( | ||
array( 'post', $postdata[ 'origin_parent_post_id' ] ), | ||
array( 'user', $postdata[ 'origin_author_id' ] ) | ||
)->will( $this->onConsecutiveCalls( $new_parent_id, $new_author_id ) ); | ||
|
||
foreach ( $postdata as $method => $return_value ) { | ||
|
||
$post_mock->expects( $this->atLeast( 1 ) ) | ||
->method( $method ) | ||
->willReturn( $return_value ); | ||
|
||
} | ||
|
||
$testee->import_post( $post_mock ); | ||
|
||
} | ||
|
||
} |