Blame view

sources/apps/files_encryption/tests/helper.php 1.84 KB
31b7f2792   Kload   Upgrade to ownclo...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  <?php
  /**
   * Copyright (c) 2013 Bjoern Schiessle <schiessle@owncloud.com>
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
  
  
  require_once __DIR__ . '/../lib/helper.php';
  
  use OCA\Encryption;
  
  /**
   * Class Test_Encryption_Helper
   */
  class Test_Encryption_Helper extends \PHPUnit_Framework_TestCase {
  
  	/**
  	 * @medium
  	 */
  	function testStripPartialFileExtension() {
  
  		$partFilename = 'testfile.txt.part';
  		$filename = 'testfile.txt';
  
  		$this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename));
  
  		$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($partFilename));
  
  		$this->assertFalse(Encryption\Helper::isPartialFilePath($filename));
  
  		$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename));
  	}
  
  
  	/**
  	 * @medium
  	 */
  	function testStripPartialFileExtensionWithTransferIdPath() {
  
  		$partFilename = 'testfile.txt.ocTransferId643653835.part';
  		$filename = 'testfile.txt';
  
  		$this->assertTrue(Encryption\Helper::isPartialFilePath($partFilename));
  
  		$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($partFilename));
  
  		$this->assertFalse(Encryption\Helper::isPartialFilePath($filename));
  
  		$this->assertEquals('testfile.txt', Encryption\Helper::stripPartialFileExtension($filename));
  	}
  
  	function testGetPathToRealFile() {
  
  		// the relative path to /user/files/ that's what we want to get from getPathToRealFile()
  		$relativePath = "foo/bar/test.txt";
  
  		// test paths
  		$versionPath = "/user/files_versions/foo/bar/test.txt.v456756835";
  		$cachePath = "/user/cache/transferid636483/foo/bar/test.txt";
  
  		$this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($versionPath));
  		$this->assertEquals($relativePath, Encryption\Helper::getPathToRealFile($cachePath));
  	}
  
  }