Exemplo n.º 1
0
 public function execute()
 {
     $getOptSpec = array('dictionaryFile::', 'minWidth::', 'maxWidth::', 'minHeight::', 'maxHeight::', 'shapesToDraw::', 'shape::', 'number::', 'format::');
     $options = getopt(null, $getOptSpec);
     $format = isset($options['format']) ? $options['format'] : 'jpg';
     unset($options['format']);
     $number = isset($options['number']) ? intval($options['number']) : 10;
     unset($options['number']);
     $randomImageGenerator = new RandomImageGenerator($options);
     $randomImageGenerator->writeImages($number, $format);
 }
Exemplo n.º 2
0
 /**
  * @depends testLogin
  */
 public function testUploadStash($session)
 {
     $this->setMwGlobals(array('wgUser' => self::$users['uploader']->getUser()));
     $extension = 'png';
     $mimeType = 'image/png';
     try {
         $randomImageGenerator = new RandomImageGenerator();
         $filePaths = $randomImageGenerator->writeImages(1, $extension, $this->getNewTempDirectory());
     } catch (Exception $e) {
         $this->markTestIncomplete($e->getMessage());
     }
     /** @var array $filePaths */
     $filePath = $filePaths[0];
     $fileSize = filesize($filePath);
     $fileName = basename($filePath);
     $this->deleteFileByFileName($fileName);
     $this->deleteFileByContent($filePath);
     if (!$this->fakeUploadFile('file', $fileName, $mimeType, $filePath)) {
         $this->markTestIncomplete("Couldn't upload file!\n");
     }
     $params = array('action' => 'upload', 'stash' => 1, 'filename' => $fileName, 'file' => 'dummy content', 'comment' => 'dummy comment', 'text' => "This is the page text for {$fileName}");
     $exception = false;
     try {
         list($result, , $session) = $this->doApiRequestWithToken($params, $session, self::$users['uploader']->getUser());
         // FIXME: leaks a temporary file
     } catch (UsageException $e) {
         $exception = true;
     }
     $this->assertFalse($exception);
     $this->assertTrue(isset($result['upload']));
     $this->assertEquals('Success', $result['upload']['result']);
     $this->assertEquals($fileSize, (int) $result['upload']['imageinfo']['size']);
     $this->assertEquals($mimeType, $result['upload']['imageinfo']['mime']);
     $this->assertTrue(isset($result['upload']['filekey']));
     $this->assertEquals($result['upload']['sessionkey'], $result['upload']['filekey']);
     $filekey = $result['upload']['filekey'];
     // it should be visible from Special:UploadStash
     // XXX ...but how to test this, with a fake WebRequest with the session?
     // now we should try to release the file from stash
     $params = array('action' => 'upload', 'filekey' => $filekey, 'filename' => $fileName, 'comment' => 'dummy comment', 'text' => "This is the page text for {$fileName}, altered");
     $this->clearFakeUploads();
     $exception = false;
     try {
         list($result) = $this->doApiRequestWithToken($params, $session, self::$users['uploader']->getUser());
     } catch (UsageException $e) {
         $exception = true;
     }
     $this->assertTrue(isset($result['upload']));
     $this->assertEquals('Success', $result['upload']['result']);
     $this->assertFalse($exception, "No UsageException exception.");
     // clean up
     $this->deleteFileByFilename($fileName);
 }