diff options
Diffstat (limited to 'tests/PHPUnit')
-rw-r--r-- | tests/PHPUnit/Unit/FilesystemTest.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/PHPUnit/Unit/FilesystemTest.php b/tests/PHPUnit/Unit/FilesystemTest.php index b21705e796..4913ee0844 100644 --- a/tests/PHPUnit/Unit/FilesystemTest.php +++ b/tests/PHPUnit/Unit/FilesystemTest.php @@ -14,6 +14,7 @@ use Piwik\Tests\Framework\TestCase\SystemTestCase; /** * @group Core + * @group FileSystem */ class FilesystemTest extends \PHPUnit\Framework\TestCase { @@ -193,6 +194,51 @@ class FilesystemTest extends \PHPUnit\Framework\TestCase $this->assertEquals(array(), $result); } + public function test_unlockTargetFilesNotPresentInSource_doNotAttemptToUnlinkFilesWithTheSameCaseInsensitiveName() + { + $sourceInsensitive = $this->createCaseInsensitiveSourceFiles(); + $targetInsensitive = $this->createCaseInsensitiveTargetFiles(); + + // Target: /CoreHome/vue/src/Menudropdown/Menudropdown.vue' + // Source: /CoreHome/vue/src/MenuDropdown/MenuDropdown.vue' + + $result = Filesystem::directoryDiff($sourceInsensitive, $targetInsensitive); + + if (Filesystem::isFileSystemCaseInsensitive()) { + + // Case insensitive filesystem: + // Since the target and source will be treated as the same file then we do not want directoryDiff() to + // report a difference as copying the source command will overwrite the target file. Reporting a difference + // will cause the target file to be unlinked after the copy which will result in a missing file. + + $this->assertEquals(array(), $result); + + } else { + + // Case sensitive filesystem: + // directoryDiff() should report a difference and we should be able to unlink the target file safely after + // the source file has been copied. + + // make sure there is a difference between those folders + $this->assertNotEmpty($result); + + Filesystem::unlinkTargetFilesNotPresentInSource($sourceInsensitive, $targetInsensitive); + + // make sure there is no longer a difference + $result = Filesystem::directoryDiff($sourceInsensitive, $targetInsensitive); + $this->assertEquals(array(), $result); + + $result = Filesystem::directoryDiff($targetInsensitive, $sourceInsensitive); + $this->assertEquals(array( + '/CoreHome/vue/src/MenuDropdown', + '/CoreHome/vue/src/MenuDropdown/MenuDropdown.vue', + '/CoreHome/vue/src/MenuDropdown/index.htm', + '/CoreHome/vue/src/MenuDropdown/index.php', + ), $result); + + } + } + private function createSourceFiles() { $source = $this->createEmptySource(); @@ -265,6 +311,26 @@ class FilesystemTest extends \PHPUnit\Framework\TestCase return $this->testPath . '/target'; } + private function createCaseInsensitiveTargetFiles() + { + $target = $this->createEmptyTarget(); + Filesystem::mkdir($target . '/CoreHome/vue/src/Menudropdown'); + + file_put_contents($target . '/CoreHome/vue/src/Menudropdown/Menudropdown.vue', ''); + + return $target; + } + + private function createCaseInsensitiveSourceFiles() + { + $source = $this->createEmptySource(); + Filesystem::mkdir($source . '/CoreHome/vue/src/MenuDropdown'); + + file_put_contents($source . '/CoreHome/vue/src/MenuDropdown/MenuDropdown.vue', ''); + + return $source; + } + public function test_getFileSize_ZeroSize() { File::setFileSize(0); |