2
0

AbstractTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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-2010 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 dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  23. require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
  24. /**
  25. * @todo: Rename class to Zend_Service_Amazon_AbstractTest
  26. *
  27. * @category Zend
  28. * @package Zend_Service_Amazon
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Service
  33. * @group Zend_Service_Amazon
  34. * @group Zend_Service_Amazon_Ec2
  35. */
  36. class Zend_Service_Amazon_Ec2_AbstractTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Prepares the environment before running a test.
  40. */
  41. protected function setUp()
  42. {
  43. parent::setUp();
  44. }
  45. /**
  46. * Cleans up the environment after running a test.
  47. */
  48. protected function tearDown()
  49. {
  50. parent::tearDown();
  51. }
  52. public function testNoKeysThrowException()
  53. {
  54. try {
  55. $class = new TestAmamzonAbstract();
  56. $this->fail('Exception should be thrown when no keys are passed in.');
  57. } catch(Zend_Service_Amazon_Exception $zsae) {}
  58. }
  59. public function testSetRegion()
  60. {
  61. TestAmamzonAbstract::setRegion('eu-west-1');
  62. $class = new TestAmamzonAbstract('TestAccessKey', 'TestSecretKey');
  63. $this->assertEquals('eu-west-1', $class->returnRegion());
  64. }
  65. public function testSetInvalidRegionThrowsException()
  66. {
  67. try {
  68. TestAmamzonAbstract::setRegion('eu-west-1a');
  69. $this->fail('Invalid Region Set with no Exception Thrown');
  70. } catch (Zend_Service_Amazon_Exception $zsae) {
  71. // do nothing
  72. }
  73. }
  74. public function testSignParamsWithSpaceEncodesWithPercentInsteadOfPlus()
  75. {
  76. $class = new TestAmamzonAbstract('TestAccessKey', 'TestSecretKey');
  77. $ret = $class->testSign(array('Action' => 'Space Test'));
  78. // this is the encode signuature with urlencode - It's Invalid!
  79. $invalidSignature = 'EeHAfo7cMcLyvH4SW4fEpjo51xJJ4ES1gdjRPxZTlto=';
  80. $this->assertNotEquals($ret, $invalidSignature);
  81. }
  82. }
  83. class TestAmamzonAbstract extends Zend_Service_Amazon_Ec2_Abstract
  84. {
  85. public function returnRegion()
  86. {
  87. return $this->_region;
  88. }
  89. public function testSign($params)
  90. {
  91. return $this->signParameters($params);
  92. }
  93. }