Skip to content

Commit

Permalink
add test for download
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Foti <foti.giuseppe@gmail.com>
  • Loading branch information
MocioF committed Apr 22, 2024
1 parent d088eb8 commit e7ded1b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
14 changes: 9 additions & 5 deletions admin/class-gcmi-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,25 @@ class GCMI_Activator {
),
array(
'name' => 'stati',
/* 'downd_name' => 'stati.zip', */
'downd_name' => 'stati.csv',
'featured_csv' => 'stati.csv',
/* 'remote_file' => 'Elenco-codici-e-denominazioni-unita-territoriali-estere.zip', */
'remote_file' => 'Elenco-codici-e-denominazioni-al-31_12_2023.csv',
/* 'remote_URL' => 'https://www.istat.it/it/files//2011/01/Elenco-codici-e-denominazioni-unita-territoriali-estere.zip', */
'remote_URL' => 'https://raw.githubusercontent.com/MocioF/campi-moduli-italiani/main/assets/data/Elenco-codici-e-denominazioni-al-31_12_2023.csv',
'table_name' => GCMI_TABLE_PREFIX . 'stati',
'optN_dwdtime' => 'gcmi_stati_downloaded_time',
'optN_remoteUpd' => 'gcmi_stati_remote_file_time',
'remoteUpd_method' => 'get_headers_by_get',
/* 'file_type' => 'zip', */
'file_type' => 'csv',
'orig_encoding' => 'ISO-8859-1',

/**
* Valori utilizzati per scaricare il file da istat
*
* 'downd_name' => 'stati.zip',
* 'remote_file' => 'Elenco-codici-e-denominazioni-unita-territoriali-estere.zip',
* 'remote_URL' => 'https://www.istat.it/it/files//2011/01/Elenco-codici-e-denominazioni-unita-territoriali-estere.zip',
* 'file_type' => 'zip',
*/
),
array(
'name' => 'stati_cessati',
Expand Down Expand Up @@ -796,7 +801,6 @@ public static function download_file( $remoteurl, $tmp_dwld_dir, $filename ) {
'timeout' => 300,
'stream' => true,
'sslverify' => true,
/* 'sslcertificates' => GCMI_PLUGIN_DIR . '/admin/assets/istat-it-catena.pem', */
'filename' => $tmpfname,
);
if( strpos( $remoteurl, 'istat.it' ) !== false ) {
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/test-class-campi-moduli-italiani-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,27 @@ public function provideDownloadedTimes() {
),
);
}

/**
* @dataProvider remoteFileArray
* @group downloadf
*/
public function test_download_file( $name, $downd_name, $featured_csv, $remote_file, $remote_URL ) {
$tmp_dir = $this->gcmi_activator::make_tmp_dwld_dir();
$this->gcmi_activator->download_file( $remote_URL, $tmp_dir, $downd_name );
$tmpfname = $tmp_dir . $downd_name;
$this->assertFileExists( $tmpfname );
}

public function remoteFileArray(){
$main_array = GCMI_Activator::$database_file_info;
$download_array = array();
foreach( $main_array as $item ) {
if ( 'html' !== $item['file_type'] ) {
$download_array[] = $item;
}
}
return $download_array;
}

}

0 comments on commit e7ded1b

Please # to comment.