33
44use PHPUnit \Framework \TestCase ;
55
6- use Qiniu \Processing \Operation ;
76use Qiniu \Processing \PersistentFop ;
7+ use Qiniu \Storage \UploadManager ;
8+ use Qiniu \Region ;
9+ use Qiniu \Config ;
810
911class PfopTest extends TestCase
1012{
11- public function testPfop ()
13+ private static function getConfig ()
14+ {
15+ // use this func to test in test env
16+ // `null` means to use production env
17+ return null ;
18+ }
19+
20+ public function testPfopExecuteAndStatusWithSingleFop ()
1221 {
1322 global $ testAuth ;
1423 $ bucket = 'testres ' ;
1524 $ key = 'sintel_trailer.mp4 ' ;
16- $ pfop = new PersistentFop ($ testAuth , null );
25+ $ pfop = new PersistentFop ($ testAuth , self :: getConfig () );
1726
1827 $ fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240 ' ;
1928 list ($ id , $ error ) = $ pfop ->execute ($ bucket , $ key , $ fops );
@@ -24,7 +33,7 @@ public function testPfop()
2433 }
2534
2635
27- public function testPfops ()
36+ public function testPfopExecuteAndStatusWithMultipleFops ()
2837 {
2938 global $ testAuth ;
3039 $ bucket = 'testres ' ;
@@ -33,7 +42,7 @@ public function testPfops()
3342 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240 ' ,
3443 'vframe/jpg/offset/7/w/480/h/360 ' ,
3544 );
36- $ pfop = new PersistentFop ($ testAuth , null );
45+ $ pfop = new PersistentFop ($ testAuth , self :: getConfig () );
3746
3847 list ($ id , $ error ) = $ pfop ->execute ($ bucket , $ key , $ fops );
3948 $ this ->assertNull ($ error );
@@ -43,6 +52,71 @@ public function testPfops()
4352 $ this ->assertNull ($ error );
4453 }
4554
55+ public function testPfopWithIdleTimeType ()
56+ {
57+ global $ testAuth ;
58+
59+ $ bucket = 'testres ' ;
60+ $ key = 'sintel_trailer.mp4 ' ;
61+ $ persistentEntry = \Qiniu \entry ($ bucket , 'test-pfop-type_1 ' );
62+ $ fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/ ' . $ persistentEntry ;
63+ $ pfop = new PersistentFop ($ testAuth , self ::getConfig ());
64+
65+ list ($ id , $ error ) = $ pfop ->execute (
66+ $ bucket ,
67+ $ key ,
68+ $ fops ,
69+ null ,
70+ null ,
71+ false ,
72+ 1
73+ );
74+ $ this ->assertNull ($ error );
75+ list ($ status , $ error ) = $ pfop ->status ($ id );
76+ $ this ->assertNotNull ($ status );
77+ $ this ->assertNull ($ error );
78+ $ this ->assertEquals (1 , $ status ['type ' ]);
79+ $ this ->assertNotEmpty ($ status ['creationDate ' ]);
80+ }
81+
82+ public function testPfopByUploadPolicy ()
83+ {
84+ global $ testAuth ;
85+ $ bucket = 'testres ' ;
86+ $ key = 'sintel_trailer.mp4 ' ;
87+ $ persistentEntry = \Qiniu \entry ($ bucket , 'test-pfop-type_1 ' );
88+ $ fops = 'avthumb/m3u8/segtime/10/vcodec/libx264/s/320x240|saveas/ ' . $ persistentEntry ;
89+
90+ $ token = $ testAuth ->uploadToken (
91+ $ bucket ,
92+ $ key ,
93+ 3600 ,
94+ array (
95+ 'persistentOps ' => $ fops ,
96+ 'persistentType ' => 1
97+ )
98+ );
99+ $ upManager = new UploadManager (self ::getConfig ());
100+ list ($ ret , $ error ) = $ upManager ->putFile (
101+ $ token ,
102+ $ key ,
103+ __file__,
104+ null ,
105+ 'text/plain ' ,
106+ true
107+ );
108+ $ this ->assertNull ($ error );
109+ $ this ->assertNotEmpty ($ ret ['persistentId ' ]);
110+ $ id = $ ret ['persistentId ' ];
111+
112+ $ pfop = new PersistentFop ($ testAuth , self ::getConfig ());
113+ list ($ status , $ error ) = $ pfop ->status ($ id );
114+ $ this ->assertNotNull ($ status );
115+ $ this ->assertNull ($ error );
116+ $ this ->assertEquals (1 , $ status ['type ' ]);
117+ $ this ->assertNotEmpty ($ status ['creationDate ' ]);
118+ }
119+
46120 public function testMkzip ()
47121 {
48122 global $ testAuth ;
0 commit comments