diff --git a/inc/Import/Service/WpPostParser.php b/inc/Import/Service/WpPostParser.php
index 695d763..be28902 100644
--- a/inc/Import/Service/WpPostParser.php
+++ b/inc/Import/Service/WpPostParser.php
@@ -120,6 +120,10 @@ public function parse_post( SimpleXMLElement $document ) {
// ImportPostInterface attribute name
'attribute' => 'origin_id',
),
+ 'post_author' => array(
+ 'cast' => $int_cast,
+ 'attribute' => 'origin_author_id'
+ ),
'comment_status' => array(
'cast' => $string_cast,
'attribute' => 'comment_status',
@@ -155,8 +159,13 @@ public function parse_post( SimpleXMLElement $document ) {
'is_sticky' => array(
'cast' => $bool_cast,
'attribute' => 'is_sticky',
+ ),
+ 'attachment_url' => array(
+ 'cast' => $string_cast,
+ 'attribute' => 'origin_attachment_url'
)
);
+ $missing_attributes = array();
foreach ( $wp_attributes as $node_name => $parameter ) {
$object_param_name = $parameter[ 'attribute' ];
$type_cast_cb = $parameter[ 'cast' ];
@@ -165,9 +174,16 @@ public function parse_post( SimpleXMLElement $document ) {
$post_data[ $object_param_name ] = $type_cast_cb( $wp->{$node_name} );
} else {
$post_data[ $object_param_name ] = $type_cast_cb( '' );
- $this->missing_attribute_error( $document, "wp:{$node_name}" );
+ $missing_attributes[ $node_name ] = $node_name;
}
}
+ if ( 'attachment' !== $post_data[ 'type' ] && isset( $missing_attributes[ 'attachment_url' ] ) ) {
+ unset( $missing_attributes[ 'attachment_url' ] );
+ }
+
+ foreach ( $missing_attributes as $node_name ) {
+ $this->missing_attribute_error( $document, "wp:{$node_name}" );
+ }
if ( isset( $wp->post_date_gmt ) ) {
// Todo: validate the DateTime instance (#38)
diff --git a/tests/phpunit/Unit/Import/Service/WpPostParserTest.php b/tests/phpunit/Unit/Import/Service/WpPostParserTest.php
index 6334060..e71435b 100644
--- a/tests/phpunit/Unit/Import/Service/WpPostParserTest.php
+++ b/tests/phpunit/Unit/Import/Service/WpPostParserTest.php
@@ -31,10 +31,6 @@ public function setUp() {
*/
public function test_parse_post_valid_item( SimpleXMLElement $item, Array $expected ) {
- if ( ! empty( $expected[ 'post' ][ 'origin_attachment_url' ] ) ) {
- $this->markTestSkipped( "Implement Type\\ImportPostInterface::origin_attachment_url first. See #41" );
- }
-
Brain\Monkey::actions()
->expectFired( 'w2m_import_parse_post_error' )
->never();
@@ -132,6 +128,7 @@ public function parse_post_test_data() {
'title' => 'This is the post title',
'guid' => 'http://wpml.to.mlp/?p=4736',
'date' => '2014-04-23 09:45:30',
+ 'origin_author_id' => 4,
'comment_status' => 'open',
'ping_status' => 'open',
'type' => 'post',
@@ -165,6 +162,7 @@ public function parse_post_test_data() {
{$post[ 'origin_id' ]}
+
@@ -243,6 +241,7 @@ public function parse_post_test_data() {
'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',
+ 'origin_author_id' => 1,
'comment_status' => 'open',
'ping_status' => 'open',
'type' => 'attachment',
@@ -276,6 +275,7 @@ public function parse_post_test_data() {
{$post['origin_id']}
+
@@ -335,6 +335,7 @@ public function parse_post_test_data() {
'title' => 'This is the post title',
'guid' => 'http://wpml.to.mlp/?p=4736',
'date' => '2014-04-23 09:45:30',
+ 'origin_author_id' => 655,
'comment_status' => 'open',
'ping_status' => 'open',
'type' => 'post',
@@ -363,6 +364,7 @@ public function parse_post_test_data() {
{$post[ 'origin_id' ]}
+