Apply code style fixes from owncloud, revert regex
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
parent
a5bc27c2a6
commit
7404c10666
|
@ -52,24 +52,27 @@ class ExcludeFileByNameFilterIterator extends \RecursiveFilterIterator {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $excludedFileNamePatterns = [
|
private $excludedFilenamePatterns = [
|
||||||
'/\.webapp-nextcloud-(\d+\.){3}(-r\d+)?/', // Gentoo/Funtoo & derivatives use a tool known as webapp-config to manage wep-apps.
|
'/^\.webapp-nextcloud-.*/', // Gentoo/Funtoo & derivatives use a tool known as webapp-config to manage wep-apps.
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function accept() {
|
public function accept() {
|
||||||
if($this->isDir()) {
|
/** @var \SplFileInfo $current */
|
||||||
|
$current = $this->current();
|
||||||
|
|
||||||
|
if ($current->isDir()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentFileName = $this->current()->getFilename();
|
$currentFileName = $current->getFilename();
|
||||||
if (in_array($currentFileName, $this->excludedFilenames, true)){
|
if (in_array($currentFileName, $this->excludedFilenames, true)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->excludedFileNamePatterns as $pattern){
|
foreach ($this->excludedFilenamePatterns as $pattern){
|
||||||
if (preg_match($pattern, $currentFileName) > 0){
|
if (preg_match($pattern, $currentFileName) > 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,25 +25,25 @@ use \OC\IntegrityCheck\Iterator\ExcludeFileByNameFilterIterator;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class ExcludeFileByNameFilterIteratorTest extends TestCase {
|
class ExcludeFileByNameFilterIteratorTest extends TestCase {
|
||||||
/** @var ExcludeFileByNameFilterIterator */
|
/** @var ExcludeFileByNameFilterIterator|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
protected $filter;
|
protected $filter;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->filter = $this->getMockBuilder(ExcludeFileByNameFilterIterator::class)
|
$this->filter = $this->getMockBuilder(ExcludeFileByNameFilterIterator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock()
|
->setMethods(['current'])
|
||||||
;
|
->getMock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fileNameProvider(){
|
public function fileNameProvider(): array {
|
||||||
return [
|
return [
|
||||||
['a file', true],
|
['a file', true],
|
||||||
['Thumbs.db', false],
|
['Thumbs.db', false],
|
||||||
['another file', true],
|
['another file', true],
|
||||||
['.directory', false],
|
['.directory', false],
|
||||||
['.webapp-netxcloud-12.0.5', false],
|
['.webapp-nextcloud-12.0.5', false],
|
||||||
['wx.webapp-nextcloud-obee', true],
|
['wx.webapp-nextcloud-obee', true],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -53,17 +53,18 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase {
|
||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @param bool $expectedResult
|
* @param bool $expectedResult
|
||||||
*/
|
*/
|
||||||
public function testAcceptForFiles($fileName, $expectedResult){
|
public function testAcceptForFiles($fileName, $expectedResult): void {
|
||||||
$iteratorMock = $this->createMock(\DirectoryIterator::class);
|
$iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class)
|
||||||
$iteratorMock->method('getFilename')
|
->disableOriginalConstructor()
|
||||||
->will($this->returnValue($fileName))
|
->setMethods(['getFilename', 'isDir'])
|
||||||
;
|
->getMock();
|
||||||
|
|
||||||
$this->filter->method('isDir')
|
$iteratorMock->method('getFilename')
|
||||||
->will($this->returnValue(false));
|
->willReturn($fileName);
|
||||||
|
$iteratorMock->method('isDir')
|
||||||
|
->willReturn(false);
|
||||||
$this->filter->method('current')
|
$this->filter->method('current')
|
||||||
->will($this->returnValue($iteratorMock))
|
->willReturn($iteratorMock);
|
||||||
;
|
|
||||||
|
|
||||||
$actualResult = $this->filter->accept();
|
$actualResult = $this->filter->accept();
|
||||||
$this->assertEquals($expectedResult, $actualResult);
|
$this->assertEquals($expectedResult, $actualResult);
|
||||||
|
@ -72,21 +73,22 @@ class ExcludeFileByNameFilterIteratorTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* @dataProvider fileNameProvider
|
* @dataProvider fileNameProvider
|
||||||
* @param string $fileName
|
* @param string $fileName
|
||||||
* @param bool $fakeExpectedResult
|
* @param bool $expectedResult
|
||||||
*/
|
*/
|
||||||
public function testAcceptForDirs($fileName, $fakeExpectedResult){
|
public function testAcceptForDirs($fileName, $expectedResult): void {
|
||||||
$iteratorMock = $this->createMock(\DirectoryIterator::class);
|
$iteratorMock = $this->getMockBuilder(\RecursiveDirectoryIterator::class)
|
||||||
$iteratorMock->method('getFilename')
|
->disableOriginalConstructor()
|
||||||
->will($this->returnValue($fileName))
|
->setMethods(['getFilename', 'isDir'])
|
||||||
;
|
->getMock();
|
||||||
|
|
||||||
$this->filter->method('isDir')
|
$iteratorMock->method('getFilename')
|
||||||
->will($this->returnValue(true));
|
->willReturn($fileName);
|
||||||
|
$iteratorMock->method('isDir')
|
||||||
|
->willReturn(true);
|
||||||
$this->filter->method('current')
|
$this->filter->method('current')
|
||||||
->will($this->returnValue($iteratorMock))
|
->willReturn($iteratorMock);
|
||||||
;
|
|
||||||
|
|
||||||
$actualResult = $this->filter->accept();
|
$actualResult = $this->filter->accept();
|
||||||
$this->assertFalse($actualResult);
|
$this->assertTrue($actualResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue