1
1
<?php
2
+
2
3
namespace Flowpack \Media \Ui \Tests \Functional ;
3
4
4
5
/*
12
13
*/
13
14
14
15
use Flowpack \Media \Ui \GraphQL \Types ;
16
+ use Neos \Behat \FlowEntitiesTrait ;
15
17
use Neos \Flow \Persistence \PersistenceManagerInterface ;
16
18
use Neos \Flow \ResourceManagement \PersistentResource ;
17
19
use Neos \Flow \ResourceManagement \ResourceManager ;
27
29
abstract class AbstractMediaTestCase extends FunctionalTestCase
28
30
{
29
31
use SecurityOperationsTrait;
32
+ use FlowEntitiesTrait;
30
33
31
34
/**
32
35
* @var string
@@ -38,43 +41,98 @@ abstract class AbstractMediaTestCase extends FunctionalTestCase
38
41
*/
39
42
protected $ resourceManager ;
40
43
44
+ protected function setUp (): void
45
+ {
46
+ $ this ->objectManager = self ::$ bootstrap ->getObjectManager ();
47
+
48
+ $ this ->truncateAndSetupFlowEntities ();
49
+
50
+ $ this ->cleanupPersistentResourcesDirectory ();
51
+ self ::$ bootstrap ->getObjectManager ()->forgetInstance (ResourceManager::class);
52
+ $ session = $ this ->objectManager ->get (\Neos \Flow \Session \SessionInterface::class);
53
+ if ($ session ->isStarted ()) {
54
+ $ session ->destroy (
55
+ sprintf (
56
+ 'assure that session is fresh, in setUp() method of functional test %s. ' ,
57
+ get_class ($ this ) . ':: ' . $ this ->getName ()
58
+ )
59
+ );
60
+ }
61
+
62
+ $ privilegeManager = $ this ->objectManager ->get (\Neos \Flow \Security \Authorization \TestingPrivilegeManager::class);
63
+ $ privilegeManager ->reset ();
64
+
65
+ if ($ this ->testableSecurityEnabled === true || static ::$ testablePersistenceEnabled === true ) {
66
+ $ this ->persistenceManager = $ this ->objectManager ->get (
67
+ PersistenceManagerInterface::class
68
+ );
69
+ } else {
70
+ $ privilegeManager ->setOverrideDecision (true );
71
+ }
72
+
73
+ // HTTP must be initialized before Session and Security because they rely
74
+ // on an HTTP request being available via the request handler:
75
+ $ this ->setupHttp ();
76
+
77
+ $ session = $ this ->objectManager ->get (\Neos \Flow \Session \SessionInterface::class);
78
+ if ($ session ->isStarted ()) {
79
+ $ session ->destroy (
80
+ sprintf (
81
+ 'assure that session is fresh, in setUp() method of functional test %s. ' ,
82
+ get_class ($ this ) . ':: ' . $ this ->getName ()
83
+ )
84
+ );
85
+ }
86
+
87
+ $ this ->setupSecurity ();
88
+ }
89
+
90
+ protected function persist (): void
91
+ {
92
+ $ this ->persistenceManager ->persistAll ();
93
+ $ this ->persistenceManager ->clearState ();
94
+ }
95
+
41
96
public function tearDown (): void
42
97
{
43
- $ persistenceManager = self :: $ bootstrap -> getObjectManager ()-> get (PersistenceManagerInterface::class);
44
- if ( is_callable ([ $ persistenceManager, ' tearDown ' ])) {
45
- $ persistenceManager -> tearDown ();
98
+ try {
99
+ $ this -> persistenceManager -> persistAll ();
100
+ } catch ( \ Exception $ exception ) {
46
101
}
47
- self ::$ bootstrap ->getObjectManager ()->forgetInstance (PersistenceManagerInterface::class);
48
- parent ::tearDown ();
102
+
103
+ //if (is_callable([$this->persistenceManager, 'tearDown'])) {
104
+ // $this->persistenceManager->tearDown();
105
+ //}
106
+ //$persistenceManager = self::$bootstrap->getObjectManager()->get(PersistenceManagerInterface::class);
107
+ //if (is_callable([$persistenceManager, 'tearDown'])) {
108
+ // $persistenceManager->tearDown();
109
+ //}
110
+ //self::$bootstrap->getObjectManager()->forgetInstance(PersistenceManagerInterface::class);
111
+ //parent::tearDown();
49
112
}
50
113
51
114
/**
52
115
* Creates an Image object from a file using a mock resource (in order to avoid a database resource pointer entry)
53
- * @param string $imagePathAndFilename
54
- * @return PersistentResource
55
116
*/
56
- protected function getMockResourceByImagePath ($ imagePathAndFilename )
117
+ protected function getMockResourceByImagePath (string $ imagePathAndFilename ): PersistentResource
57
118
{
58
119
$ imagePathAndFilename = Files::getUnixStylePath ($ imagePathAndFilename );
59
120
$ hash = sha1_file ($ imagePathAndFilename );
60
121
copy ($ imagePathAndFilename , 'resource:// ' . $ hash );
61
- return $ mockResource = $ this ->createMockResourceAndPointerFromHash ($ hash );
122
+ return $ this ->createMockResourceAndPointerFromHash ($ hash );
62
123
}
63
124
64
125
/**
65
126
* Creates a mock ResourcePointer and PersistentResource from a given hash.
66
127
* Make sure that a file representation already exists, e.g. with
67
128
* file_put_content('resource://' . $hash) before
68
- *
69
- * @param string $hash
70
- * @return PersistentResource
71
129
*/
72
- protected function createMockResourceAndPointerFromHash ($ hash )
130
+ protected function createMockResourceAndPointerFromHash (string $ hash ): PersistentResource
73
131
{
74
132
$ mockResource = $ this ->getMockBuilder (PersistentResource::class)->setMethods (['getHash ' , 'getUri ' ])->getMock ();
75
133
$ mockResource ->expects (self ::any ())
76
- ->method ('getHash ' )
77
- ->will (self ::returnValue ($ hash ));
134
+ ->method ('getHash ' )
135
+ ->will (self ::returnValue ($ hash ));
78
136
$ mockResource ->expects (self ::any ())
79
137
->method ('getUri ' )
80
138
->will (self ::returnValue ('resource:// ' . $ hash ));
@@ -83,11 +141,12 @@ protected function createMockResourceAndPointerFromHash($hash)
83
141
84
142
/**
85
143
* Builds a temporary directory to work on.
86
- * @return void
87
144
*/
88
- protected function prepareTemporaryDirectory ()
145
+ protected function prepareTemporaryDirectory (): void
89
146
{
90
- $ this ->temporaryDirectory = Files::concatenatePaths ([FLOW_PATH_DATA , 'Temporary ' , 'Testing ' , str_replace ('\\' , '_ ' , __CLASS__ )]);
147
+ $ this ->temporaryDirectory = Files::concatenatePaths (
148
+ [FLOW_PATH_DATA , 'Temporary ' , 'Testing ' , str_replace ('\\' , '_ ' , __CLASS__ )]
149
+ );
91
150
if (!file_exists ($ this ->temporaryDirectory )) {
92
151
Files::createDirectoryRecursively ($ this ->temporaryDirectory );
93
152
}
0 commit comments