33
44use PHPUnit \Framework \TestCase ;
55
6+ use Qiniu \Auth ;
67use Qiniu \Processing \PersistentFop ;
78use Qiniu \Storage \UploadManager ;
8- use Qiniu \Region ;
9- use Qiniu \Config ;
9+ // use Qiniu\Region;
10+ // use Qiniu\Config;
1011
1112class PfopTest extends TestCase
1213{
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+
1332 private static function getConfig ()
1433 {
1534 // use this func to test in test env
@@ -52,7 +71,7 @@ public function testPfopExecuteAndStatusWithMultipleFops()
5271 $ this ->assertNull ($ error );
5372 }
5473
55- private function pfopTypeTestData ()
74+ private function pfopOptionsTestData ()
5675 {
5776 return array (
5877 array (
@@ -69,31 +88,47 @@ private function pfopTypeTestData()
6988 ),
7089 array (
7190 'type ' => 2
91+ ),
92+ array (
93+ 'workflowTemplateID ' => 'test-workflow '
7294 )
7395 );
7496 }
7597
76- public function testPfopWithIdleTimeType ()
98+ public function testPfopExecuteWithOptions ()
7799 {
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 ());
85103
86- $ testCases = $ this ->pfopTypeTestData ();
104+ $ testCases = $ this ->pfopOptionsTestData ();
87105
88106 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+ }
89123 list ($ id , $ error ) = $ pfop ->execute (
90124 $ bucket ,
91125 $ key ,
92126 $ fops ,
93127 null ,
94128 null ,
95129 false ,
96- $ testCase ['type ' ]
130+ $ testCase ['type ' ],
131+ $ testCase ['workflowTemplateID ' ]
97132 );
98133
99134 if (in_array ($ testCase ['type ' ], array (null , 0 , 1 ))) {
@@ -104,29 +139,50 @@ public function testPfopWithIdleTimeType()
104139 if ($ testCase ['type ' ] == 1 ) {
105140 $ this ->assertEquals (1 , $ status ['type ' ]);
106141 }
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+ }
107151 $ this ->assertNotEmpty ($ status ['creationDate ' ]);
108152 } else {
109153 $ this ->assertNotNull ($ error );
110154 }
111155 }
112156 }
113157
114-
115- public function testPfopByUploadPolicy ()
158+ public function testPfopWithUploadPolicy ()
116159 {
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 ' ;
122163
123- $ testCases = $ this ->pfopTypeTestData ();
164+ $ testCases = $ this ->pfopOptionsTestData ();
124165
125166 foreach ($ testCases as $ testCase ) {
126167 $ putPolicy = array (
127- 'persistentOps ' => $ fops ,
128168 'persistentType ' => $ testCase ['type ' ]
129169 );
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+ }
130186
131187 if ($ testCase ['type ' ] == null ) {
132188 unset($ putPolicy ['persistentType ' ]);
@@ -165,16 +221,24 @@ public function testPfopByUploadPolicy()
165221 if ($ testCase ['type ' ] == 1 ) {
166222 $ this ->assertEquals (1 , $ status ['type ' ]);
167223 }
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+ }
168233 $ this ->assertNotEmpty ($ status ['creationDate ' ]);
169234 }
170235 }
171236
172237 public function testMkzip ()
173238 {
174- global $ testAuth ;
175- $ bucket = 'phpsdk ' ;
239+ $ bucket = self ::$ bucketName ;
176240 $ key = 'php-logo.png ' ;
177- $ pfop = new PersistentFop ($ testAuth , null );
241+ $ pfop = new PersistentFop (self :: $ testAuth , null );
178242
179243 $ url1 = 'http://phpsdk.qiniudn.com/php-logo.png ' ;
180244 $ url2 = 'http://phpsdk.qiniudn.com/php-sdk.html ' ;
0 commit comments