2016-11-03 07:09:47 +11:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Backend\Models\ImportModel;
|
|
|
|
use System\Models\File as FileModel;
|
|
|
|
|
|
|
|
class ExampleDbImportModel extends ImportModel
|
|
|
|
{
|
|
|
|
public $rules = [];
|
|
|
|
|
|
|
|
public function importData($results, $sessionKey = null)
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ImportModelDbTest extends PluginTestCase
|
|
|
|
{
|
|
|
|
public function testGetImportFilePath()
|
|
|
|
{
|
|
|
|
$model = new ExampleDbImportModel;
|
|
|
|
$sessionKey = uniqid('session_key', true);
|
|
|
|
|
|
|
|
$file1 = FileModel::create([
|
2018-04-19 01:57:27 -06:00
|
|
|
'data' => base_path().'/tests/fixtures/backend/reference/file1.txt',
|
|
|
|
'is_public' => false,
|
2016-11-03 07:09:47 +11:00
|
|
|
]);
|
|
|
|
|
|
|
|
$file2 = FileModel::create([
|
2018-04-19 01:57:27 -06:00
|
|
|
'data' => base_path().'/tests/fixtures/backend/reference/file2.txt',
|
|
|
|
'is_public' => false,
|
2016-11-03 07:09:47 +11:00
|
|
|
]);
|
|
|
|
|
|
|
|
$model->import_file()->add($file1, $sessionKey);
|
|
|
|
$model->import_file()->add($file2, $sessionKey);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$file2->getLocalPath(),
|
|
|
|
$model->getImportFilePath($sessionKey),
|
|
|
|
'ImportModel::getImportFilePath() should return the last uploaded file.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|