-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from leancloud/deprecate-file-api
feat(file): new file key mechanism
- Loading branch information
Showing
4 changed files
with
96 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
use LeanCloud\LeanObject; | ||
use LeanCloud\Client; | ||
use LeanCloud\File; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class MasterTest extends TestCase { | ||
public static function setUpBeforeClass() { | ||
Client::initialize( | ||
getenv("LEANCLOUD_APP_ID"), | ||
getenv("LEANCLOUD_APP_KEY"), | ||
getenv("LEANCLOUD_APP_MASTER_KEY")); | ||
Client::useMasterKey(true); | ||
} | ||
|
||
public function testSaveWithSpecifiedKey() { | ||
$file = File::createWithData("test.txt", "Hello World!"); | ||
$file->setKey("abc"); | ||
$this->assertEquals("abc", $file->getKey()); | ||
$file->save(); | ||
$this->assertNotEmpty($file->getObjectId()); | ||
$this->assertNotEmpty($file->getName()); | ||
|
||
$this->assertEquals("abc", $file->getKey()); | ||
$url = $file->getUrl(); | ||
$parsedUrl = parse_url($url); | ||
$path = $parsedUrl["path"]; | ||
$oldSchoolAwsS3FileUrlPrefix = "/avos-cloud-"; | ||
$newAwsS3GluttonyUrlPrefix = "https://lc-gluttony"; | ||
if (substr($path, 0, strlen($oldSchoolAwsS3FileUrlPrefix)) === $oldSchoolAwsS3FileUrlPrefix) { | ||
$splitPath = explode("/", $path, 3); | ||
$this->assertEquals("abc", $splitPath[2]); | ||
} else if (substr($url, 0, strlen($newAwsS3GluttonyUrlPrefix)) === $newAwsS3GluttonyUrlPrefix) { | ||
$gluttonyPath = "/" + substr(getenv("LEANCLOUD_APP_KEY"), 0, 12) + "/abc"; | ||
$this->assertEquals($gluttonyPath, $path); | ||
} else { | ||
$this->assertEquals("/abc", $path); | ||
} | ||
|
||
$this->assertEquals("text/plain", $file->getMimeType()); | ||
$content = file_get_contents($url); | ||
$this->assertEquals("Hello World!", $content); | ||
|
||
$file->destroy(); | ||
} | ||
} |