Jarves\Tests\File\FileRESTTest::testCopyFile PHP Method

testCopyFile() public method

public testCopyFile ( )
    public function testCopyFile()
    {
        $id = dechex(time() / mt_rand(100, 500));
        $testPath = '/test_' . $id . '.txt';
        $response = $this->restCall('/jarves/admin/file', 'PUT', ['path' => $testPath]);
        $this->assertEquals(true, $response['data']);
        $response = $this->restCall('/jarves/admin/file/single?path=' . $testPath);
        $file = $response['data'];
        $this->assertNotNull($file);
        $this->assertGreaterThan(0, $file['id']);
        $this->assertEquals($testPath, $file['path']);
        $this->assertEquals(basename($testPath), $file['name']);
        $this->assertEquals(dirname($testPath), $file['dir']);
        $this->assertEquals(true, $file['writeAccess']);
        $this->assertEquals('file', $file['type']);
        $id = dechex(time() / mt_rand(100, 500));
        $testDirPath = '/test_' . $id;
        $response = $this->restCall('/jarves/admin/file/dir', 'PUT', ['path' => $testDirPath]);
        $this->assertEquals(true, $response['data']);
        $response = $this->restCall('/jarves/admin/file/paste', 'POST', ['files' => [$testPath], 'target' => $testDirPath . '/', 'move' => false]);
        $this->assertEquals(true, $response['data']);
        $response = $this->restCall('/jarves/admin/file?path=' . $testDirPath);
        //copied
        $this->assertcount(1, $response['data']);
        $file = $response['data'][0];
        $newPath = $testDirPath . '/' . basename($testPath);
        $this->assertEquals($newPath, $file['path']);
        $this->assertEquals(basename($testPath), $file['name']);
        $this->assertEquals($testDirPath, $file['dir']);
        $response = $this->restCall('/jarves/admin/file/single?path=' . $testPath);
        //still there
        $file = $response['data'];
        $this->assertNotNull($file);
        $this->assertGreaterThan(0, $file['id']);
        $this->assertEquals($testPath, $file['path']);
        $this->assertEquals(basename($testPath), $file['name']);
        $this->assertEquals(dirname($testPath), $file['dir']);
        $this->assertEquals(true, $file['writeAccess']);
        $this->assertEquals('file', $file['type']);
        $response = $this->restCall('/jarves/admin/file', 'DELETE', ['path' => $testPath]);
        $this->assertEquals(true, $response['data']);
        $response = $this->restCall('/jarves/admin/file', 'DELETE', ['path' => $newPath]);
        $this->assertEquals(true, $response['data']);
        $response = $this->restCall('/jarves/admin/file', 'DELETE', ['path' => $testDirPath]);
        $this->assertEquals(true, $response['data']);
    }