Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
33.33% covered (danger)
33.33%
2 / 6
CRAP
93.44% covered (success)
93.44%
57 / 61
DocserverToolsControllerTest
0.00% covered (danger)
0.00%
0 / 1
33.33% covered (danger)
33.33%
2 / 6
10.03
93.44% covered (success)
93.44%
57 / 61
 testSetRights
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 testDoFingerprint
0.00% covered (danger)
0.00%
0 / 1
2.00
92.31% covered (success)
92.31%
12 / 13
 testControlFingerprint
0.00% covered (danger)
0.00%
0 / 1
2.00
92.86% covered (success)
92.86%
13 / 14
 testCopyOnDocserver
0.00% covered (danger)
0.00%
0 / 1
2.00
93.75% covered (success)
93.75%
15 / 16
 testWashTmp
0.00% covered (danger)
0.00%
0 / 1
2.01
87.50% covered (success)
87.50%
7 / 8
 testCreatePathOnDocServer
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
<?php
namespace MaarchTest;
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
require_once __DIR__.'/define.php';
class DocserverToolsControllerTest extends \PHPUnit_Framework_TestCase
{
    public function testSetRights()
    {
        $action = new \Core\Controllers\DocserverToolsController();
        $aArgs = [
            'path' => '/opt/maarch/docservers/'
        ];
        $response = $action->setRights($aArgs);
        $this->assertTrue($response['setRights']);
    }
    public function testDoFingerprint()
    {
        $action = new \Core\Controllers\DocserverToolsController();
        $path = $_SESSION['config']['tmppath'] . '/test/';
        if (!is_dir($path)) {
            mkdir($path);
        }
        $fileSource = 'test_source.txt';
        //creates an empty file
        $fp = fopen($path . $fileSource, 'a');
        fwrite($fp, 'a unit test');
        fclose($fp);
        $aArgs = [
            'path'            => $fileSource,
            'fingerprintMode' => 'NONE',
        ];
        $response = $action->doFingerprint($aArgs);
        $this->assertEquals($response['setRights'], 0);
    }
    public function testControlFingerprint()
    {
        $action = new \Core\Controllers\DocserverToolsController();
        $path = $_SESSION['config']['tmppath'] . '/test/';
        if (!is_dir($path)) {
            mkdir($path);
        }
        $fileSource = 'test_source.txt';
        $fp = fopen($path . $fileSource, 'a');
        fwrite($fp, 'a unit test');
        fclose($fp);
        $aArgs = [
            'pathInit'        => $path . $fileSource,
            'pathTarget'      => $path . $fileSource,
            'fingerprintMode' => 'sha256',
        ];
        $response = $action->controlFingerprint($aArgs);
        $this->assertTrue($response['controlFingerprint']);
    }
    public function testCopyOnDocserver()
    {
        $action = new \Core\Controllers\DocserverToolsController();
        $path = $_SESSION['config']['tmppath'] . '/test/';
        if (!is_dir($path)) {
            mkdir($path);
        }
        $fileSource = 'test_source.txt';
        $fileDest = 'test_dest.txt';
        $fp = fopen($path . $fileSource, 'a');
        fwrite($fp, 'a unit test');
        fclose($fp);
        $aArgs = [
            'sourceFilePath'             => $path . $fileSource,
            'destinationDir'             => $path,
            'fileDestinationName'        => $fileDest,
            'docserverSourceFingerprint' => 'sha256',
        ];
        $response = $action->copyOnDocserver($aArgs);
        $this->assertArrayHasKey('destinationDir', $response['copyOnDocserver']);
    }
    public function testWashTmp()
    {
        $action = new \Core\Controllers\DocserverToolsController();
        $path = $_SESSION['config']['tmppath'] . '/test/';
        
        if (!is_dir($path)) {
            mkdir($path);
        }
        $aArgs = [
            'path'        => $path,
            'contentOnly' => false,
        ];
        $response = $action->washTmp($aArgs);
        $this->assertTrue($response['washTmp']);
    }
    public function testCreatePathOnDocServer()
    {
        $action = new \Core\Controllers\DocserverToolsController();
        $aArgs = [
            'path' => '/opt/maarch/new_docservers/MaarchCourrierGit/manual/'
        ];
        $response = $action->createPathOnDocServer($aArgs);
        $this->assertArrayHasKey('destinationDir', $response['createPathOnDocServer']);
    }
}