diff options
author | Justin Velluppillai <justin@innocraft.com> | 2022-03-09 00:03:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 00:03:18 +0300 |
commit | 7255b44b89f9c73b4d39a492902f4c56739fbc99 (patch) | |
tree | 0a790d97af2ddb8898e8b00ea75bb96df590a4f7 /tests | |
parent | 680db1156be27769709bf9a6e7f67636e7cfb8dc (diff) |
Merge RC patches back to main branch (#18901)
* Update version to 4.8.0-rc1
* Fix possible warning in Url::isValidHost (#18887)
* Handle case only file name updates on case insensitive file systems (#18865)
* Added unit test for case-sensitive unlink
* Use case-insensitive comparison in directoryDiff() if a case-insensitive filesystem is detected
* Fix misleading method name
* Update tests/PHPUnit/Unit/FilesystemTest.php
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
* Update tests/PHPUnit/Unit/FilesystemTest.php
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
Co-authored-by: Justin Velluppillai <justin@innocraft.com>
* Update version to 4.8.0 (#18893)
Co-authored-by: Stefan Giehl <stefan@matomo.org>
Co-authored-by: Ben Burgess <88810029+bx80@users.noreply.github.com>
Diffstat (limited to 'tests')
-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); |