/
Core_Foundation_FileSystem_FileSystemTest.php
134 lines (115 loc) · 4.18 KB
/
Core_Foundation_FileSystem_FileSystemTest.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace LegacyTests\Unit\Core\Foundation\FileSystem;
use LegacyTests\TestCase\UnitTestCase;
use PrestaShop\PrestaShop\Core\Foundation\Filesystem\FileSystem;
class Core_Foundation_FileSystem_FileSystemTest extends UnitTestCase
{
private $fs;
private $fixturesPath;
public function setUp()
{
$this->fs = new FileSystem();
$this->fixturesPath = __DIR__ . DIRECTORY_SEPARATOR . 'fixtures';
}
public function test_joinPaths_two_paths()
{
$this->assertEquals(
'a' . DIRECTORY_SEPARATOR . 'b',
$this->fs->joinPaths('a', 'b')
);
}
public function test_joinPaths_three_paths()
{
$this->assertEquals(
'a' . DIRECTORY_SEPARATOR . 'b' . DIRECTORY_SEPARATOR . 'c',
$this->fs->joinPaths('a', 'b', 'c')
);
}
/**
*/
public function test_joinPaths_one_path_throws()
{
$this->expectException(\PrestaShop\PrestaShop\Core\Foundation\Filesystem\Exception::class);
$this->fs->joinPaths('a');
}
/**
*/
public function test_joinPaths_zero_path_throws()
{
$this->expectException(\PrestaShop\PrestaShop\Core\Foundation\Filesystem\Exception::class);
$this->fs->joinPaths();
}
public function test_joinPaths_normalizes_directory_separators()
{
$this->assertEquals(
'a' . DIRECTORY_SEPARATOR . 'b' . DIRECTORY_SEPARATOR . 'c' . DIRECTORY_SEPARATOR . 'd',
$this->fs->joinPaths('a\\', 'b///', 'c\\', 'd/')
);
}
public function test_listEntriesRecursively()
{
$expectedPaths = array(
$this->fs->joinPaths($this->fixturesPath, 'a'),
$this->fs->joinPaths($this->fixturesPath, 'a', 'a.tmp'),
$this->fs->joinPaths($this->fixturesPath, 'a', 'b'),
$this->fs->joinPaths($this->fixturesPath, 'a', 'b', 'b.file'),
$this->fs->joinPaths($this->fixturesPath, 'toplevel.txt')
);
$this->assertEquals(
$expectedPaths,
array_keys($this->fs->listEntriesRecursively($this->fixturesPath))
);
}
public function test_listFilesRecursively()
{
$expectedPaths = array(
$this->fs->joinPaths($this->fixturesPath, 'a', 'a.tmp'),
$this->fs->joinPaths($this->fixturesPath, 'a', 'b', 'b.file'),
$this->fs->joinPaths($this->fixturesPath, 'toplevel.txt')
);
$this->assertEquals(
$expectedPaths,
array_keys($this->fs->listFilesRecursively($this->fixturesPath))
);
}
/**
* Rationale: ls /some/non/existing/file => ls: cannot access /some/non/existing/file: No such file or directory
*/
public function test_listEntriesRecursively_throws_if_path_does_not_exist()
{
$this->expectException(\PrestaShop\PrestaShop\Core\Foundation\Filesystem\Exception::class);
$this->fs->listEntriesRecursively('/some/w/h/e/r/e/over/the/rainbow');
}
/**
*
*/
public function test_listEntriesRecursively_throws_when_path_is_a_file()
{
$this->expectException(\PrestaShop\PrestaShop\Core\Foundation\Filesystem\Exception::class);
$this->fs->listEntriesRecursively(__FILE__);
}
}