Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Update WpPostParserTest for #41
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Jan 18, 2016
1 parent 2a75326 commit 7cf9fa5
Showing 1 changed file with 106 additions and 9 deletions.
115 changes: 106 additions & 9 deletions tests/phpunit/Unit/Import/Service/WpPostParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

class WpPostParserTest extends Helper\MonkeyTestCase {

public function setUp() {

parent::setUp();

Brain\Monkey::functions()
->when( 'maybe_unserialize' )
->returnArg( 1 );
}

/**
* Test the parsing of a XML that is considered valid.
*
Expand All @@ -22,12 +31,11 @@ class WpPostParserTest extends Helper\MonkeyTestCase {
*/
public function test_parse_post_valid_item( SimpleXMLElement $item, Array $expected ) {

$this->markTestSkipped( "Implement Type\\ImportPostInterface::origin_attachment_url first. See #41" );
Brain\Monkey::actions()
->expectFired( 'w2m_import_parse_post_error' )
->never();
Brain\Monkey::functions()
->when( 'maybe_unserialize' )
->returnArg( 1 );


$testee = new Service\WpPostParser(
$this->mock_builder->common_wp_factory()
Expand All @@ -43,6 +51,7 @@ public function test_parse_post_valid_item( SimpleXMLElement $item, Array $expec
foreach ( $expected[ 'post' ] as $method => $value ) {
if ( 'date' === $method )
continue;

$this->assertSame(
$value,
$result->{$method}(),
Expand Down Expand Up @@ -110,6 +119,7 @@ public function parse_post_test_data() {
$data = array();

$post = array(
'origin_id' => 4736,
'title' => 'This is the post title',
'guid' => 'http://wpml.to.mlp/?p=4736',
'date' => '2014-04-23 09:45:30',
Expand All @@ -124,7 +134,8 @@ public function parse_post_test_data() {
'status' => 'publish',
'origin_parent_post_id' => 0,
'menu_order' => 0,
'password' => ''
'password' => '',

);

$xml = <<<XML
Expand All @@ -136,13 +147,13 @@ public function parse_post_test_data() {
>
<item>
<title>{$post[ 'title' ]}</title>
<link>http://wpml.to.mlp/this-is-the-post-title/</link>
<link>{$post['origin_link']}</link>
<pubDate><![CDATA[{$post[ 'date' ]}]]></pubDate>
<dc:creator><![CDATA[]]></dc:creator>
<guid isPermaLink="false">{$post[ 'guid' ]}</guid>
<excerpt:encoded><![CDATA[{$post[ 'excerpt' ]}]]></excerpt:encoded>
<content:encoded><![CDATA[{$post[ 'content' ]}]]></content:encoded>
<wp:post_id>4736</wp:post_id>
<wp:post_id>{$post[ 'origin_id' ]}</wp:post_id>
<wp:post_date><![CDATA[{$post[ 'date' ]}]]></wp:post_date>
<wp:post_date_gmt><![CDATA[{$post[ 'date' ]}]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[{$post[ 'comment_status' ]}]]></wp:comment_status>
Expand Down Expand Up @@ -214,6 +225,94 @@ public function parse_post_test_data() {
)
);


$post = array(
'origin_id' => 4096,
'title' => 'hello-world-2.jpeg',
'guid' => 'http://wpml.to.mlp/wp-content/uploads/2013/10/hello-world-2.jpeg',
'date' => '2013-10-27 20:13:05',
'comment_status' => 'open',
'ping_status' => 'open',
'type' => 'post',
'is_sticky' => 0,
'origin_link' => 'http://wpml.to.mlp/hello-world/',
'excerpt' => '',
'content' => 'http://wpml.to.mlp/wp-content/uploads/2013/10/hello-world-2.jpeg',
'name' => 'hello-world-2',
'status' => 'inherit',
'origin_parent_post_id' => 0,
'menu_order' => 0,
'password' => '',
'origin_attachment_url' => 'http://wpml.to.mlp/wp-content/uploads/2015/03/hello-world.jpeg'
);

$xml = <<<XML
<root
xmlns:wp="wp"
xmlns:excerpt="excerpt"
xmlns:content="content"
xmlns:dc="dc"
>
<item>
<title>{$post['title']}</title>
<link>{$post['origin_link']}</link>
<pubDate><![CDATA[{$post['date']}]]></pubDate>
<dc:creator><![CDATA[]]></dc:creator>
<guid isPermaLink="false">{$post['guid']}</guid>
<excerpt:encoded><![CDATA[{$post['excerpt']}]]></excerpt:encoded>
<content:encoded><![CDATA[{$post['content']}]]></content:encoded>
<wp:post_id>{$post['origin_id']}</wp:post_id>
<wp:post_date><![CDATA[]]></wp:post_date>
<wp:post_date_gmt><![CDATA[{$post['date']}]]></wp:post_date_gmt>
<wp:comment_status><![CDATA[{$post['comment_status']}]]></wp:comment_status>
<wp:ping_status><![CDATA[{$post['ping_status']}]]></wp:ping_status>
<wp:post_name><![CDATA[{$post['name']}]]></wp:post_name>
<wp:status><![CDATA[{$post['status']}]]></wp:status>
<wp:post_parent>{$post['origin_parent_post_id']}</wp:post_parent>
<wp:menu_order>{$post['menu_order']}</wp:menu_order>
<wp:post_type><![CDATA[{$post['type']}]]></wp:post_type>
<wp:post_password><![CDATA[{$post['password']}]]></wp:post_password>
<wp:is_sticky>{$post['is_sticky']}</wp:is_sticky>
<wp:attachment_url><![CDATA[{$post['origin_attachment_url']}]]></wp:attachment_url>
<wp:postmeta>
<wp:meta_key><![CDATA[wpml_media_processed]]></wp:meta_key>
<wp:meta_value><![CDATA[1]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key><![CDATA[_wp_attached_file]]></wp:meta_key>
<wp:meta_value><![CDATA[2013/10/hello-world-2.jpeg]]></wp:meta_value>
</wp:postmeta>
<wp:translation>
<wp:locale><![CDATA[en_US]]></wp:locale>
<wp:element_id>4096</wp:element_id>
</wp:translation>
</item>
</root>
XML;

$post[ 'is_sticky' ] = (bool) $post[ 'is_sticky' ];

$data[ 'valid_attachment' ] = array(
# 1. Parameter $item
new SimpleXMLElement( $xml ),
# 2. Parameter
array(
'post' => $post,
'terms' => [],
'meta' => [
[ 'key' => 'wpml_media_processed', 'value' => '1', 'is_single' => TRUE ],
[ 'key' => '_wp_attached_file', 'value' => '2013/10/hello-world-2.jpeg', 'is_single' => TRUE ]
],
'locale_relations' => [
[ 'locale' => 'en_US', 'origin_id' => 4096 ],
]
)
);

return $data;
}

Expand All @@ -238,6 +337,7 @@ public function test_parse_post_missing_item() {
->expectFired( 'w2m_import_parse_post_error' )
->once()
->with( $wp_error_mock );

$testee = new Service\WpPostParser( $wp_factory_mock );

$result = $testee->parse_post( $document );
Expand Down Expand Up @@ -386,9 +486,6 @@ public function test_parse_post_meta( SimpleXMLElement $document, Array $expecte
->expectFired( 'w2m_import_parse_post_error' )
->never();

Brain\Monkey::functions()
->when( 'maybe_unserialize' )
->returnArg( 1 );
$testee = new Service\WpPostParser;
$result = $testee->parse_post_meta( $document );

Expand Down

0 comments on commit 7cf9fa5

Please sign in to comment.