Exemplo n.º 1
0
 public function testParseFileTypes()
 {
     $contents = "a fractal of rad design";
     $file = ParseFile::createFromData($contents, "noextension");
     $file2 = ParseFile::createFromData($contents, "photo.png", "text/plain");
     $file3 = ParseFile::createFromData($contents, "photo.png");
     $file->save();
     $file2->save();
     $file3->save();
     $fileAgain = ParseFile::_createFromServer($file->getName(), $file->getURL());
     $file2Again = ParseFile::_createFromServer($file2->getName(), $file2->getURL());
     $file3Again = ParseFile::_createFromServer($file3->getName(), $file3->getURL());
     $this->assertEquals($contents, $fileAgain->getData());
     $this->assertEquals($contents, $file2Again->getData());
     $this->assertEquals($contents, $file3Again->getData());
     $this->assertEquals("unknown/unknown", $fileAgain->getMimeType());
     $this->assertEquals("text/plain", $file2Again->getMimeType());
     $this->assertEquals("image/png", $file3Again->getMimeType());
 }
Exemplo n.º 2
0
 /**
  * ParseClient::_decode, internal method for decoding server responses.
  *
  * @param mixed $data The value to decode
  *
  * @return mixed
  */
 public static function _decode($data)
 {
     // The json decoded response from Parse will make JSONObjects into stdClass
     //     objects.    We'll change it to an associative array here.
     if ($data instanceof \stdClass) {
         $tmp = (array) $data;
         if (!empty($tmp)) {
             return self::_decode(get_object_vars($data));
         }
     }
     if (!isset($data) && !is_array($data)) {
         return;
     }
     if (is_array($data)) {
         $typeString = isset($data['__type']) ? $data['__type'] : null;
         if ($typeString === 'Date') {
             return new \DateTime($data['iso']);
         }
         if ($typeString === 'Bytes') {
             return base64_decode($data['base64']);
         }
         if ($typeString === 'Pointer') {
             return ParseObject::create($data['className'], $data['objectId']);
         }
         if ($typeString === 'File') {
             return ParseFile::_createFromServer($data['name'], $data['url']);
         }
         if ($typeString === 'GeoPoint') {
             return new ParseGeoPoint($data['latitude'], $data['longitude']);
         }
         if ($typeString === 'Object') {
             $output = ParseObject::create($data['className']);
             $output->_mergeAfterFetch($data);
             return $output;
         }
         if ($typeString === 'Relation') {
             return $data;
         }
         $newDict = [];
         foreach ($data as $key => $value) {
             $newDict[$key] = static::_decode($value);
         }
         return $newDict;
     }
     return $data;
 }
Exemplo n.º 3
0
 public function testFileDelete()
 {
     $data = "c-c-c-combo breaker";
     $name = "php.txt";
     $file = ParseFile::createFromData($data, $name);
     $file->save();
     $url = $file->getURL();
     $fileAgain = ParseFile::_createFromServer($name, $url);
     $contents = $fileAgain->getData();
     $this->assertEquals($data, $contents);
     $file->delete();
     $fileAgain = ParseFile::_createFromServer($name, $url);
     $this->setExpectedException('Parse\\ParseException', 'Download failed');
     $contents = $fileAgain->getData();
 }
Exemplo n.º 4
0
 public function testFileDelete()
 {
     $data = 'c-c-c-combo breaker';
     $name = 'php.txt';
     $file = ParseFile::createFromData($data, $name);
     $file->save();
     $url = $file->getURL();
     $fileAgain = ParseFile::_createFromServer($name, $url);
     $contents = $fileAgain->getData();
     $this->assertEquals($data, $contents);
     $file->delete();
     //We can't retrieve deleted file because it cached with CloudFront.
     //We need to check it's availability throw Parse API (?) or
     //turn on CloudFront's cache invalidation based on query string
     //$fileAgain = ParseFile::_createFromServer($name, $url);
     //$this->setExpectedException('Parse\ParseException', 'Download failed');
     //$contents = $fileAgain->getData();
 }