فهرست منبع

ZF-2146
Zend_Gdata
Improved test suite for Zend_Gdata_AuthSub


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24028 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan 14 سال پیش
والد
کامیت
ff31fe459d
1فایلهای تغییر یافته به همراه135 افزوده شده و 0 حذف شده
  1. 135 0
      tests/Zend/Gdata/AuthSubTest.php

+ 135 - 0
tests/Zend/Gdata/AuthSubTest.php

@@ -30,9 +30,17 @@ require_once 'Zend/Gdata/HttpClient.php';
  * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  * @group      Zend_Gdata
+ * @group      Zend_Gdata_AuthSub
  */
 class Zend_Gdata_AuthSubTest extends PHPUnit_Framework_TestCase
 {
+    /**
+     * Dummy token used during testing
+     * @var type string
+     */
+    protected $token = 'DQAAFPHOW7DCTN';
+    
+    
     public function setUp()
     {
     }
@@ -125,4 +133,131 @@ class Zend_Gdata_AuthSubTest extends PHPUnit_Framework_TestCase
             $c->setAuthSubPrivateKeyFile("zendauthsubfilenotfound",  null, true);
         }
     }
+        
+    public function testAuthSubSessionTokenReceivesSuccessfulResult()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Test();
+        $adapter->setResponse("HTTP/1.1 200 OK\r\n\r\nToken={$this->token}\r\nExpiration=20201004T123456Z");
+        
+        $client = new Zend_Gdata_HttpClient();
+        $client->setUri('http://example.com/AuthSub');
+        $client->setAdapter($adapter);
+        
+        $respToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($this->token, $client);
+        $this->assertEquals($this->token, $respToken);        
+    }
+
+    /**
+     * @expectedException Zend_Gdata_App_AuthException
+     */
+    public function testAuthSubSessionTokenCatchesFailedResult()
+    {        
+        $adapter = new Zend_Http_Client_Adapter_Test();
+        $adapter->setResponse("HTTP/1.1 500 Internal Server Error\r\n\r\nInternal Server Error");
+        
+        $client = new Zend_Gdata_HttpClient();
+        $client->setUri('http://example.com/AuthSub');
+        $client->setAdapter($adapter);
+        
+        $newtok = Zend_Gdata_AuthSub::getAuthSubSessionToken($this->token, $client);
+    }
+    
+    /**
+     * @expectedException Zend_Gdata_App_HttpException
+     */
+    public function testAuthSubSessionTokenCatchesHttpClientException()
+    {        
+        $adapter = new Zend_Http_Client_Adapter_Test();
+        $adapter->setNextRequestWillFail(true);
+        
+        $client = new Zend_Gdata_HttpClient();
+        $client->setUri('http://example.com/AuthSub');
+        $client->setAdapter($adapter);
+        
+        $newtok = Zend_Gdata_AuthSub::getAuthSubSessionToken($this->token, $client);
+    }
+    
+    public function testAuthSubRevokeTokenReceivesSuccessfulResult()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Test();
+        $adapter->setResponse("HTTP/1.1 200 OK");
+        
+        $client = new Zend_Gdata_HttpClient();
+        $client->setUri('http://example.com/AuthSub');
+        $client->setAdapter($adapter);
+        
+        $revoked = Zend_Gdata_AuthSub::AuthSubRevokeToken($this->token, $client);
+        $this->assertTrue($revoked);
+    }
+
+    public function testAuthSubRevokeTokenCatchesFailedResult()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Test();
+        $adapter->setResponse("HTTP/1.1 500 Not Successful");
+        
+        $client = new Zend_Gdata_HttpClient();
+        $client->setUri('http://example.com/AuthSub');
+        $client->setAdapter($adapter);
+        
+        $revoked = Zend_Gdata_AuthSub::AuthSubRevokeToken($this->token, $client);
+        $this->assertFalse($revoked);
+    }
+
+    /**
+     * @expectedException Zend_Gdata_App_HttpException
+     */
+    public function testAuthSubRevokeTokenCatchesHttpClientException()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Test();
+        $adapter->setNextRequestWillFail(true);
+        
+        $client = new Zend_Gdata_HttpClient();
+        $client->setUri('http://example.com/AuthSub');
+        $client->setAdapter($adapter);
+        
+        $revoked = Zend_Gdata_AuthSub::AuthSubRevokeToken($this->token, $client);
+    }
+        
+    public function testGetAuthSubTokenInfoReceivesSuccessfulResult()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Test();
+        $adapter->setResponse("HTTP/1.1 200 OK
+
+Target=http://example.com
+Scope=http://example.com
+Secure=false");
+        
+        $client = new Zend_Gdata_HttpClient();
+        $client->setUri('http://example.com/AuthSub');
+        $client->setAdapter($adapter);
+        
+        $respBody = Zend_Gdata_AuthSub::getAuthSubTokenInfo($this->token, $client);
+        
+        $this->assertContains("Target=http://example.com", $respBody);
+        $this->assertContains("Scope=http://example.com", $respBody);
+        $this->assertContains("Secure=false", $respBody);
+    }
+    
+    /**
+     * @expectedException Zend_Gdata_App_HttpException
+     */
+    public function testGetAuthSubTokenInfoCatchesHttpClientException()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Test();
+        $adapter->setNextRequestWillFail(true);
+        
+        $client = new Zend_Gdata_HttpClient();
+        $client->setUri('http://example.com/AuthSub');
+        $client->setAdapter($adapter);
+        
+        $revoked = Zend_Gdata_AuthSub::getAuthSubTokenInfo($this->token, $client);
+    }
+    
+    public function testGetHttpClientProvidesNewClientWhenNullPassed()
+    {
+        $client = Zend_Gdata_AuthSub::getHttpClient($this->token);
+        $this->assertTrue($client instanceof Zend_Gdata_HttpClient );
+        $this->assertEquals($this->token, $client->getAuthSubToken());
+    }
+    
 }