create fetch form remote in importer
This commit is contained in:
parent
fe215d7116
commit
8dd729092c
|
@ -70,16 +70,19 @@ abstract class Importer {
|
|||
}
|
||||
|
||||
/**
|
||||
* get the content form url and creates a file
|
||||
*
|
||||
* @param $url
|
||||
* @return array
|
||||
*/
|
||||
public function fetch_from_remote( $url ){
|
||||
$tmp = download_url( $url );
|
||||
$path_parts = pathinfo( $url );
|
||||
|
||||
$file_array['name'] = $path_parts['basename'];
|
||||
$file_array['tmp_name'] = $tmp;
|
||||
$file_array['size'] = filesize( $tmp );
|
||||
return media_handle_sideload( $file_array, 0 );
|
||||
$tmp = wp_remote_get( $url );
|
||||
if( isset( $tmp['body'] ) ){
|
||||
$file = fopen( $this->get_id().'.txt', 'w' );
|
||||
fwrite( $file, $tmp['body'] );
|
||||
fclose( $file );
|
||||
return $this->set_file( $this->get_id().'.txt' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,4 +68,14 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
// here the session is init already
|
||||
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @group importer
|
||||
*/
|
||||
public function test_fetch_file(){
|
||||
$csv_importer = new Importer\CSV();
|
||||
$id = $csv_importer->get_id();
|
||||
$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wordpress-test/wp-json' );
|
||||
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue