3
3
4
4
use PHPUnit \Framework \TestCase ;
5
5
6
+ use Qiniu \Auth ;
6
7
use Qiniu \Processing \PersistentFop ;
7
8
use Qiniu \Storage \UploadManager ;
8
- use Qiniu \Region ;
9
- use Qiniu \Config ;
9
+ // use Qiniu\Region;
10
+ // use Qiniu\Config;
10
11
11
12
class PfopTest extends TestCase
12
13
{
14
+ /**
15
+ * @var Auth
16
+ */
17
+ private static $ testAuth ;
18
+
19
+ private static $ bucketName ;
20
+ /**
21
+ * @beforeClass
22
+ */
23
+ public static function setupBeforeClass ()
24
+ {
25
+ global $ bucketName ;
26
+ global $ testAuth ;
27
+
28
+ self ::$ bucketName = $ bucketName ;
29
+ self ::$ testAuth = $ testAuth ;
30
+ }
31
+
13
32
private static function getConfig ()
14
33
{
15
34
// use this func to test in test env
@@ -52,7 +71,7 @@ public function testPfopExecuteAndStatusWithMultipleFops()
52
71
$ this ->assertNull ($ error );
53
72
}
54
73
55
- private function pfopTypeTestData ()
74
+ private function pfopOptionsTestData ()
56
75
{
57
76
return array (
58
77
array (
@@ -69,31 +88,47 @@ private function pfopTypeTestData()
69
88
),
70
89
array (
71
90
'type ' => 2
91
+ ),
92
+ array (
93
+ 'workflowTemplateID ' => 'test-workflow '
72
94
)
73
95
);
74
96
}
75
97
76
- public function testPfopWithIdleTimeType ()
98
+ public function testPfopExecuteWithOptions ()
77
99
{
78
- global $ testAuth ;
79
-
80
- $ bucket = 'testres ' ;
81
- $ key = 'sintel_trailer.mp4 ' ;
82
- $ persistentEntry = \Qiniu \entry ($ bucket , 'test-pfop-type_1 ' );
83
- $ fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/ ' . $ persistentEntry ;
84
- $ pfop = new PersistentFop ($ testAuth , self ::getConfig ());
100
+ $ bucket = self ::$ bucketName ;
101
+ $ key = 'qiniu.png ' ;
102
+ $ pfop = new PersistentFop (self ::$ testAuth , self ::getConfig ());
85
103
86
- $ testCases = $ this ->pfopTypeTestData ();
104
+ $ testCases = $ this ->pfopOptionsTestData ();
87
105
88
106
foreach ($ testCases as $ testCase ) {
107
+ if ($ testCase ['workflowTemplateID ' ]) {
108
+ $ fops = null ;
109
+ } else {
110
+ $ persistentEntry = \Qiniu \entry (
111
+ $ bucket ,
112
+ implode (
113
+ '_ ' ,
114
+ array (
115
+ 'test-pfop/test-pfop-by-api ' ,
116
+ 'type ' ,
117
+ $ testCase ['type ' ]
118
+ )
119
+ )
120
+ );
121
+ $ fops = 'avinfo|saveas/ ' . $ persistentEntry ;
122
+ }
89
123
list ($ id , $ error ) = $ pfop ->execute (
90
124
$ bucket ,
91
125
$ key ,
92
126
$ fops ,
93
127
null ,
94
128
null ,
95
129
false ,
96
- $ testCase ['type ' ]
130
+ $ testCase ['type ' ],
131
+ $ testCase ['workflowTemplateID ' ]
97
132
);
98
133
99
134
if (in_array ($ testCase ['type ' ], array (null , 0 , 1 ))) {
@@ -104,29 +139,50 @@ public function testPfopWithIdleTimeType()
104
139
if ($ testCase ['type ' ] == 1 ) {
105
140
$ this ->assertEquals (1 , $ status ['type ' ]);
106
141
}
142
+ if ($ testCase ['workflowTemplateID ' ]) {
143
+ // assertStringContainsString when PHPUnit >= 8.0
144
+ $ this ->assertTrue (
145
+ strpos (
146
+ $ status ['taskFrom ' ],
147
+ $ testCase ['workflowTemplateID ' ]
148
+ ) !== false
149
+ );
150
+ }
107
151
$ this ->assertNotEmpty ($ status ['creationDate ' ]);
108
152
} else {
109
153
$ this ->assertNotNull ($ error );
110
154
}
111
155
}
112
156
}
113
157
114
-
115
- public function testPfopByUploadPolicy ()
158
+ public function testPfopWithUploadPolicy ()
116
159
{
117
- global $ testAuth ;
118
- $ bucket = 'testres ' ;
119
- $ key = 'sintel_trailer.mp4 ' ;
120
- $ persistentEntry = \Qiniu \entry ($ bucket , 'test-pfop-type_1 ' );
121
- $ fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/ ' . $ persistentEntry ;
160
+ $ bucket = self ::$ bucketName ;
161
+ $ testAuth = self ::$ testAuth ;
162
+ $ key = 'test-pfop/upload-file ' ;
122
163
123
- $ testCases = $ this ->pfopTypeTestData ();
164
+ $ testCases = $ this ->pfopOptionsTestData ();
124
165
125
166
foreach ($ testCases as $ testCase ) {
126
167
$ putPolicy = array (
127
- 'persistentOps ' => $ fops ,
128
168
'persistentType ' => $ testCase ['type ' ]
129
169
);
170
+ if ($ testCase ['workflowTemplateID ' ]) {
171
+ $ putPolicy ['persistentWorkflowTemplateID ' ] = $ testCase ['workflowTemplateID ' ];
172
+ } else {
173
+ $ persistentEntry = \Qiniu \entry (
174
+ $ bucket ,
175
+ implode (
176
+ '_ ' ,
177
+ array (
178
+ 'test-pfop/test-pfop-by-upload ' ,
179
+ 'type ' ,
180
+ $ testCase ['type ' ]
181
+ )
182
+ )
183
+ );
184
+ $ putPolicy ['persistentOps ' ] = 'avinfo|saveas/ ' . $ persistentEntry ;
185
+ }
130
186
131
187
if ($ testCase ['type ' ] == null ) {
132
188
unset($ putPolicy ['persistentType ' ]);
@@ -165,16 +221,24 @@ public function testPfopByUploadPolicy()
165
221
if ($ testCase ['type ' ] == 1 ) {
166
222
$ this ->assertEquals (1 , $ status ['type ' ]);
167
223
}
224
+ if ($ testCase ['workflowTemplateID ' ]) {
225
+ // assertStringContainsString when PHPUnit >= 8.0
226
+ $ this ->assertTrue (
227
+ strpos (
228
+ $ status ['taskFrom ' ],
229
+ $ testCase ['workflowTemplateID ' ]
230
+ ) !== false
231
+ );
232
+ }
168
233
$ this ->assertNotEmpty ($ status ['creationDate ' ]);
169
234
}
170
235
}
171
236
172
237
public function testMkzip ()
173
238
{
174
- global $ testAuth ;
175
- $ bucket = 'phpsdk ' ;
239
+ $ bucket = self ::$ bucketName ;
176
240
$ key = 'php-logo.png ' ;
177
- $ pfop = new PersistentFop ($ testAuth , null );
241
+ $ pfop = new PersistentFop (self :: $ testAuth , null );
178
242
179
243
$ url1 = 'http://phpsdk.qiniudn.com/php-logo.png ' ;
180
244
$ url2 = 'http://phpsdk.qiniudn.com/php-sdk.html ' ;
0 commit comments