Skip to content

Commit

Permalink
Don't check imported urls while testing
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Nov 29, 2024
1 parent ed108b3 commit fca2904
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 5 additions & 1 deletion includes/class-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 5 additions & 3 deletions includes/class-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 );
Expand All @@ -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 ) {
Expand Down
8 changes: 6 additions & 2 deletions tests/test-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -692,14 +694,16 @@ 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 );
$feeds_imported = 0;
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 );
}
}

0 comments on commit fca2904

Please sign in to comment.