Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
1cc6f34d
Unverified
Commit
1cc6f34d
authored
5 years ago
by
Arthur Schiwon
Browse files
Options
Downloads
Patches
Plain Diff
adapt file hooks test to eventdispatcher utilization
Signed-off-by:
Arthur Schiwon
<
blizzz@arthur-schiwon.de
>
parent
3a4e31ef
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/lib/Files/Node/HookConnectorTest.php
+66
-23
66 additions, 23 deletions
tests/lib/Files/Node/HookConnectorTest.php
with
66 additions
and
23 deletions
tests/lib/Files/Node/HookConnectorTest.php
+
66
−
23
View file @
1cc6f34d
...
...
@@ -9,12 +9,15 @@
namespace
Test\Files\Node
;
use
OC\Files\Filesystem
;
use
OC\Files\Node\HookConnector
;
use
OC\Files\Node\Root
;
use
OC\Files\Storage\Temporary
;
use
OC\Files\View
;
use
OCP\Files\Node
;
use
OCP\ILogger
;
use
OCP\IUserManager
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\EventDispatcher\GenericEvent
;
use
Test\TestCase
;
use
Test\Traits\MountProviderTrait
;
use
Test\Traits\UserTrait
;
...
...
@@ -29,6 +32,9 @@ use Test\Traits\UserTrait;
class
HookConnectorTest
extends
TestCase
{
use
UserTrait
;
use
MountProviderTrait
;
/** @var \PHPUnit\Framework\MockObject\MockObject */
/** @var EventDispatcherInterface */
protected
$eventDispatcher
;
/**
* @var View
...
...
@@ -60,6 +66,7 @@ class HookConnectorTest extends TestCase {
$this
->
createMock
(
ILogger
::
class
),
$this
->
createMock
(
IUserManager
::
class
)
);
$this
->
eventDispatcher
=
\OC
::
$server
->
getEventDispatcher
();
}
public
function
tearDown
()
{
...
...
@@ -72,50 +79,50 @@ class HookConnectorTest extends TestCase {
return
[
[
function
()
{
Filesystem
::
file_put_contents
(
'test.txt'
,
'asd'
);
},
'preWrite'
],
},
'preWrite'
,
'\OCP\Files::preWrite'
],
[
function
()
{
Filesystem
::
file_put_contents
(
'test.txt'
,
'asd'
);
},
'postWrite'
],
},
'postWrite'
,
'\OCP\Files::postWrite'
],
[
function
()
{
Filesystem
::
file_put_contents
(
'test.txt'
,
'asd'
);
},
'preCreate'
],
},
'preCreate'
,
'\OCP\Files::preCreate'
],
[
function
()
{
Filesystem
::
file_put_contents
(
'test.txt'
,
'asd'
);
},
'postCreate'
],
},
'postCreate'
,
'\OCP\Files::postCreate'
],
[
function
()
{
Filesystem
::
mkdir
(
'test.txt'
);
},
'preCreate'
],
},
'preCreate'
,
'\OCP\Files::preCreate'
],
[
function
()
{
Filesystem
::
mkdir
(
'test.txt'
);
},
'postCreate'
],
},
'postCreate'
,
'\OCP\Files::postCreate'
],
[
function
()
{
Filesystem
::
touch
(
'test.txt'
);
},
'preTouch'
],
},
'preTouch'
,
'\OCP\Files::preTouch'
],
[
function
()
{
Filesystem
::
touch
(
'test.txt'
);
},
'postTouch'
],
},
'postTouch'
,
'\OCP\Files::postTouch'
],
[
function
()
{
Filesystem
::
touch
(
'test.txt'
);
},
'preCreate'
],
},
'preCreate'
,
'\OCP\Files::preCreate'
],
[
function
()
{
Filesystem
::
touch
(
'test.txt'
);
},
'postCreate'
],
},
'postCreate'
,
'\OCP\Files::postCreate'
],
[
function
()
{
Filesystem
::
file_put_contents
(
'test.txt'
,
'asd'
);
Filesystem
::
unlink
(
'test.txt'
);
},
'preDelete'
],
},
'preDelete'
,
'\OCP\Files::preDelete'
],
[
function
()
{
Filesystem
::
file_put_contents
(
'test.txt'
,
'asd'
);
Filesystem
::
unlink
(
'test.txt'
);
},
'postDelete'
],
},
'postDelete'
,
'\OCP\Files::postDelete'
],
[
function
()
{
Filesystem
::
mkdir
(
'test.txt'
);
Filesystem
::
rmdir
(
'test.txt'
);
},
'preDelete'
],
},
'preDelete'
,
'\OCP\Files::preDelete'
],
[
function
()
{
Filesystem
::
mkdir
(
'test.txt'
);
Filesystem
::
rmdir
(
'test.txt'
);
},
'postDelete'
],
},
'postDelete'
,
'\OCP\Files::postDelete'
],
];
}
...
...
@@ -124,8 +131,8 @@ class HookConnectorTest extends TestCase {
* @param string $expectedHook
* @dataProvider viewToNodeProvider
*/
public
function
testViewToNode
(
callable
$operation
,
$expectedHook
)
{
$connector
=
new
\OC\Files\Node\
HookConnector
(
$this
->
root
,
$this
->
view
);
public
function
testViewToNode
(
callable
$operation
,
$expectedHook
,
$expectedEvent
)
{
$connector
=
new
HookConnector
(
$this
->
root
,
$this
->
view
,
$this
->
eventDispatcher
);
$connector
->
viewToNode
();
$hookCalled
=
false
;
/** @var Node $hookNode */
...
...
@@ -136,10 +143,21 @@ class HookConnectorTest extends TestCase {
$hookNode
=
$node
;
});
$dispatcherCalled
=
false
;
/** @var Node $dispatcherNode */
$dispatcherNode
=
null
;
$this
->
eventDispatcher
->
addListener
(
$expectedEvent
,
function
(
GenericEvent
$event
)
use
(
&
$dispatcherCalled
,
&
$dispatcherNode
)
{
$dispatcherCalled
=
true
;
$dispatcherNode
=
$event
->
getSubject
();
});
$operation
();
$this
->
assertTrue
(
$hookCalled
);
$this
->
assertEquals
(
'/'
.
$this
->
userId
.
'/files/test.txt'
,
$hookNode
->
getPath
());
$this
->
assertTrue
(
$dispatcherCalled
);
$this
->
assertEquals
(
'/'
.
$this
->
userId
.
'/files/test.txt'
,
$dispatcherNode
->
getPath
());
}
public
function
viewToNodeProviderCopyRename
()
{
...
...
@@ -147,19 +165,19 @@ class HookConnectorTest extends TestCase {
[
function
()
{
Filesystem
::
file_put_contents
(
'source'
,
'asd'
);
Filesystem
::
rename
(
'source'
,
'target'
);
},
'preRename'
],
},
'preRename'
,
'\OCP\Files::preRename'
],
[
function
()
{
Filesystem
::
file_put_contents
(
'source'
,
'asd'
);
Filesystem
::
rename
(
'source'
,
'target'
);
},
'postRename'
],
},
'postRename'
,
'\OCP\Files::postRename'
],
[
function
()
{
Filesystem
::
file_put_contents
(
'source'
,
'asd'
);
Filesystem
::
copy
(
'source'
,
'target'
);
},
'preCopy'
],
},
'preCopy'
,
'\OCP\Files::preCopy'
],
[
function
()
{
Filesystem
::
file_put_contents
(
'source'
,
'asd'
);
Filesystem
::
copy
(
'source'
,
'target'
);
},
'postCopy'
],
},
'postCopy'
,
'\OCP\Files::postCopy'
],
];
}
...
...
@@ -168,8 +186,8 @@ class HookConnectorTest extends TestCase {
* @param string $expectedHook
* @dataProvider viewToNodeProviderCopyRename
*/
public
function
testViewToNodeCopyRename
(
callable
$operation
,
$expectedHook
)
{
$connector
=
new
\OC\Files\Node\
HookConnector
(
$this
->
root
,
$this
->
view
);
public
function
testViewToNodeCopyRename
(
callable
$operation
,
$expectedHook
,
$expectedEvent
)
{
$connector
=
new
HookConnector
(
$this
->
root
,
$this
->
view
,
$this
->
eventDispatcher
);
$connector
->
viewToNode
();
$hookCalled
=
false
;
/** @var Node $hookSourceNode */
...
...
@@ -183,15 +201,29 @@ class HookConnectorTest extends TestCase {
$hookTargetNode
=
$targetNode
;
});
$dispatcherCalled
=
false
;
/** @var Node $dispatcherSourceNode */
$dispatcherSourceNode
=
null
;
/** @var Node $dispatcherTargetNode */
$dispatcherTargetNode
=
null
;
$this
->
eventDispatcher
->
addListener
(
$expectedEvent
,
function
(
GenericEvent
$event
)
use
(
&
$dispatcherSourceNode
,
&
$dispatcherTargetNode
,
&
$dispatcherCalled
)
{
$dispatcherCalled
=
true
;
list
(
$dispatcherSourceNode
,
$dispatcherTargetNode
)
=
$event
->
getSubject
();
});
$operation
();
$this
->
assertTrue
(
$hookCalled
);
$this
->
assertEquals
(
'/'
.
$this
->
userId
.
'/files/source'
,
$hookSourceNode
->
getPath
());
$this
->
assertEquals
(
'/'
.
$this
->
userId
.
'/files/target'
,
$hookTargetNode
->
getPath
());
$this
->
assertTrue
(
$dispatcherCalled
);
$this
->
assertEquals
(
'/'
.
$this
->
userId
.
'/files/source'
,
$dispatcherSourceNode
->
getPath
());
$this
->
assertEquals
(
'/'
.
$this
->
userId
.
'/files/target'
,
$dispatcherTargetNode
->
getPath
());
}
public
function
testPostDeleteMeta
()
{
$connector
=
new
\OC\Files\Node\
HookConnector
(
$this
->
root
,
$this
->
view
);
$connector
=
new
HookConnector
(
$this
->
root
,
$this
->
view
,
$this
->
eventDispatcher
);
$connector
->
viewToNode
();
$hookCalled
=
false
;
/** @var Node $hookNode */
...
...
@@ -202,11 +234,22 @@ class HookConnectorTest extends TestCase {
$hookNode
=
$node
;
});
$dispatcherCalled
=
false
;
/** @var Node $dispatcherNode */
$dispatcherNode
=
null
;
$this
->
eventDispatcher
->
addListener
(
'\OCP\Files::postDelete'
,
function
(
GenericEvent
$event
)
use
(
&
$dispatcherCalled
,
&
$dispatcherNode
)
{
$dispatcherCalled
=
true
;
$dispatcherNode
=
$event
->
getSubject
();
});
Filesystem
::
file_put_contents
(
'test.txt'
,
'asd'
);
$info
=
Filesystem
::
getFileInfo
(
'test.txt'
);
Filesystem
::
unlink
(
'test.txt'
);
$this
->
assertTrue
(
$hookCalled
);
$this
->
assertEquals
(
$hookNode
->
getId
(),
$info
->
getId
());
$this
->
assertTrue
(
$dispatcherCalled
);
$this
->
assertEquals
(
$dispatcherNode
->
getId
(),
$info
->
getId
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment