DefaultProfileTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. include_once '../../Config.php';
  21. class DefaultProfileTest extends PHPUnit_Framework_TestCase
  22. {
  23. public function testGetProfile()
  24. {
  25. $profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret");
  26. $this->assertEquals("cn-hangzhou",$profile->getRegionId());
  27. $this->assertEquals("accessId",$profile->getCredential()->getAccessKeyId());
  28. $this->assertEquals("accessSecret",$profile->getCredential()->getAccessSecret());
  29. }
  30. public function testAddEndpoint()
  31. {
  32. $profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret");
  33. $profile->addEndpoint("cn-hangzhou", "cn-hangzhou", "TestProduct", "testproduct.aliyuncs.com");
  34. $endpoints = $profile->getEndpoints();
  35. foreach ($endpoints as $key => $endpoint)
  36. {
  37. if("cn-hangzhou" == $endpoint->getName())
  38. {
  39. $regionIds = $endpoint->getRegionIds();
  40. $this->assertContains("cn-hangzhou",$regionIds);
  41. $productDomains= $endpoint->getProductDomains();
  42. $this->assertNotNull($productDomains);
  43. $productDomain = $this->getProductDomain($productDomains);
  44. $this->assertNotNull($productDomain);
  45. $this->assertEquals("TestProduct",$productDomain->getProductName());
  46. $this->assertEquals("testproduct.aliyuncs.com",$productDomain->getDomainName());
  47. }
  48. }
  49. }
  50. private function getProductDomain($productDomains)
  51. {
  52. foreach ($productDomains as $productDomain)
  53. {
  54. if($productDomain->getProductName() == "TestProduct")
  55. {
  56. return $productDomain;
  57. }
  58. }
  59. return null;
  60. }
  61. }