diff options
author | Morris Jobke <hey@morrisjobke.de> | 2019-02-26 00:17:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-26 00:17:25 +0100 |
commit | dc2798460b30fdf47e6141bcd775787f5a3a052b (patch) | |
tree | 2a491f032210a17f50d8cab43a536913e5eddd16 /tests | |
parent | 58fd78951c944d69770f2979387d865f1e7f91a5 (diff) | |
parent | b14700c9360b2589d35b20b00bc5b863d7fb8243 (diff) | |
download | nextcloud-server-dc2798460b30fdf47e6141bcd775787f5a3a052b.tar.gz nextcloud-server-dc2798460b30fdf47e6141bcd775787f5a3a052b.zip |
Merge pull request #14198 from nextcloud/bugfix/8647-exclude-file-name-patterns
Exclude file name patterns; ignore gentoo webapp files
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php b/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php new file mode 100644 index 00000000000..124618eb538 --- /dev/null +++ b/tests/lib/IntegrityCheck/Iterator/ExcludeFileByNameFilterIteratorTest.php @@ -0,0 +1,94 @@ +<?php +/** + * @author Victor Dubiniuk <dubiniuk@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Test\IntegrityCheck\Iterator; + +use \OC\IntegrityCheck\Iterator\ExcludeFileByNameFilterIterator; +use Test\TestCase; + +class ExcludeFileByNameFilterIteratorTest extends TestCase { + /** @var ExcludeFileByNameFilterIterator|\PHPUnit\Framework\MockObject\MockObject */ + protected $filter; + + public function setUp() { + parent::setUp(); + $this->filter = $this->getMockBuilder(ExcludeFileByNameFilterIterator::class) + ->disableOriginalConstructor() + ->setMethods(['current']) + ->getMock(); + } + + public function fileNameProvider(): array { + return [ + ['a file', true], + ['Thumbs.db', false], + ['another file', true], + ['.directory', false], + ['.webapp-nextcloud-15.0.2', false], + ['.webapp-nextcloud-14.0.5-r3', false], + ['wx.webapp-nextcloud-obee', true], + ]; + } + + /** + * @dataProvider fileNameProvider + * @param string $fileName + * @param bool $expectedResult + */ + public function testAcceptForFiles($fileName, $expectedResult): void { + $iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class) + ->disableOriginalConstructor() + ->setMethods(['getFilename', 'isDir']) + ->getMock(); + + $iteratorMock->method('getFilename') + ->willReturn($fileName); + $iteratorMock->method('isDir') + ->willReturn(false); + $this->filter->method('current') + ->willReturn($iteratorMock); + + $actualResult = $this->filter->accept(); + $this->assertEquals($expectedResult, $actualResult); + } + + /** + * @dataProvider fileNameProvider + * @param string $fileName + * @param bool $expectedResult + */ + public function testAcceptForDirs($fileName, $expectedResult): void { + $iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class) + ->disableOriginalConstructor() + ->setMethods(['getFilename', 'isDir']) + ->getMock(); + + $iteratorMock->method('getFilename') + ->willReturn($fileName); + $iteratorMock->method('isDir') + ->willReturn(true); + $this->filter->method('current') + ->willReturn($iteratorMock); + + $actualResult = $this->filter->accept(); + $this->assertTrue($actualResult); + } +} |