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

Commit

Permalink
Add missing attributes in WpPostParser
Browse files Browse the repository at this point in the history
parse wp:attachment_url see #41
parse wp:post_author see #37
  • Loading branch information
dnaber-de committed Jan 29, 2016
1 parent 0e88039 commit 3f93b09
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 17 additions & 1 deletion inc/Import/Service/WpPostParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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' ];
Expand All @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions tests/phpunit/Unit/Import/Service/WpPostParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -165,6 +162,7 @@ public function parse_post_test_data() {
<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:post_author><![CDATA[{$post[ 'origin_author_id' ]}]]></wp:post_author>
<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>
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -276,6 +275,7 @@ public function parse_post_test_data() {
<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:post_author><![CDATA[{$post[ 'origin_author_id' ]}]]></wp:post_author>
<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>
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -363,6 +364,7 @@ public function parse_post_test_data() {
<wp:post_id xmlns:wp="http://wordpress.org/export/1.2/">{$post[ 'origin_id' ]}</wp:post_id>
<wp:post_date xmlns:wp="http://wordpress.org/export/1.2/"><![CDATA[{$post[ 'date' ]}]]></wp:post_date>
<wp:post_date_gmt xmlns:wp="http://wordpress.org/export/1.2/"><![CDATA[{$post[ 'date' ]}]]></wp:post_date_gmt>
<wp:post_author xmlns:wp="http://wordpress.org/export/1.2/"><![CDATA[{$post[ 'origin_author_id' ]}]]></wp:post_author>
<wp:comment_status xmlns:wp="http://wordpress.org/export/1.2/"><![CDATA[{$post[ 'comment_status' ]}]]></wp:comment_status>
<wp:ping_status xmlns:wp="http://wordpress.org/export/1.2/"><![CDATA[{$post[ 'ping_status' ]}]]></wp:ping_status>
<wp:post_name xmlns:wp="http://wordpress.org/export/1.2/"><![CDATA[{$post[ 'name' ]}]]></wp:post_name>
Expand Down

0 comments on commit 3f93b09

Please sign in to comment.