Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests #226

Merged
merged 3 commits into from
Jun 3, 2024
Merged

tests #226

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test/Generated*
test/InputFiles3*
test/test1/*
newdir2/
/companion
/releases
src/docto.exe
*.rsm
Expand Down
26 changes: 26 additions & 0 deletions companion/app/Services/FileGatherService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Services;

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;

class FileGatherService
{
public static function GatherFiles(Collection $list, $tempDirName)
{
// remove exisitn files
if (\Illuminate\Support\Facades\Storage::exists($tempDirName)){
\Illuminate\Support\Facades\Storage::deleteDirectory($tempDirName);
}

$tempDirPath = Storage::path($tempDirName);
$list->each(function ($dir) use ($tempDirName, $tempDirPath){
$inputfilesdir = \Illuminate\Support\Facades\Storage::path('inputfiles\\' . $dir );
$cmd = "xcopy \"$inputfilesdir\" \"$tempDirPath\\\" ";
$result = \Illuminate\Support\Facades\Process::run( $cmd );
echo "\n" . $result->output() . "\n";
});
return collect(Storage::listContents($tempDirName));
}
}
4 changes: 4 additions & 0 deletions companion/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
|
*/

'docto' => [
'path' => env('DOCTO_PATH','..\\exe\\32\\docto.exe'),
],

'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
Expand Down
17 changes: 7 additions & 10 deletions companion/tests/Feature/Remove/RemoveInputFilePestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

it('test deletes files from directory', function (){
// setup
if (\Illuminate\Support\Facades\Storage::exists('inputfilestemp')){
\Illuminate\Support\Facades\Storage::deleteDirectory('inputfilestemp');
}
$testinputfilesdir = \Illuminate\Support\Facades\Storage::path('inputfiles\\plain');
// $testinputfilesdir = \Illuminate\Support\Facades\Storage::path('inputfiles\\plain');
$testinputfilesdir_temp = \Illuminate\Support\Facades\Storage::path('inputfilestemp');



$testoutputdir_temp = \Illuminate\Support\Facades\Storage::path('outputtemp2');
// echo "\n". $testoutputdir_temp;
\Illuminate\Support\Facades\Storage::createDirectory('outputtemp2');
$cmd = "xcopy \"$testinputfilesdir\" \"$testinputfilesdir_temp\\\" ";
// $cmd = "xcopy \"$testinputfilesdir\" \"$testinputfilesdir_temp\\\" ";
// echo "\n". $cmd;
$result = \Illuminate\Support\Facades\Process::run( $cmd );
// $result = \Illuminate\Support\Facades\Process::run( $cmd );

//echo "\n" . $result->output() . "\n";
$dirfiles = collect(\Illuminate\Support\Facades\Storage::listContents('inputfilestemp'));
// $dirfiles = collect(\Illuminate\Support\Facades\Storage::listContents('inputfilestemp'));
$dirfiles = \App\Services\FileGatherService::GatherFiles(collect(['plain']),'inputfilestemp');
$docfiles = $dirfiles->filter(function ($item){
return str($item->path())->endsWith('.doc');
});
Expand All @@ -28,9 +26,8 @@

$dirfilescount = $dirfiles->count();
// do conversion
$doctocmd = <<<CMD
..\\src\\docto.exe -WD -f $testinputfilesdir_temp -fx .doc -o $testoutputdir_temp -t wdFormatPDF -R true
CMD;
$docto = config('services.docto.path');
$doctocmd = "$docto -WD -f $testinputfilesdir_temp -fx .doc -o $testoutputdir_temp -t wdFormatPDF -R true";
// echo $doctocmd;
$output = \Illuminate\Support\Facades\Process::run($doctocmd);
// echo $output->output();
Expand Down
17 changes: 17 additions & 0 deletions companion/tests/Feature/output/OutputDirCreationPestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Illuminate\Support\Facades\Process;

test('can create non existant directory', function () {
$gatherdir = uniqid();
$outputdir = uniqid();
$files = \App\Services\FileGatherService::GatherFiles(collect(['single']),$gatherdir);
$docto = config('services.docto.path');
$inputdir = \Illuminate\Support\Facades\Storage::path($gatherdir);
$outputdir = \Illuminate\Support\Facades\Storage::path($outputdir);
$cmd = "$docto -WD -f $inputdir -o $outputdir -t wdFormatHTML";
echo $cmd;
$output = Process::run($cmd);
expect(\Illuminate\Support\Facades\Storage::exists($outputdir))->toBeTrue();

});