Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
d11f01fa
Commit
d11f01fa
authored
Mar 24, 2015
by
Robin Appelman
Browse files
Add `getNonExistingName()` to the node api
parent
e07a2fd8
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/private/files/node/folder.php
View file @
d11f01fa
...
...
@@ -389,4 +389,16 @@ class Folder extends Node implements \OCP\Files\Folder {
throw
new
NotPermittedException
();
}
}
/**
* Add a suffix to the name in case the file exists
*
* @param string $name
* @return string
* @throws NotPermittedException
*/
public
function
getNonExistingName
(
$name
)
{
$uniqueName
=
\
OC_Helper
::
buildNotExistingFileNameForView
(
$this
->
getPath
(),
$name
,
$this
->
view
);
return
trim
(
$this
->
getRelativePath
(
$uniqueName
),
'/'
);
}
}
lib/public/files/folder.php
View file @
d11f01fa
...
...
@@ -146,4 +146,13 @@ interface Folder extends Node {
* @return bool
*/
public
function
isCreatable
();
/**
* Add a suffix to the name in case the file exists
*
* @param string $name
* @return string
* @throws NotPermittedException
*/
public
function
getNonExistingName
(
$name
);
}
tests/lib/files/node/folder.php
View file @
d11f01fa
...
...
@@ -679,4 +679,40 @@ class Folder extends \Test\TestCase {
$this
->
assertEquals
(
'/bar/foo/qwerty'
,
$result
[
0
]
->
getPath
());
$this
->
assertEquals
(
'/bar/foo/asd/foo/qwerty'
,
$result
[
1
]
->
getPath
());
}
public
function
uniqueNameProvider
()
{
return
[
// input, existing, expected
[
'foo'
,
[]
,
'foo'
],
[
'foo'
,
[
'foo'
]
,
'foo (2)'
],
[
'foo'
,
[
'foo'
,
'foo (2)'
]
,
'foo (3)'
]
];
}
/**
* @dataProvider uniqueNameProvider
*/
public
function
testGetUniqueName
(
$name
,
$existingFiles
,
$expected
)
{
$manager
=
$this
->
getMock
(
'\OC\Files\Mount\Manager'
);
$folderPath
=
'/bar/foo'
;
/**
* @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
*/
$view
=
$this
->
getMock
(
'\OC\Files\View'
);
$root
=
$this
->
getMock
(
'\OC\Files\Node\Root'
,
array
(
'getUser'
,
'getMountsIn'
,
'getMount'
),
array
(
$manager
,
$view
,
$this
->
user
));
$view
->
expects
(
$this
->
any
())
->
method
(
'file_exists'
)
->
will
(
$this
->
returnCallback
(
function
(
$path
)
use
(
$existingFiles
,
$folderPath
)
{
foreach
(
$existingFiles
as
$existing
)
{
if
(
$folderPath
.
'/'
.
$existing
===
$path
){
return
true
;
}
}
return
false
;
}));
$node
=
new
\
OC\Files\Node\Folder
(
$root
,
$view
,
$folderPath
);
$this
->
assertEquals
(
$expected
,
$node
->
getNonExistingName
(
$name
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment