BucketCnameTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace OSS\Tests;
  3. require_once __DIR__ . '/Common.php';
  4. use OSS\Model\CnameConfig;
  5. class BucketCnameTest extends \PHPUnit_Framework_TestCase
  6. {
  7. private $bucketName;
  8. private $client;
  9. public function setUp()
  10. {
  11. $this->client = Common::getOssClient();
  12. $this->bucketName = 'php-sdk-test-bucket-' . strval(rand(0, 10000));
  13. $this->client->createBucket($this->bucketName);
  14. }
  15. public function tearDown()
  16. {
  17. $this->client->deleteBucket($this->bucketName);
  18. }
  19. public function testBucketWithoutCname()
  20. {
  21. $cnameConfig = $this->client->getBucketCname($this->bucketName);
  22. $this->assertEquals(0, count($cnameConfig->getCnames()));
  23. }
  24. public function testAddCname()
  25. {
  26. $this->client->addBucketCname($this->bucketName, 'www.baidu.com');
  27. $this->client->addBucketCname($this->bucketName, 'www.qq.com');
  28. $ret = $this->client->getBucketCname($this->bucketName);
  29. $this->assertEquals(2, count($ret->getCnames()));
  30. // add another 2 cnames
  31. $this->client->addBucketCname($this->bucketName, 'www.sina.com.cn');
  32. $this->client->addBucketCname($this->bucketName, 'www.iqiyi.com');
  33. $ret = $this->client->getBucketCname($this->bucketName);
  34. $cnames = $ret->getCnames();
  35. $cnameList = array();
  36. foreach ($cnames as $c) {
  37. $cnameList[] = $c['Domain'];
  38. }
  39. $should = array(
  40. 'www.baidu.com',
  41. 'www.qq.com',
  42. 'www.sina.com.cn',
  43. 'www.iqiyi.com'
  44. );
  45. $this->assertEquals(4, count($cnames));
  46. $this->assertEquals(sort($should), sort($cnameList));
  47. }
  48. public function testDeleteCname()
  49. {
  50. $this->client->addBucketCname($this->bucketName, 'www.baidu.com');
  51. $this->client->addBucketCname($this->bucketName, 'www.qq.com');
  52. $ret = $this->client->getBucketCname($this->bucketName);
  53. $this->assertEquals(2, count($ret->getCnames()));
  54. // delete one cname
  55. $this->client->deleteBucketCname($this->bucketName, 'www.baidu.com');
  56. $ret = $this->client->getBucketCname($this->bucketName);
  57. $this->assertEquals(1, count($ret->getCnames()));
  58. $cnames = $ret->getCnames();
  59. $this->assertEquals('www.qq.com', $cnames[0]['Domain']);
  60. }
  61. }