AbstractTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Amazon
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: AbstractTest.php 17667 2009-08-18 21:40:09Z mikaelkael $
  21. */
  22. require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
  23. /**
  24. * @todo: Rename class to Zend_Service_Amazon_AbstractTest
  25. *
  26. * @category Zend
  27. * @package Zend_Service_Amazon
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Service
  32. * @group Zend_Service_Amazon
  33. * @group Zend_Service_Amazon_Ec2
  34. */
  35. class Zend_Service_Amazon_Ec2_AbstractTest extends PHPUnit_Framework_TestCase
  36. {
  37. /**
  38. * Prepares the environment before running a test.
  39. */
  40. protected function setUp()
  41. {
  42. parent::setUp();
  43. }
  44. /**
  45. * Cleans up the environment after running a test.
  46. */
  47. protected function tearDown()
  48. {
  49. parent::tearDown();
  50. }
  51. public function testNoKeysThrowException()
  52. {
  53. try {
  54. $class = new TestAmamzonEc2Abstract();
  55. $this->fail('Exception should be thrown when no keys are passed in.');
  56. } catch(Zend_Service_Amazon_Exception $zsae) {}
  57. }
  58. public function testSetRegion()
  59. {
  60. TestAmamzonEc2Abstract::setRegion('eu-west-1');
  61. $class = new TestAmamzonEc2Abstract('TestAccessKey', 'TestSecretKey');
  62. $this->assertEquals('eu-west-1', $class->returnRegion());
  63. }
  64. public function testSetInvalidRegionThrowsException()
  65. {
  66. try {
  67. TestAmamzonEc2Abstract::setRegion('eu-west-1a');
  68. $this->fail('Invalid Region Set with no Exception Thrown');
  69. } catch (Zend_Service_Amazon_Exception $zsae) {
  70. // do nothing
  71. }
  72. }
  73. public function testSignParamsWithSpaceEncodesWithPercentInsteadOfPlus()
  74. {
  75. $class = new TestAmamzonEc2Abstract('TestAccessKey', 'TestSecretKey');
  76. $ret = $class->testSign(array('Action' => 'Space Test'));
  77. // this is the encode signuature with urlencode - It's Invalid!
  78. $invalidSignature = 'EeHAfo7cMcLyvH4SW4fEpjo51xJJ4ES1gdjRPxZTlto=';
  79. $this->assertNotEquals($ret, $invalidSignature);
  80. }
  81. }
  82. class TestAmamzonEc2Abstract extends Zend_Service_Amazon_Ec2_Abstract
  83. {
  84. public function returnRegion()
  85. {
  86. return $this->_region;
  87. }
  88. public function testSign($params)
  89. {
  90. return $this->signParameters($params);
  91. }
  92. }