From fca2904a3c52c91a3098df62ad8e75209684f541 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 29 Nov 2024 08:53:11 +0100 Subject: [PATCH] Don't check imported urls while testing --- includes/class-import.php | 6 +++++- includes/class-user.php | 8 +++++--- tests/test-feed.php | 8 ++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/includes/class-import.php b/includes/class-import.php index d32e83c2..7be8bebe 100644 --- a/includes/class-import.php +++ b/includes/class-import.php @@ -34,7 +34,7 @@ private static function get_feed_from_opml_node( $friend ) { $username = preg_replace( '/^https?:\/\//', '', $username ); } if ( ! $username ) { - $username = (string) $friend['xmlUrl']; + $username = (string) $xml_url; $username = preg_replace( '/^https?:\/\//', '', $username ); } @@ -67,6 +67,10 @@ private static function get_feed_from_opml_node( $friend ) { ); if ( ! $feed instanceof User_Feed ) { + if ( is_wp_error( $feed ) && apply_filters( 'friends_debug', false ) ) { + wp_trigger_error( __FUNCTION__, $feed->get_error_message() ); + + } return null; } diff --git a/includes/class-user.php b/includes/class-user.php index e56f4b15..73c038b3 100644 --- a/includes/class-user.php +++ b/includes/class-user.php @@ -388,7 +388,7 @@ public function save_feeds( $feeds = array() ) { $errors = new \WP_Error(); foreach ( $feeds as $feed_url => $options ) { if ( ! is_string( $feed_url ) || ! Friends::check_url( $feed_url ) ) { - $errors->add( 'invalid-url', 'An invalid URL was provided' ); + $errors->add( 'invalid-url', 'An invalid URL was provided', $feed_url ); unset( $feeds[ $feed_url ] ); continue; } @@ -406,7 +406,8 @@ public function save_feeds( $feeds = array() ) { $all_urls = array(); foreach ( wp_get_object_terms( $this->get_object_id(), User_Feed::TAXONOMY ) as $term ) { - $all_urls[ $term->name ] = $term->term_id; + $url = str_replace( '&', '&', $term->name ); + $all_urls[ $url ] = $term->term_id; } $user_feeds = wp_set_object_terms( $this->get_object_id(), array_keys( array_merge( $all_urls, $feeds ) ), User_Feed::TAXONOMY ); @@ -415,7 +416,8 @@ public function save_feeds( $feeds = array() ) { } foreach ( wp_get_object_terms( $this->get_object_id(), User_Feed::TAXONOMY ) as $term ) { - $all_urls[ $term->name ] = $term->term_id; + $url = str_replace( '&', '&', $term->name ); + $all_urls[ $url ] = $term->term_id; } foreach ( $feeds as $url => $feed_options ) { diff --git a/tests/test-feed.php b/tests/test-feed.php index 5ad1c724..e989e2b9 100644 --- a/tests/test-feed.php +++ b/tests/test-feed.php @@ -680,6 +680,8 @@ public function test_podcast() { } public function test_import_feedland_opml() { + add_filter( 'friends_pre_check_url', '__return_true' ); + $opml = file_get_contents( __DIR__ . '/data/feedland.opml' ); $feeds = Import::opml( $opml ); $users_created = count( $feeds ); @@ -692,6 +694,8 @@ public function test_import_feedland_opml() { } public function test_import_friends_opml() { + add_filter( 'friends_pre_check_url', '__return_true' ); + $opml = file_get_contents( __DIR__ . '/data/friends.opml' ); $feeds = Import::opml( $opml ); $users_created = count( $feeds ); @@ -699,7 +703,7 @@ public function test_import_friends_opml() { foreach ( $feeds as $user => $user_feeds ) { $feeds_imported += count( $user_feeds ); } - $this->assertEquals( 19, $users_created ); - $this->assertEquals( 20, $feeds_imported ); + $this->assertEquals( 22, $users_created ); + $this->assertEquals( 24, $feeds_imported ); } }