mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-31 00:03:58 +01:00 
			
		
		
		
	Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
		
							parent
							
								
									5a580df460
								
							
						
					
					
						commit
						235a541597
					
				
					 793 changed files with 60746 additions and 23753 deletions
				
			
		
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * SocketTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Network | ||||
|  * @since         CakePHP(tm) v 1.2.0.4206 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('CakeSocket', 'Network'); | ||||
|  | @ -57,7 +56,7 @@ class CakeSocketTest extends CakeTestCase { | |||
| 		$this->assertSame($config, array( | ||||
| 			'persistent'	=> false, | ||||
| 			'host'			=> 'localhost', | ||||
| 			'protocol'		=> getprotobyname('tcp'), | ||||
| 			'protocol'		=> 'tcp', | ||||
| 			'port'			=> 80, | ||||
| 			'timeout'		=> 30 | ||||
| 		)); | ||||
|  | @ -72,7 +71,7 @@ class CakeSocketTest extends CakeTestCase { | |||
| 
 | ||||
| 		$config['host'] = 'www.cakephp.org'; | ||||
| 		$config['port'] = 23; | ||||
| 		$config['protocol'] = 17; | ||||
| 		$config['protocol'] = 'udp'; | ||||
| 
 | ||||
| 		$this->assertSame($this->Socket->config, $config); | ||||
| 	} | ||||
|  | @ -86,16 +85,20 @@ class CakeSocketTest extends CakeTestCase { | |||
| 		$this->assertFalse($this->Socket->connected); | ||||
| 		$this->Socket->disconnect(); | ||||
| 		$this->assertFalse($this->Socket->connected); | ||||
| 		$this->Socket->connect(); | ||||
| 		$this->assertTrue($this->Socket->connected); | ||||
| 		$this->Socket->connect(); | ||||
| 		$this->assertTrue($this->Socket->connected); | ||||
| 		try { | ||||
| 			$this->Socket->connect(); | ||||
| 			$this->assertTrue($this->Socket->connected); | ||||
| 			$this->Socket->connect(); | ||||
| 			$this->assertTrue($this->Socket->connected); | ||||
| 
 | ||||
| 		$this->Socket->disconnect(); | ||||
| 		$config = array('persistent' => true); | ||||
| 		$this->Socket = new CakeSocket($config); | ||||
| 		$this->Socket->connect(); | ||||
| 		$this->assertTrue($this->Socket->connected); | ||||
| 			$this->Socket->disconnect(); | ||||
| 			$config = array('persistent' => true); | ||||
| 			$this->Socket = new CakeSocket($config); | ||||
| 			$this->Socket->connect(); | ||||
| 			$this->assertTrue($this->Socket->connected); | ||||
| 		} catch (SocketException $e) { | ||||
| 			$this->markTestSkipped('Cannot test network, skipping.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -115,7 +118,7 @@ class CakeSocketTest extends CakeTestCase { | |||
|  * | ||||
|  * @dataProvider invalidConnections | ||||
|  * @expectedException SocketException | ||||
|  * return void | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testInvalidConnection($data) { | ||||
| 		$this->Socket->config = array_merge($this->Socket->config, $data); | ||||
|  | @ -128,19 +131,23 @@ class CakeSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testSocketHost() { | ||||
| 		$this->Socket = new CakeSocket(); | ||||
| 		$this->Socket->connect(); | ||||
| 		$this->assertEquals('127.0.0.1', $this->Socket->address()); | ||||
| 		$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host()); | ||||
| 		$this->assertEquals(null, $this->Socket->lastError()); | ||||
| 		$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses())); | ||||
| 		try { | ||||
| 			$this->Socket = new CakeSocket(); | ||||
| 			$this->Socket->connect(); | ||||
| 			$this->assertEquals('127.0.0.1', $this->Socket->address()); | ||||
| 			$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host()); | ||||
| 			$this->assertEquals(null, $this->Socket->lastError()); | ||||
| 			$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses())); | ||||
| 
 | ||||
| 		$this->Socket = new CakeSocket(array('host' => '127.0.0.1')); | ||||
| 		$this->Socket->connect(); | ||||
| 		$this->assertEquals('127.0.0.1', $this->Socket->address()); | ||||
| 		$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host()); | ||||
| 		$this->assertEquals(null, $this->Socket->lastError()); | ||||
| 		$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses())); | ||||
| 			$this->Socket = new CakeSocket(array('host' => '127.0.0.1')); | ||||
| 			$this->Socket->connect(); | ||||
| 			$this->assertEquals('127.0.0.1', $this->Socket->address()); | ||||
| 			$this->assertEquals(gethostbyaddr('127.0.0.1'), $this->Socket->host()); | ||||
| 			$this->assertEquals(null, $this->Socket->lastError()); | ||||
| 			$this->assertTrue(in_array('127.0.0.1', $this->Socket->addresses())); | ||||
| 		} catch (SocketException $e) { | ||||
| 			$this->markTestSkipped('Cannot test network, skipping.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -149,8 +156,12 @@ class CakeSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testSocketWriting() { | ||||
| 		$request = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n"; | ||||
| 		$this->assertTrue((bool)$this->Socket->write($request)); | ||||
| 		try { | ||||
| 			$request = "GET / HTTP/1.1\r\nConnection: close\r\n\r\n"; | ||||
| 			$this->assertTrue((bool)$this->Socket->write($request)); | ||||
| 		} catch (SocketException $e) { | ||||
| 			$this->markTestSkipped('Cannot test network, skipping.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -160,14 +171,18 @@ class CakeSocketTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testSocketReading() { | ||||
| 		$this->Socket = new CakeSocket(array('timeout' => 5)); | ||||
| 		$this->Socket->connect(); | ||||
| 		$this->assertEquals(null, $this->Socket->read(26)); | ||||
| 		try { | ||||
| 			$this->Socket->connect(); | ||||
| 			$this->assertEquals(null, $this->Socket->read(26)); | ||||
| 
 | ||||
| 		$config = array('host' => 'google.com', 'port' => 80, 'timeout' => 1); | ||||
| 		$this->Socket = new CakeSocket($config); | ||||
| 		$this->assertTrue($this->Socket->connect()); | ||||
| 		$this->assertEquals(null, $this->Socket->read(26)); | ||||
| 		$this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError()); | ||||
| 			$config = array('host' => 'google.com', 'port' => 80, 'timeout' => 1); | ||||
| 			$this->Socket = new CakeSocket($config); | ||||
| 			$this->assertTrue($this->Socket->connect()); | ||||
| 			$this->assertEquals(null, $this->Socket->read(26)); | ||||
| 			$this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError()); | ||||
| 		} catch (SocketException $e) { | ||||
| 			$this->markTestSkipped('Cannot test network, skipping.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -178,12 +193,16 @@ class CakeSocketTest extends CakeTestCase { | |||
| 	public function testTimeOutConnection() { | ||||
| 		$config = array('host' => '127.0.0.1', 'timeout' => 0.5); | ||||
| 		$this->Socket = new CakeSocket($config); | ||||
| 		$this->assertTrue($this->Socket->connect()); | ||||
| 		try { | ||||
| 			$this->assertTrue($this->Socket->connect()); | ||||
| 
 | ||||
| 		$config = array('host' => '127.0.0.1', 'timeout' => 0.00001); | ||||
| 		$this->Socket = new CakeSocket($config); | ||||
| 		$this->assertFalse($this->Socket->read(1024 * 1024)); | ||||
| 		$this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError()); | ||||
| 			$config = array('host' => '127.0.0.1', 'timeout' => 0.00001); | ||||
| 			$this->Socket = new CakeSocket($config); | ||||
| 			$this->assertFalse($this->Socket->read(1024 * 1024)); | ||||
| 			$this->assertEquals('2: ' . __d('cake_dev', 'Connection timed out'), $this->Socket->lastError()); | ||||
| 		} catch (SocketException $e) { | ||||
| 			$this->markTestSkipped('Cannot test network, skipping.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -204,14 +223,194 @@ class CakeSocketTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testReset() { | ||||
| 		$config = array( | ||||
| 			'persistent'	=> true, | ||||
| 			'host'			=> '127.0.0.1', | ||||
| 			'protocol'		=> 'udp', | ||||
| 			'port'			=> 80, | ||||
| 			'timeout'		=> 20 | ||||
| 			'persistent' => true, | ||||
| 			'host' => '127.0.0.1', | ||||
| 			'protocol' => 'udp', | ||||
| 			'port' => 80, | ||||
| 			'timeout' => 20 | ||||
| 		); | ||||
| 		$anotherSocket = new CakeSocket($config); | ||||
| 		$anotherSocket->reset(); | ||||
| 		$this->assertEquals(array(), $anotherSocket->config); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEncrypt | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testEnableCryptoSocketExceptionNoSsl() { | ||||
| 		$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); | ||||
| 		$configNoSslOrTls = array('host' => 'localhost', 'port' => 80, 'timeout' => 0.1); | ||||
| 
 | ||||
| 		// testing exception on no ssl socket server for ssl and tls methods
 | ||||
| 		$this->Socket = new CakeSocket($configNoSslOrTls); | ||||
| 		$this->Socket->connect(); | ||||
| 		$this->Socket->enableCrypto('sslv3', 'client'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEnableCryptoSocketExceptionNoTls | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testEnableCryptoSocketExceptionNoTls() { | ||||
| 		$configNoSslOrTls = array('host' => 'localhost', 'port' => 80, 'timeout' => 0.1); | ||||
| 
 | ||||
| 		// testing exception on no ssl socket server for ssl and tls methods
 | ||||
| 		$this->Socket = new CakeSocket($configNoSslOrTls); | ||||
| 		$this->Socket->connect(); | ||||
| 		$this->Socket->enableCrypto('tls', 'client'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that protocol in the host doesn't cause cert errors. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnectProtocolInHost() { | ||||
| 		$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); | ||||
| 		$configSslTls = array('host' => 'ssl://smtp.gmail.com', 'port' => 465, 'timeout' => 5); | ||||
| 		$socket = new CakeSocket($configSslTls); | ||||
| 		try { | ||||
| 			$socket->connect(); | ||||
| 			$this->assertEquals('smtp.gmail.com', $socket->config['host']); | ||||
| 			$this->assertEquals('ssl', $socket->config['protocol']); | ||||
| 		} catch (SocketException $e) { | ||||
| 			$this->markTestSkipped('Cannot test network, skipping.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * _connectSocketToSslTls | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	protected function _connectSocketToSslTls() { | ||||
| 		$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); | ||||
| 		$configSslTls = array('host' => 'smtp.gmail.com', 'port' => 465, 'timeout' => 5); | ||||
| 		$this->Socket = new CakeSocket($configSslTls); | ||||
| 		try { | ||||
| 			$this->Socket->connect(); | ||||
| 		} catch (SocketException $e) { | ||||
| 			$this->markTestSkipped('Cannot test network, skipping.'); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEnableCryptoBadMode | ||||
|  * | ||||
|  * @expectedException InvalidArgumentException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testEnableCryptoBadMode() { | ||||
| 		// testing wrong encryption mode
 | ||||
| 		$this->_connectSocketToSslTls(); | ||||
| 		$this->Socket->enableCrypto('doesntExistMode', 'server'); | ||||
| 		$this->Socket->disconnect(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEnableCrypto | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testEnableCrypto() { | ||||
| 		// testing on tls server
 | ||||
| 		$this->_connectSocketToSslTls(); | ||||
| 		$this->assertTrue($this->Socket->enableCrypto('tls', 'client')); | ||||
| 		$this->Socket->disconnect(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEnableCryptoExceptionEnableTwice | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testEnableCryptoExceptionEnableTwice() { | ||||
| 		// testing on tls server
 | ||||
| 		$this->_connectSocketToSslTls(); | ||||
| 		$this->Socket->enableCrypto('tls', 'client'); | ||||
| 		$this->Socket->enableCrypto('tls', 'client'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEnableCryptoExceptionDisableTwice | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testEnableCryptoExceptionDisableTwice() { | ||||
| 		// testing on tls server
 | ||||
| 		$this->_connectSocketToSslTls(); | ||||
| 		$this->Socket->enableCrypto('tls', 'client', false); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEnableCryptoEnableStatus | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testEnableCryptoEnableStatus() { | ||||
| 		// testing on tls server
 | ||||
| 		$this->_connectSocketToSslTls(); | ||||
| 		$this->assertFalse($this->Socket->encrypted); | ||||
| 		$this->Socket->enableCrypto('tls', 'client', true); | ||||
| 		$this->assertTrue($this->Socket->encrypted); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test getting the context for a socket. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetContext() { | ||||
| 		$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); | ||||
| 		$config = array( | ||||
| 			'host' => 'smtp.gmail.com', | ||||
| 			'port' => 465, | ||||
| 			'timeout' => 5, | ||||
| 			'context' => array( | ||||
| 				'ssl' => array('capture_peer' => true) | ||||
| 			) | ||||
| 		); | ||||
| 		$this->Socket = new CakeSocket($config); | ||||
| 		$this->Socket->connect(); | ||||
| 		$result = $this->Socket->context(); | ||||
| 		$this->assertSame($config['context']['ssl']['capture_peer'], $result['ssl']['capture_peer']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test configuring the context from the flat keys. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConfigContext() { | ||||
| 		$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); | ||||
| 		$config = array( | ||||
| 			'host' => 'smtp.gmail.com', | ||||
| 			'port' => 465, | ||||
| 			'timeout' => 5, | ||||
| 			'ssl_verify_peer' => true, | ||||
| 			'ssl_allow_self_signed' => false, | ||||
| 			'ssl_verify_depth' => 5, | ||||
| 			'ssl_verify_host' => true, | ||||
| 		); | ||||
| 		$this->Socket = new CakeSocket($config); | ||||
| 
 | ||||
| 		$this->Socket->connect(); | ||||
| 		$result = $this->Socket->context(); | ||||
| 
 | ||||
| 		$this->assertTrue($result['ssl']['verify_peer']); | ||||
| 		$this->assertFalse($result['ssl']['allow_self_signed']); | ||||
| 		$this->assertEquals(5, $result['ssl']['verify_depth']); | ||||
| 		$this->assertEquals('smtp.gmail.com', $result['ssl']['CN_match']); | ||||
| 		$this->assertArrayNotHasKey('ssl_verify_peer', $this->Socket->config); | ||||
| 		$this->assertArrayNotHasKey('ssl_allow_self_signed', $this->Socket->config); | ||||
| 		$this->assertArrayNotHasKey('ssl_verify_host', $this->Socket->config); | ||||
| 		$this->assertArrayNotHasKey('ssl_verify_depth', $this->Socket->config); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -2,27 +2,26 @@ | |||
| /** | ||||
|  * DebugTransportTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Network.Email | ||||
|  * @since         CakePHP(tm) v 2.0.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('CakeEmail', 'Network/Email'); | ||||
| App::uses('AbstractTransport', 'Network/Email'); | ||||
| App::uses('DebugTransport', 'Network/Email'); | ||||
| 
 | ||||
| /** | ||||
|  * Test case | ||||
|  * | ||||
|  */ | ||||
| class DebugTransportTest extends CakeTestCase { | ||||
| 
 | ||||
|  | @ -32,6 +31,7 @@ class DebugTransportTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->DebugTransport = new DebugTransport(); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -41,8 +41,7 @@ class DebugTransportTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testSend() { | ||||
| 		$this->getMock('CakeEmail', array('message'), array(), 'DebugCakeEmail'); | ||||
| 		$email = new DebugCakeEmail(); | ||||
| 		$email = $this->getMock('CakeEmail', array('message'), array(), 'DebugCakeEmail'); | ||||
| 		$email->from('noreply@cakephp.org', 'CakePHP Test'); | ||||
| 		$email->to('cake@cakephp.org', 'CakePHP'); | ||||
| 		$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso')); | ||||
|  | @ -51,7 +50,7 @@ class DebugTransportTest extends CakeTestCase { | |||
| 		$email->subject('Testing Message'); | ||||
| 		$date = date(DATE_RFC2822); | ||||
| 		$email->setHeaders(array('X-Mailer' => DebugCakeEmail::EMAIL_CLIENT, 'Date' => $date)); | ||||
| 		$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); | ||||
| 		$email->expects($this->once())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); | ||||
| 
 | ||||
| 		$headers = "From: CakePHP Test <noreply@cakephp.org>\r\n"; | ||||
| 		$headers .= "To: CakePHP <cake@cakephp.org>\r\n"; | ||||
|  | @ -74,4 +73,4 @@ class DebugTransportTest extends CakeTestCase { | |||
| 		$this->assertEquals($data, $result['message']); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -2,28 +2,26 @@ | |||
| /** | ||||
|  * MailTransportTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Network.Email | ||||
|  * @since         CakePHP(tm) v 2.0.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('CakeEmail', 'Network/Email'); | ||||
| App::uses('AbstractTransport', 'Network/Email'); | ||||
| App::uses('MailTransport', 'Network/Email'); | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Test case | ||||
|  * | ||||
|  */ | ||||
| class MailTransportTest extends CakeTestCase { | ||||
| 
 | ||||
|  | @ -33,6 +31,7 @@ class MailTransportTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->MailTransport = $this->getMock('MailTransport', array('_mail')); | ||||
| 		$this->MailTransport->config(array('additionalParameters' => '-f')); | ||||
| 	} | ||||
|  | @ -50,10 +49,19 @@ class MailTransportTest extends CakeTestCase { | |||
| 		$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso')); | ||||
| 		$email->bcc('phpnut@cakephp.org'); | ||||
| 		$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>'); | ||||
| 		$email->subject('Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz'); | ||||
| 		$longNonAscii = 'Foø Bår Béz Foø Bår Béz Foø Bår Béz Foø Bår Béz'; | ||||
| 		$email->subject($longNonAscii); | ||||
| 		$date = date(DATE_RFC2822); | ||||
| 		$email->setHeaders(array('X-Mailer' => 'CakePHP Email', 'Date' => $date)); | ||||
| 		$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); | ||||
| 		$email->setHeaders(array( | ||||
| 			'X-Mailer' => 'CakePHP Email', | ||||
| 			'Date' => $date, | ||||
| 			'X-add' => mb_encode_mimeheader($longNonAscii, 'utf8', 'B'), | ||||
| 		)); | ||||
| 		$email->expects($this->any())->method('message') | ||||
| 			->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); | ||||
| 
 | ||||
| 		$encoded = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?='; | ||||
| 		$encoded .= ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?='; | ||||
| 
 | ||||
| 		$data = "From: CakePHP Test <noreply@cakephp.org>" . PHP_EOL; | ||||
| 		$data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>" . PHP_EOL; | ||||
|  | @ -61,24 +69,25 @@ class MailTransportTest extends CakeTestCase { | |||
| 		$data .= "Bcc: phpnut@cakephp.org" . PHP_EOL; | ||||
| 		$data .= "X-Mailer: CakePHP Email" . PHP_EOL; | ||||
| 		$data .= "Date: " . $date . PHP_EOL; | ||||
| 		$data .= "X-add: " . $encoded . PHP_EOL; | ||||
| 		$data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>" . PHP_EOL; | ||||
| 		$data .= "MIME-Version: 1.0" . PHP_EOL; | ||||
| 		$data .= "Content-Type: text/plain; charset=UTF-8" . PHP_EOL; | ||||
| 		$data .= "Content-Transfer-Encoding: 8bit"; | ||||
| 
 | ||||
| 		$subject = '=?UTF-8?B?Rm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXogRm/DuCBCw6VyIELDqXog?='; | ||||
| 		$subject .= "\r\n" . ' =?UTF-8?B?Rm/DuCBCw6VyIELDqXo=?='; | ||||
| 		$this->MailTransport->expects($this->once())->method('_mail') | ||||
| 			->with( | ||||
| 				'CakePHP <cake@cakephp.org>', | ||||
| 				$subject, | ||||
| 				$encoded, | ||||
| 				implode(PHP_EOL, array('First Line', 'Second Line', '.Third Line', '')), | ||||
| 				$data, | ||||
| 				'-f' | ||||
| 			); | ||||
| 
 | ||||
| 		$this->MailTransport->send($email); | ||||
| 		$result = $this->MailTransport->send($email); | ||||
| 
 | ||||
| 		$this->assertContains('Subject: ', $result['headers']); | ||||
| 		$this->assertContains('To: ', $result['headers']); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,50 +2,39 @@ | |||
| /** | ||||
|  * SmtpTransportTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Network.Email | ||||
|  * @since         CakePHP(tm) v 2.0.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('CakeEmail', 'Network/Email'); | ||||
| App::uses('AbstractTransport', 'Network/Email'); | ||||
| App::uses('SmtpTransport', 'Network/Email'); | ||||
| 
 | ||||
| /** | ||||
|  * Help to test SmtpTransport | ||||
|  * | ||||
|  */ | ||||
| class SmtpTestTransport extends SmtpTransport { | ||||
| 
 | ||||
| /** | ||||
|  * Helper to change the socket | ||||
|  * | ||||
|  * @param object $socket | ||||
|  * @param CakeSocket $socket A socket. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setSocket(CakeSocket $socket) { | ||||
| 		$this->_socket = $socket; | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Helper to change the CakeEmail | ||||
|  * | ||||
|  * @param object $cakeEmail | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setCakeEmail($cakeEmail) { | ||||
| 		$this->_cakeEmail = $cakeEmail; | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Disabled the socket change | ||||
|  * | ||||
|  | @ -57,20 +46,19 @@ class SmtpTestTransport extends SmtpTransport { | |||
| /** | ||||
|  * Magic function to call protected methods | ||||
|  * | ||||
|  * @param string $method | ||||
|  * @param string $args | ||||
|  * @param string $method The method to call. | ||||
|  * @param string $args The arguments. | ||||
|  * @return mixed | ||||
|  */ | ||||
| 	public function __call($method, $args) { | ||||
| 		$method = '_' . $method; | ||||
| 		return $this->$method(); | ||||
| 		return call_user_func_array(array($this, $method), $args); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Test case | ||||
|  * | ||||
|  */ | ||||
| class SmtpTransportTest extends CakeTestCase { | ||||
| 
 | ||||
|  | @ -80,10 +68,8 @@ class SmtpTransportTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		if (!class_exists('MockSocket')) { | ||||
| 			$this->getMock('CakeSocket', array('read', 'write', 'connect'), array(), 'MockSocket'); | ||||
| 		} | ||||
| 		$this->socket = new MockSocket(); | ||||
| 		parent::setUp(); | ||||
| 		$this->socket = $this->getMock('CakeSocket', array('read', 'write', 'connect', 'enableCrypto')); | ||||
| 
 | ||||
| 		$this->SmtpTransport = new SmtpTestTransport(); | ||||
| 		$this->SmtpTransport->setSocket($this->socket); | ||||
|  | @ -105,6 +91,72 @@ class SmtpTransportTest extends CakeTestCase { | |||
| 		$this->SmtpTransport->connect(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testConnectEhloTls method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnectEhloTls() { | ||||
| 		$this->SmtpTransport->config(array('tls' => true)); | ||||
| 		$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true)); | ||||
| 		$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n")); | ||||
| 		$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n"); | ||||
| 		$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n")); | ||||
| 		$this->socket->expects($this->at(5))->method('write')->with("STARTTLS\r\n"); | ||||
| 		$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("220 Server ready\r\n")); | ||||
| 		$this->socket->expects($this->at(8))->method('enableCrypto')->with('tls')->will($this->returnValue(true)); | ||||
| 		$this->socket->expects($this->at(9))->method('write')->with("EHLO localhost\r\n"); | ||||
| 		$this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 Accepted\r\n")); | ||||
| 		$this->SmtpTransport->connect(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testConnectEhloTlsOnNonTlsServer method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @expectedExceptionMessage SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnectEhloTlsOnNonTlsServer() { | ||||
| 		$this->SmtpTransport->config(array('tls' => true)); | ||||
| 		$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true)); | ||||
| 		$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n")); | ||||
| 		$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n"); | ||||
| 		$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n")); | ||||
| 		$this->socket->expects($this->at(5))->method('write')->with("STARTTLS\r\n"); | ||||
| 		$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("500 5.3.3 Unrecognized command\r\n")); | ||||
| 		$this->SmtpTransport->connect(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testConnectEhloNoTlsOnRequiredTlsServer method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @expectedExceptionMessage SMTP authentication method not allowed, check if SMTP server requires TLS. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnectEhloNoTlsOnRequiredTlsServer() { | ||||
| 		$this->SmtpTransport->config(array('tls' => false, 'username' => 'user', 'password' => 'pass')); | ||||
| 		$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true)); | ||||
| 		$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n")); | ||||
| 		$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n"); | ||||
| 		$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n")); | ||||
| 		$this->socket->expects($this->at(5))->method('write')->with("AUTH LOGIN\r\n"); | ||||
| 		$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("504 5.7.4 Unrecognized authentication type\r\n")); | ||||
| 		$this->SmtpTransport->connect(); | ||||
| 		$this->SmtpTransport->auth(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testConnectHelo method | ||||
|  * | ||||
|  | @ -127,6 +179,7 @@ class SmtpTransportTest extends CakeTestCase { | |||
|  * testConnectFail method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @expectedExceptionMessage SMTP server did not accept the connection. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnectFail() { | ||||
|  | @ -161,13 +214,98 @@ class SmtpTransportTest extends CakeTestCase { | |||
| 		$this->SmtpTransport->auth(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testAuthNotRecognized method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @expectedExceptionMessage AUTH command not recognized or not implemented, SMTP server may not require authentication. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthNotRecognized() { | ||||
| 		$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n"); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("500 5.3.3 Unrecognized command\r\n")); | ||||
| 		$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story')); | ||||
| 		$this->SmtpTransport->auth(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testAuthNotImplemented method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @expectedExceptionMessage AUTH command not recognized or not implemented, SMTP server may not require authentication. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthNotImplemented() { | ||||
| 		$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n"); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("502 5.3.3 Command not implemented\r\n")); | ||||
| 		$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story')); | ||||
| 		$this->SmtpTransport->auth(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testAuthBadSequence method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @expectedExceptionMessage SMTP Error: 503 5.5.1 Already authenticated | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthBadSequence() { | ||||
| 		$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n"); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("503 5.5.1 Already authenticated\r\n")); | ||||
| 		$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story')); | ||||
| 		$this->SmtpTransport->auth(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testAuthBadUsername method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @expectedExceptionMessage SMTP server did not accept the username. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthBadUsername() { | ||||
| 		$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n"); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n")); | ||||
| 		$this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n"); | ||||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("535 5.7.8 Authentication failed\r\n")); | ||||
| 		$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story')); | ||||
| 		$this->SmtpTransport->auth(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testAuthBadPassword method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @expectedExceptionMessage SMTP server did not accept the password. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthBadPassword() { | ||||
| 		$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n"); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n")); | ||||
| 		$this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n"); | ||||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("334 Pass\r\n")); | ||||
| 		$this->socket->expects($this->at(6))->method('write')->with("c3Rvcnk=\r\n"); | ||||
| 		$this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("535 5.7.8 Authentication failed\r\n")); | ||||
| 		$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story')); | ||||
| 		$this->SmtpTransport->auth(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testAuthNoAuth method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuthNoAuth() { | ||||
| 		$this->socket->expects($this->never())->method('write')->with("AUTH LOGIN\r\n"); | ||||
| 		$this->socket->expects($this->any())->method('write')->with($this->logicalNot($this->stringContains('AUTH LOGIN'))); | ||||
| 
 | ||||
| 		$this->SmtpTransport->config(array('username' => null, 'password' => null)); | ||||
| 		$this->SmtpTransport->auth(); | ||||
| 	} | ||||
|  | @ -200,8 +338,28 @@ class SmtpTransportTest extends CakeTestCase { | |||
| 		$this->socket->expects($this->at(13))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(14))->method('read')->will($this->returnValue("250 OK\r\n")); | ||||
| 
 | ||||
| 		$this->SmtpTransport->setCakeEmail($email); | ||||
| 		$this->SmtpTransport->sendRcpt(); | ||||
| 		$this->SmtpTransport->sendRcpt($email); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testRcptWithReturnPath method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRcptWithReturnPath() { | ||||
| 		$email = new CakeEmail(); | ||||
| 		$email->from('noreply@cakephp.org', 'CakePHP Test'); | ||||
| 		$email->to('cake@cakephp.org', 'CakePHP'); | ||||
| 		$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return'); | ||||
| 
 | ||||
| 		$this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<pleasereply@cakephp.org>\r\n"); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n")); | ||||
| 		$this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n"); | ||||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n")); | ||||
| 
 | ||||
| 		$this->SmtpTransport->sendRcpt($email); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -210,8 +368,7 @@ class SmtpTransportTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testSendData() { | ||||
| 		$this->getMock('CakeEmail', array('message'), array(), 'SmtpCakeEmail'); | ||||
| 		$email = new SmtpCakeEmail(); | ||||
| 		$email = $this->getMock('CakeEmail', array('message'), array(), 'SmtpCakeEmail'); | ||||
| 		$email->from('noreply@cakephp.org', 'CakePHP Test'); | ||||
| 		$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return'); | ||||
| 		$email->to('cake@cakephp.org', 'CakePHP'); | ||||
|  | @ -221,10 +378,9 @@ class SmtpTransportTest extends CakeTestCase { | |||
| 		$email->subject('Testing SMTP'); | ||||
| 		$date = date(DATE_RFC2822); | ||||
| 		$email->setHeaders(array('X-Mailer' => SmtpCakeEmail::EMAIL_CLIENT, 'Date' => $date)); | ||||
| 		$email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); | ||||
| 		$email->expects($this->once())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); | ||||
| 
 | ||||
| 		$data = "From: CakePHP Test <noreply@cakephp.org>\r\n"; | ||||
| 		$data .= "Return-Path: CakePHP Return <pleasereply@cakephp.org>\r\n"; | ||||
| 		$data .= "To: CakePHP <cake@cakephp.org>\r\n"; | ||||
| 		$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n"; | ||||
| 		$data .= "X-Mailer: CakePHP Email\r\n"; | ||||
|  | @ -248,8 +404,7 @@ class SmtpTransportTest extends CakeTestCase { | |||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n")); | ||||
| 
 | ||||
| 		$this->SmtpTransport->setCakeEmail($email); | ||||
| 		$this->SmtpTransport->sendData(); | ||||
| 		$this->SmtpTransport->sendData($email); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -262,4 +417,108 @@ class SmtpTransportTest extends CakeTestCase { | |||
| 		$this->SmtpTransport->disconnect(); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testEmptyConfigArray method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testEmptyConfigArray() { | ||||
| 		$expected = $this->SmtpTransport->config(array( | ||||
| 			'client' => 'myhost.com', | ||||
| 			'port' => 666 | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertEquals(666, $expected['port']); | ||||
| 
 | ||||
| 		$result = $this->SmtpTransport->config(array()); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testGetLastResponse method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetLastResponse() { | ||||
| 		$this->assertEmpty($this->SmtpTransport->getLastResponse()); | ||||
| 
 | ||||
| 		$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true)); | ||||
| 		$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n")); | ||||
| 		$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n"); | ||||
| 		$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250-PIPELINING\r\n")); | ||||
| 		$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250-SIZE 102400000\r\n")); | ||||
| 		$this->socket->expects($this->at(6))->method('read')->will($this->returnValue("250-VRFY\r\n")); | ||||
| 		$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("250-ETRN\r\n")); | ||||
| 		$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250-STARTTLS\r\n")); | ||||
| 		$this->socket->expects($this->at(9))->method('read')->will($this->returnValue("250-AUTH PLAIN LOGIN\r\n")); | ||||
| 		$this->socket->expects($this->at(10))->method('read')->will($this->returnValue("250-AUTH=PLAIN LOGIN\r\n")); | ||||
| 		$this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250-ENHANCEDSTATUSCODES\r\n")); | ||||
| 		$this->socket->expects($this->at(12))->method('read')->will($this->returnValue("250-8BITMIME\r\n")); | ||||
| 		$this->socket->expects($this->at(13))->method('read')->will($this->returnValue("250 DSN\r\n")); | ||||
| 		$this->SmtpTransport->connect(); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			array('code' => '250', 'message' => 'PIPELINING'), | ||||
| 			array('code' => '250', 'message' => 'SIZE 102400000'), | ||||
| 			array('code' => '250', 'message' => 'VRFY'), | ||||
| 			array('code' => '250', 'message' => 'ETRN'), | ||||
| 			array('code' => '250', 'message' => 'STARTTLS'), | ||||
| 			array('code' => '250', 'message' => 'AUTH PLAIN LOGIN'), | ||||
| 			array('code' => '250', 'message' => 'AUTH=PLAIN LOGIN'), | ||||
| 			array('code' => '250', 'message' => 'ENHANCEDSTATUSCODES'), | ||||
| 			array('code' => '250', 'message' => '8BITMIME'), | ||||
| 			array('code' => '250', 'message' => 'DSN') | ||||
| 		); | ||||
| 		$result = $this->SmtpTransport->getLastResponse(); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$email = new CakeEmail(); | ||||
| 		$email->from('noreply@cakephp.org', 'CakePHP Test'); | ||||
| 		$email->to('cake@cakephp.org', 'CakePHP'); | ||||
| 
 | ||||
| 		$this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<noreply@cakephp.org>\r\n"); | ||||
| 		$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n")); | ||||
| 		$this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n"); | ||||
| 		$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n")); | ||||
| 
 | ||||
| 		$this->SmtpTransport->sendRcpt($email); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			array('code' => '250', 'message' => 'OK'), | ||||
| 		); | ||||
| 		$result = $this->SmtpTransport->getLastResponse(); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testBufferResponseLines method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testBufferResponseLines() { | ||||
| 		$reponseLines = array( | ||||
| 			'123', | ||||
| 			"456\tFOO", | ||||
| 			'FOOBAR', | ||||
| 			'250-PIPELINING', | ||||
| 			'250-ENHANCEDSTATUSCODES', | ||||
| 			'250-8BITMIME', | ||||
| 			'250 DSN', | ||||
| 		); | ||||
| 		$this->SmtpTransport->bufferResponseLines($reponseLines); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			array('code' => '123', 'message' => null), | ||||
| 			array('code' => '250', 'message' => 'PIPELINING'), | ||||
| 			array('code' => '250', 'message' => 'ENHANCEDSTATUSCODES'), | ||||
| 			array('code' => '250', 'message' => '8BITMIME'), | ||||
| 			array('code' => '250', 'message' => 'DSN') | ||||
| 		); | ||||
| 		$result = $this->SmtpTransport->getLastResponse(); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -2,24 +2,42 @@ | |||
| /** | ||||
|  * BasicAuthenticationTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Network.Http | ||||
|  * @since         CakePHP(tm) v 2.0.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('HttpSocket', 'Network/Http'); | ||||
| App::uses('BasicAuthentication', 'Network/Http'); | ||||
| 
 | ||||
| /** | ||||
|  * TestSslHttpSocket | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Network.Http | ||||
|  */ | ||||
| class TestSslHttpSocket extends HttpSocket { | ||||
| 
 | ||||
| /** | ||||
|  * testSetProxy method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSetProxy($proxy = null) { | ||||
| 		$this->_proxy = $proxy; | ||||
| 		$this->_setProxy(); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * BasicMethodTest class | ||||
|  * | ||||
|  | @ -61,4 +79,26 @@ class BasicAuthenticationTest extends CakeTestCase { | |||
| 		$this->assertEquals('Basic bWFyazpzZWNyZXQ=', $http->request['header']['Proxy-Authorization']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testProxyAuthenticationSsl method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testProxyAuthenticationSsl() { | ||||
| 		$http = new TestSslHttpSocket(); | ||||
| 		$http->request['uri']['scheme'] = 'https'; | ||||
| 		$proxy = array( | ||||
| 			'host' => 'localhost', | ||||
| 			'port' => 3128, | ||||
| 			'method' => 'Basic', | ||||
| 			'user' => 'mark', | ||||
| 			'pass' => 'secret' | ||||
| 		); | ||||
| 
 | ||||
| 		$http->testSetProxy($proxy); | ||||
| 
 | ||||
| 		$this->assertEquals('Basic bWFyazpzZWNyZXQ=', $http->config['proxyauth']); | ||||
| 		$this->assertFalse(isset($http->request['header']['Proxy-Authorization'])); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -2,24 +2,28 @@ | |||
| /** | ||||
|  * DigestAuthenticationTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Network.Http | ||||
|  * @since         CakePHP(tm) v 2.0.0 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('HttpSocket', 'Network/Http'); | ||||
| App::uses('DigestAuthentication', 'Network/Http'); | ||||
| 
 | ||||
| /** | ||||
|  * DigestHttpSocket | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Network.Http | ||||
|  */ | ||||
| class DigestHttpSocket extends HttpSocket { | ||||
| 
 | ||||
| /** | ||||
|  | @ -57,7 +61,7 @@ class DigestAuthenticationTest extends CakeTestCase { | |||
| /** | ||||
|  * Socket property | ||||
|  * | ||||
|  * @var mixed null | ||||
|  * @var mixed | ||||
|  */ | ||||
| 	public $HttpSocket = null; | ||||
| 
 | ||||
|  | @ -67,6 +71,7 @@ class DigestAuthenticationTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->HttpSocket = new DigestHttpSocket(); | ||||
| 		$this->HttpSocket->request['method'] = 'GET'; | ||||
| 		$this->HttpSocket->request['uri']['path'] = '/'; | ||||
|  | @ -78,6 +83,7 @@ class DigestAuthenticationTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		unset($this->HttpSocket); | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,21 +2,19 @@ | |||
| /** | ||||
|  * HttpResponseTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Network.Http | ||||
|  * @since         CakePHP(tm) v 1.2.0.4206 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('HttpResponse', 'Network/Http'); | ||||
| 
 | ||||
| /** | ||||
|  | @ -40,7 +38,7 @@ class TestHttpResponse extends HttpResponse { | |||
|  * Convenience method for testing protected method | ||||
|  * | ||||
|  * @param string $body A string containing the body to decode | ||||
|  * @param boolean|string $encoding Can be false in case no encoding is being used, or a string representing the encoding | ||||
|  * @param bool|string $encoding Can be false in case no encoding is being used, or a string representing the encoding | ||||
|  * @return mixed Array or false | ||||
|  */ | ||||
| 	public function decodeBody($body, $encoding = 'chunked') { | ||||
|  | @ -70,7 +68,7 @@ class TestHttpResponse extends HttpResponse { | |||
| /** | ||||
|  * Convenience method for testing protected method | ||||
|  * | ||||
|  * @param boolean $hex true to get them as HEX values, false otherwise | ||||
|  * @param bool $hex true to get them as HEX values, false otherwise | ||||
|  * @return array Escape chars | ||||
|  */ | ||||
| 	public function tokenEscapeChars($hex = true, $chars = null) { | ||||
|  | @ -92,6 +90,7 @@ class HttpResponseTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->HttpResponse = new TestHttpResponse(); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -141,7 +140,7 @@ class HttpResponseTest extends CakeTestCase { | |||
| 		$this->assertEquals('Bar', $this->HttpResponse->getHeader('FOO')); | ||||
| 		$this->assertEquals('value', $this->HttpResponse->getHeader('header')); | ||||
| 		$this->assertEquals('text/plain', $this->HttpResponse->getHeader('Content-Type')); | ||||
| 		$this->assertSame($this->HttpResponse->getHeader(0), null); | ||||
| 		$this->assertNull($this->HttpResponse->getHeader(0)); | ||||
| 
 | ||||
| 		$this->assertEquals('Bar', $this->HttpResponse->getHeader('foo', false)); | ||||
| 		$this->assertEquals('not from class', $this->HttpResponse->getHeader('foo', array('foo' => 'not from class'))); | ||||
|  | @ -157,12 +156,36 @@ class HttpResponseTest extends CakeTestCase { | |||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = -1; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 201; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 'what?'; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 200; | ||||
| 		$this->assertTrue($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 201; | ||||
| 		$this->assertTrue($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 202; | ||||
| 		$this->assertTrue($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 203; | ||||
| 		$this->assertTrue($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 204; | ||||
| 		$this->assertTrue($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 205; | ||||
| 		$this->assertTrue($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 206; | ||||
| 		$this->assertTrue($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 207; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 208; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 209; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 210; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 226; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 288; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 		$this->HttpResponse->code = 301; | ||||
| 		$this->assertFalse($this->HttpResponse->isOk()); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -244,10 +267,19 @@ class HttpResponseTest extends CakeTestCase { | |||
| 		); | ||||
| 		$this->assertEquals($expected, $r); | ||||
| 
 | ||||
| 		$header = "Multi-Line: I am a \r\nmulti line\t\r\nfield value.\r\nSingle-Line: I am not\r\n"; | ||||
| 		$header = "Date:Sat, 07 Apr 2007 10:10:25 GMT\r\nLink: \r\nX-Total-Count: 19\r\n"; | ||||
| 		$r = $this->HttpResponse->parseHeader($header); | ||||
| 		$expected = array( | ||||
| 			'Multi-Line' => "I am a\r\nmulti line\r\nfield value.", | ||||
| 			'Date' => 'Sat, 07 Apr 2007 10:10:25 GMT', | ||||
| 			'Link' => '', | ||||
| 			'X-Total-Count' => '19', | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $r); | ||||
| 
 | ||||
| 		$header = "Multi-Line: I am a\r\n multi line \r\n\tfield value.\r\nSingle-Line: I am not\r\n"; | ||||
| 		$r = $this->HttpResponse->parseHeader($header); | ||||
| 		$expected = array( | ||||
| 			'Multi-Line' => "I am a multi line field value.", | ||||
| 			'Single-Line' => 'I am not' | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $r); | ||||
|  | @ -331,7 +363,7 @@ class HttpResponseTest extends CakeTestCase { | |||
|  * | ||||
|  * @dataProvider invalidParseResponseDataProvider | ||||
|  * @expectedException SocketException | ||||
|  * return void | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testInvalidParseResponseData($value) { | ||||
| 		$this->HttpResponse->parseResponse($value); | ||||
|  | @ -429,12 +461,13 @@ class HttpResponseTest extends CakeTestCase { | |||
| /** | ||||
|  * testDecodeChunkedBodyError method | ||||
|  * | ||||
|  * @expectedException SocketException | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecodeChunkedBodyError() { | ||||
| 		$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n"; | ||||
| 		$r = $this->HttpResponse->decodeChunkedBody($encoded); | ||||
| 		$result = $this->HttpResponse->decodeChunkedBody($encoded); | ||||
| 		$expected = "This is a chunked message\nThat is cool\n"; | ||||
| 		$this->assertEquals($expected, $result['body']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -447,7 +480,9 @@ class HttpResponseTest extends CakeTestCase { | |||
| 			'Set-Cookie' => array( | ||||
| 				'foo=bar', | ||||
| 				'people=jim,jack,johnny";";Path=/accounts', | ||||
| 				'google=not=nice' | ||||
| 				'google=not=nice', | ||||
| 				'1271; domain=.example.com; expires=Fri, 04-Nov-2016 12:50:26 GMT; path=/', | ||||
| 				'cakephp=great; Secure' | ||||
| 			), | ||||
| 			'Transfer-Encoding' => 'chunked', | ||||
| 			'Date' => 'Sun, 18 Nov 2007 18:57:42 GMT', | ||||
|  | @ -463,17 +498,24 @@ class HttpResponseTest extends CakeTestCase { | |||
| 			), | ||||
| 			'google' => array( | ||||
| 				'value' => 'not=nice', | ||||
| 			), | ||||
| 			'' => array( | ||||
| 				'value' => '1271', | ||||
| 				'domain' => '.example.com', | ||||
| 				'expires' => 'Fri, 04-Nov-2016 12:50:26 GMT', | ||||
| 				'path' => '/' | ||||
| 			), | ||||
| 			'cakephp' => array( | ||||
| 				'value' => 'great', | ||||
| 				'secure' => true, | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $cookies); | ||||
| 
 | ||||
| 		$header['Set-Cookie'][] = 'cakephp=great; Secure'; | ||||
| 		$expected['cakephp'] = array('value' => 'great', 'secure' => true); | ||||
| 		$cookies = $this->HttpResponse->parseCookies($header); | ||||
| 		$this->assertEquals($expected, $cookies); | ||||
| 
 | ||||
| 		$header['Set-Cookie'] = 'foo=bar'; | ||||
| 		unset($expected['people'], $expected['cakephp'], $expected['google']); | ||||
| 		$expected = array( | ||||
| 			'foo' => array('value' => 'bar') | ||||
| 		); | ||||
| 		$cookies = $this->HttpResponse->parseCookies($header); | ||||
| 		$this->assertEquals($expected, $cookies); | ||||
| 	} | ||||
|  | @ -552,7 +594,7 @@ class HttpResponseTest extends CakeTestCase { | |||
| 		$this->assertEquals($expected, $this->HttpResponse['cookies']); | ||||
| 
 | ||||
| 		$this->HttpResponse->raw = "HTTP/1.1 200 OK\r\n\r\nThis is a test!"; | ||||
| 		$this->assertSame($this->HttpResponse['raw']['header'], null); | ||||
| 		$this->assertNull($this->HttpResponse['raw']['header']); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * HttpSocketTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Network.Http | ||||
|  * @since         CakePHP(tm) v 1.2.0.4206 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('HttpSocket', 'Network/Http'); | ||||
|  | @ -24,15 +23,14 @@ App::uses('HttpResponse', 'Network/Http'); | |||
|  * TestAuthentication class | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Network.Http | ||||
|  * @package       Cake.Test.Case.Network.Http | ||||
|  */ | ||||
| class TestAuthentication { | ||||
| 
 | ||||
| /** | ||||
|  * authentication method | ||||
|  * | ||||
|  * @param HttpSocket $http | ||||
|  * @param array $authInfo | ||||
|  * @param HttpSocket $http A HTTP socket. | ||||
|  * @param array &$authInfo Some auth info. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public static function authentication(HttpSocket $http, &$authInfo) { | ||||
|  | @ -42,8 +40,8 @@ class TestAuthentication { | |||
| /** | ||||
|  * proxyAuthentication method | ||||
|  * | ||||
|  * @param HttpSocket $http | ||||
|  * @param array $proxyInfo | ||||
|  * @param HttpSocket $http A HTTP socket. | ||||
|  * @param array &$proxyInfo Some proxy info. | ||||
|  * @return void | ||||
|  */ | ||||
| 	public static function proxyAuthentication(HttpSocket $http, &$proxyInfo) { | ||||
|  | @ -54,7 +52,6 @@ class TestAuthentication { | |||
| 
 | ||||
| /** | ||||
|  * CustomResponse | ||||
|  * | ||||
|  */ | ||||
| class CustomResponse { | ||||
| 
 | ||||
|  | @ -68,6 +65,7 @@ class CustomResponse { | |||
| /** | ||||
|  * Constructor | ||||
|  * | ||||
|  * @param string $message A message. | ||||
|  */ | ||||
| 	public function __construct($message) { | ||||
| 		$this->first10 = substr($message, 0, 10); | ||||
|  | @ -77,7 +75,6 @@ class CustomResponse { | |||
| 
 | ||||
| /** | ||||
|  * TestHttpSocket | ||||
|  * | ||||
|  */ | ||||
| class TestHttpSocket extends HttpSocket { | ||||
| 
 | ||||
|  | @ -95,7 +92,7 @@ class TestHttpSocket extends HttpSocket { | |||
|  * Convenience method for testing protected method | ||||
|  * | ||||
|  * @param string|array $uri URI to parse | ||||
|  * @param boolean|array $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc. | ||||
|  * @param bool|array $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc. | ||||
|  * @return array Parsed URI | ||||
|  */ | ||||
| 	public function parseUri($uri = null, $base = array()) { | ||||
|  | @ -137,17 +134,16 @@ class TestHttpSocket extends HttpSocket { | |||
|  * Convenience method for testing protected method | ||||
|  * | ||||
|  * @param array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET. | ||||
|  * @param string $versionToken The version token to use, defaults to HTTP/1.1 | ||||
|  * @return string Request line | ||||
|  */ | ||||
| 	public function buildRequestLine($request = array(), $versionToken = 'HTTP/1.1') { | ||||
| 		return parent::_buildRequestLine($request, $versionToken); | ||||
| 	public function buildRequestLine($request = array()) { | ||||
| 		return parent::_buildRequestLine($request); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Convenience method for testing protected method | ||||
|  * | ||||
|  * @param boolean $hex true to get them as HEX values, false otherwise | ||||
|  * @param bool $hex true to get them as HEX values, false otherwise | ||||
|  * @return array Escape chars | ||||
|  */ | ||||
| 	public function tokenEscapeChars($hex = true, $chars = null) { | ||||
|  | @ -176,14 +172,14 @@ class HttpSocketTest extends CakeTestCase { | |||
| /** | ||||
|  * Socket property | ||||
|  * | ||||
|  * @var mixed null | ||||
|  * @var mixed | ||||
|  */ | ||||
| 	public $Socket = null; | ||||
| 
 | ||||
| /** | ||||
|  * RequestSocket property | ||||
|  * | ||||
|  * @var mixed null | ||||
|  * @var mixed | ||||
|  */ | ||||
| 	public $RequestSocket = null; | ||||
| 
 | ||||
|  | @ -193,13 +189,9 @@ class HttpSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		if (!class_exists('MockHttpSocket')) { | ||||
| 			$this->getMock('TestHttpSocket', array('read', 'write', 'connect'), array(), 'MockHttpSocket'); | ||||
| 			$this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'), array(), 'MockHttpSocketRequests'); | ||||
| 		} | ||||
| 
 | ||||
| 		$this->Socket = new MockHttpSocket(); | ||||
| 		$this->RequestSocket = new MockHttpSocketRequests(); | ||||
| 		parent::setUp(); | ||||
| 		$this->Socket = $this->getMock('TestHttpSocket', array('read', 'write', 'connect')); | ||||
| 		$this->RequestSocket = $this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -208,6 +200,7 @@ class HttpSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		unset($this->Socket, $this->RequestSocket); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -221,8 +214,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		$baseConfig = $this->Socket->config; | ||||
| 		$this->Socket->expects($this->never())->method('connect'); | ||||
| 		$this->Socket->__construct(array('host' => 'foo-bar')); | ||||
| 		$baseConfig['host']	 = 'foo-bar'; | ||||
| 		$baseConfig['protocol'] = getprotobyname($baseConfig['protocol']); | ||||
| 		$baseConfig['host'] = 'foo-bar'; | ||||
| 		$this->assertEquals($this->Socket->config, $baseConfig); | ||||
| 
 | ||||
| 		$this->Socket->reset(); | ||||
|  | @ -231,7 +223,6 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		$baseConfig['host'] = $baseConfig['request']['uri']['host'] = 'www.cakephp.org'; | ||||
| 		$baseConfig['port'] = $baseConfig['request']['uri']['port'] = 23; | ||||
| 		$baseConfig['request']['uri']['scheme'] = 'http'; | ||||
| 		$baseConfig['protocol'] = getprotobyname($baseConfig['protocol']); | ||||
| 		$this->assertEquals($this->Socket->config, $baseConfig); | ||||
| 
 | ||||
| 		$this->Socket->reset(); | ||||
|  | @ -253,6 +244,10 @@ class HttpSocketTest extends CakeTestCase { | |||
| 			'protocol' => 'tcp', | ||||
| 			'port' => 23, | ||||
| 			'timeout' => 30, | ||||
| 			'ssl_verify_peer' => true, | ||||
| 			'ssl_allow_self_signed' => false, | ||||
| 			'ssl_verify_depth' => 5, | ||||
| 			'ssl_verify_host' => true, | ||||
| 			'request' => array( | ||||
| 				'uri' => array( | ||||
| 					'scheme' => 'https', | ||||
|  | @ -260,7 +255,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 					'port' => 23 | ||||
| 				), | ||||
| 				'redirect' => false, | ||||
| 				'cookies' => array() | ||||
| 				'cookies' => array(), | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->Socket->config); | ||||
|  | @ -278,6 +273,10 @@ class HttpSocketTest extends CakeTestCase { | |||
| 			'protocol' => 'tcp', | ||||
| 			'port' => 80, | ||||
| 			'timeout' => 30, | ||||
| 			'ssl_verify_peer' => true, | ||||
| 			'ssl_allow_self_signed' => false, | ||||
| 			'ssl_verify_depth' => 5, | ||||
| 			'ssl_verify_host' => true, | ||||
| 			'request' => array( | ||||
| 				'uri' => array( | ||||
| 					'scheme' => 'http', | ||||
|  | @ -285,7 +284,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 					'port' => 80 | ||||
| 				), | ||||
| 				'redirect' => false, | ||||
| 				'cookies' => array() | ||||
| 				'cookies' => array(), | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $this->Socket->config); | ||||
|  | @ -306,6 +305,10 @@ class HttpSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testRequest() { | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->returnValue(false)); | ||||
| 
 | ||||
| 		$this->Socket->reset(); | ||||
| 
 | ||||
| 		$response = $this->Socket->request(true); | ||||
|  | @ -321,6 +324,10 @@ class HttpSocketTest extends CakeTestCase { | |||
| 						'protocol' => 'tcp', | ||||
| 						'port' => 80, | ||||
| 						'timeout' => 30, | ||||
| 						'ssl_verify_peer' => true, | ||||
| 						'ssl_allow_self_signed' => false, | ||||
| 						'ssl_verify_depth' => 5, | ||||
| 						'ssl_verify_host' => true, | ||||
| 						'request' => array( | ||||
| 							'uri' => array( | ||||
| 								'scheme' => 'http', | ||||
|  | @ -481,6 +488,9 @@ class HttpSocketTest extends CakeTestCase { | |||
| 					) | ||||
| 				) | ||||
| 			), | ||||
| 			'reset10' => array( | ||||
| 				'config.protocol' => 'ssl' | ||||
| 			), | ||||
| 			array( | ||||
| 				'request' => array( | ||||
| 					'method' => 'POST', | ||||
|  | @ -509,8 +519,12 @@ class HttpSocketTest extends CakeTestCase { | |||
| 					) | ||||
| 				) | ||||
| 			), | ||||
| 			'reset11' => array( | ||||
| 				'config.protocol' => 'ssl' | ||||
| 			), | ||||
| 			array( | ||||
| 				'request' => array( | ||||
| 					'version' => '1.0', | ||||
| 					'method' => 'POST', | ||||
| 					'uri' => 'https://www.cakephp.org/posts/add', | ||||
| 					'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'), | ||||
|  | @ -518,6 +532,8 @@ class HttpSocketTest extends CakeTestCase { | |||
| 				), | ||||
| 				'expectation' => array( | ||||
| 					'request' => array( | ||||
| 						'version' => '1.0', | ||||
| 						'line' => "POST /posts/add HTTP/1.0\r\n", | ||||
| 						'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\nCookie: foo=bar\r\n", | ||||
| 						'cookies' => array( | ||||
| 							'foo' => array('value' => 'bar'), | ||||
|  | @ -545,13 +561,13 @@ class HttpSocketTest extends CakeTestCase { | |||
| 			$expectation['request']['raw'] = $expectation['request']['line'] . $expectation['request']['header'] . "\r\n" . $raw; | ||||
| 
 | ||||
| 			$r = array('config' => $this->Socket->config, 'request' => $this->Socket->request); | ||||
| 			$v = $this->assertEquals($r, $expectation, 'Failed test #' . $i . ' '); | ||||
| 			$this->assertEquals($r, $expectation, 'Failed test #' . $i . ' '); | ||||
| 			$expectation['request']['raw'] = $raw; | ||||
| 		} | ||||
| 
 | ||||
| 		$this->Socket->reset(); | ||||
| 		$request = array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')); | ||||
| 		$response = $this->Socket->request($request); | ||||
| 		$this->Socket->request($request); | ||||
| 		$this->assertEquals("name=HttpSocket-is-released&date=today", $this->Socket->request['body']); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -561,6 +577,10 @@ class HttpSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testGetWithSchemeAndPort() { | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->returnValue(false)); | ||||
| 
 | ||||
| 		$this->Socket->reset(); | ||||
| 		$request = array( | ||||
| 			'uri' => array( | ||||
|  | @ -571,16 +591,20 @@ class HttpSocketTest extends CakeTestCase { | |||
| 			), | ||||
| 			'method' => 'GET' | ||||
| 		); | ||||
| 		$response = $this->Socket->request($request); | ||||
| 		$this->Socket->request($request); | ||||
| 		$this->assertContains('Host: cakephp.org:8080', $this->Socket->request['header']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test urls like http://cakephp.org/index.php?somestring without key/value pair for query | ||||
|  * Test URLs like http://cakephp.org/index.php?somestring without key/value pair for query | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRequestWithStringQuery() { | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->returnValue(false)); | ||||
| 
 | ||||
| 		$this->Socket->reset(); | ||||
| 		$request = array( | ||||
| 			'uri' => array( | ||||
|  | @ -591,7 +615,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 			), | ||||
| 			'method' => 'GET' | ||||
| 		); | ||||
| 		$response = $this->Socket->request($request); | ||||
| 		$this->Socket->request($request); | ||||
| 		$this->assertContains("GET /index.php?somestring HTTP/1.1", $this->Socket->request['line']); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -604,7 +628,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 	public function testRequestNotAllowedUri() { | ||||
| 		$this->Socket->reset(); | ||||
| 		$request = array('uri' => '*', 'method' => 'GET'); | ||||
| 		$response = $this->Socket->request($request); | ||||
| 		$this->Socket->request($request); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -614,14 +638,18 @@ class HttpSocketTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testRequest2() { | ||||
| 		$this->Socket->reset(); | ||||
| 
 | ||||
| 		$request = array('uri' => 'htpp://www.cakephp.org/'); | ||||
| 		$number = mt_rand(0, 9999999); | ||||
| 		$this->Socket->expects($this->once())->method('connect')->will($this->returnValue(true)); | ||||
| 		$this->Socket->expects($this->any())->method('connect')->will($this->returnValue(true)); | ||||
| 		$serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>Hello, your lucky number is " . $number . "</h1>"; | ||||
| 		$this->Socket->expects($this->at(0))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); | ||||
| 		$this->Socket->expects($this->once())->method('write') | ||||
| 		$this->Socket->expects($this->at(0))->method('write') | ||||
| 			->with("GET / HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n"); | ||||
| 
 | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->onConsecutiveCalls($serverResponse, false)); | ||||
| 
 | ||||
| 		$response = (string)$this->Socket->request($request); | ||||
| 		$this->assertEquals($response, "<h1>Hello, your lucky number is " . $number . "</h1>"); | ||||
| 	} | ||||
|  | @ -634,17 +662,21 @@ class HttpSocketTest extends CakeTestCase { | |||
| 	public function testRequest3() { | ||||
| 		$request = array('uri' => 'htpp://www.cakephp.org/'); | ||||
| 		$serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a cookie test!</h1>"; | ||||
| 		$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); | ||||
| 
 | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->onConsecutiveCalls($serverResponse, false)); | ||||
| 
 | ||||
| 		$this->Socket->connected = true; | ||||
| 		$this->Socket->request($request); | ||||
| 		$result = $this->Socket->response['cookies']; | ||||
| 		$expect = array( | ||||
| 		$expected = array( | ||||
| 			'foo' => array( | ||||
| 				'value' => 'bar' | ||||
| 			) | ||||
| 		); | ||||
| 		$this->assertEquals($expect, $result); | ||||
| 		$this->assertEquals($this->Socket->config['request']['cookies']['www.cakephp.org'], $expect); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 		$this->assertEquals($expected, $this->Socket->config['request']['cookies']['www.cakephp.org']); | ||||
| 		$this->assertFalse($this->Socket->connected); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -665,7 +697,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 				) | ||||
| 			) | ||||
| 		); | ||||
| 		$http = new MockHttpSocketRequests($request); | ||||
| 		$http = $this->getMock('TestHttpSocket', array('read', 'write', 'connect', 'request'), array($request)); | ||||
| 
 | ||||
| 		$expected = array('method' => 'GET', 'uri' => '/_test'); | ||||
| 		$http->expects($this->at(0))->method('request')->with($expected); | ||||
|  | @ -683,9 +715,10 @@ class HttpSocketTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function testRequestWithResource() { | ||||
| 		$serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a test!</h1>"; | ||||
| 		$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); | ||||
| 		$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse)); | ||||
| 
 | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->onConsecutiveCalls($serverResponse, false, $serverResponse, false)); | ||||
| 		$this->Socket->connected = true; | ||||
| 
 | ||||
| 		$f = fopen(TMP . 'download.txt', 'w'); | ||||
|  | @ -716,8 +749,10 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		$this->Socket->config['request']['cookies'] = array(); | ||||
| 
 | ||||
| 		$serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a test!</h1>"; | ||||
| 
 | ||||
| 		$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); | ||||
| 		$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); | ||||
| 
 | ||||
| 		$expected = array('www.cakephp.org' => array('foo' => array('value' => 'bar'))); | ||||
| 		$this->Socket->request('http://www.cakephp.org/'); | ||||
| 		$this->assertEquals($expected, $this->Socket->config['request']['cookies']); | ||||
|  | @ -753,8 +788,9 @@ class HttpSocketTest extends CakeTestCase { | |||
| 	public function testRequestCustomResponse() { | ||||
| 		$this->Socket->connected = true; | ||||
| 		$serverResponse = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>This is a test!</h1>"; | ||||
| 		$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); | ||||
| 		$this->Socket->expects($this->at(2))->method('read')->will($this->returnValue(false)); | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->onConsecutiveCalls($serverResponse, false)); | ||||
| 
 | ||||
| 		$this->Socket->responseClass = 'CustomResponse'; | ||||
| 		$response = $this->Socket->request('http://www.cakephp.org/'); | ||||
|  | @ -763,7 +799,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that redirect urls are urldecoded | ||||
|  * Test that redirect URLs are urldecoded | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -772,7 +808,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 			'uri' => 'http://localhost/oneuri', | ||||
| 			'redirect' => 1 | ||||
| 		); | ||||
| 		$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://i.cmpnet.com%2Ftechonline%2Fpdf%2Fa.pdf=\r\n\r\n"; | ||||
| 		$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://i.cmpnet.com%2Ftechonline%2Fpdf%2Fa+b.pdf=\r\n\r\n"; | ||||
| 		$serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>You have been redirected</h1>"; | ||||
| 
 | ||||
| 		$this->Socket->expects($this->at(1)) | ||||
|  | @ -783,12 +819,14 @@ class HttpSocketTest extends CakeTestCase { | |||
| 			->method('write') | ||||
| 			->with($this->logicalAnd( | ||||
| 				$this->stringContains('Host: i.cmpnet.com'), | ||||
| 				$this->stringContains('GET /techonline/pdf/a.pdf') | ||||
| 				$this->stringContains('GET /techonline/pdf/a+b.pdf') | ||||
| 			)); | ||||
| 
 | ||||
| 		$this->Socket->expects($this->at(4)) | ||||
| 			->method('read') | ||||
| 			->will($this->returnValue($serverResponse2)); | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read')->will($this->returnValue(false)); | ||||
| 
 | ||||
| 		$response = $this->Socket->request($request); | ||||
| 		$this->assertEquals('<h1>You have been redirected</h1>', $response->body()); | ||||
|  | @ -806,8 +844,10 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		); | ||||
| 		$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/anotheruri\r\n\r\n"; | ||||
| 		$serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>You have been redirected</h1>"; | ||||
| 		$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse1)); | ||||
| 		$this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse2)); | ||||
| 
 | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->onConsecutiveCalls($serverResponse1, false, $serverResponse2, false)); | ||||
| 
 | ||||
| 		$response = $this->Socket->request($request); | ||||
| 		$this->assertEquals('<h1>You have been redirected</h1>', $response->body()); | ||||
|  | @ -825,10 +865,12 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		); | ||||
| 		$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/anotheruri\r\n\r\n"; | ||||
| 		$serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n<h1>You have been redirected</h1>"; | ||||
| 		$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse1)); | ||||
| 		$this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse2)); | ||||
| 
 | ||||
| 		$response = $this->Socket->request($request); | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->onConsecutiveCalls($serverResponse1, false, $serverResponse2, false)); | ||||
| 
 | ||||
| 		$this->Socket->request($request); | ||||
| 		$this->assertEquals(1, $this->Socket->request['redirect']); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -844,8 +886,10 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		); | ||||
| 		$serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/oneruri\r\n\r\n"; | ||||
| 		$serverResponse2 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/anotheruri\r\n\r\n"; | ||||
| 		$this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse1)); | ||||
| 		$this->Socket->expects($this->at(4))->method('read')->will($this->returnValue($serverResponse2)); | ||||
| 
 | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->onConsecutiveCalls($serverResponse1, false, $serverResponse2, false)); | ||||
| 
 | ||||
| 		$response = $this->Socket->request($request); | ||||
| 		$this->assertEquals(0, $this->Socket->request['redirect']); | ||||
|  | @ -1031,23 +1075,96 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test the head method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testHead() { | ||||
| 		$this->RequestSocket->reset(); | ||||
| 		$this->RequestSocket->expects($this->at(0)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/')); | ||||
| 
 | ||||
| 		$this->RequestSocket->expects($this->at(1)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=bar')); | ||||
| 
 | ||||
| 		$this->RequestSocket->expects($this->at(2)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=bar')); | ||||
| 
 | ||||
| 		$this->RequestSocket->expects($this->at(3)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/?foo=23&foobar=42')); | ||||
| 
 | ||||
| 		$this->RequestSocket->expects($this->at(4)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'HEAD', 'uri' => 'http://www.google.com/', 'version' => '1.0')); | ||||
| 
 | ||||
| 		$this->RequestSocket->expects($this->at(5)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'HEAD', 'uri' => 'https://secure.example.com/test.php?one=two')); | ||||
| 
 | ||||
| 		$this->RequestSocket->expects($this->at(6)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'HEAD', 'uri' => 'https://example.com/oauth/access?clientid=123&redirect_uri=http%3A%2F%2Fexample.com&code=456')); | ||||
| 
 | ||||
| 		$this->RequestSocket->head('http://www.google.com/'); | ||||
| 		$this->RequestSocket->head('http://www.google.com/', array('foo' => 'bar')); | ||||
| 		$this->RequestSocket->head('http://www.google.com/', 'foo=bar'); | ||||
| 		$this->RequestSocket->head('http://www.google.com/?foo=bar', array('foobar' => '42', 'foo' => '23')); | ||||
| 		$this->RequestSocket->head('http://www.google.com/', null, array('version' => '1.0')); | ||||
| 		$this->RequestSocket->head('https://secure.example.com/test.php', array('one' => 'two')); | ||||
| 		$this->RequestSocket->head('https://example.com/oauth/access', array( | ||||
| 			'clientid' => '123', | ||||
| 			'redirect_uri' => 'http://example.com', | ||||
| 			'code' => 456 | ||||
| 		)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test authentication | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAuth() { | ||||
| 		$socket = new MockHttpSocket(); | ||||
| 		$socket->get('http://mark:secret@example.com/test'); | ||||
| 		$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read')->will($this->returnValue(false)); | ||||
| 
 | ||||
| 		$socket->configAuth(false); | ||||
| 		$socket->get('http://example.com/test'); | ||||
| 		$this->assertFalse(strpos($socket->request['header'], 'Authorization:')); | ||||
| 		$this->Socket->get('http://mark:secret@example.com/test'); | ||||
| 		$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); | ||||
| 
 | ||||
| 		$socket->configAuth('Test', 'mark', 'passwd'); | ||||
| 		$socket->get('http://example.com/test'); | ||||
| 		$this->assertTrue(strpos($socket->request['header'], 'Authorization: Test mark.passwd') !== false); | ||||
| 		$this->Socket->configAuth(false); | ||||
| 		$this->Socket->get('http://example.com/test'); | ||||
| 		$this->assertFalse(strpos($this->Socket->request['header'], 'Authorization:')); | ||||
| 
 | ||||
| 		$this->Socket->configAuth('Test', 'mark', 'passwd'); | ||||
| 		$this->Socket->get('http://example.com/test'); | ||||
| 		$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Test mark.passwd') !== false); | ||||
| 
 | ||||
| 		$this->Socket->configAuth(false); | ||||
| 		$this->Socket->request(array( | ||||
| 			'method' => 'GET', | ||||
| 			'uri' => 'http://example.com/test', | ||||
| 			'auth' => array( | ||||
| 				'method' => 'Basic', | ||||
| 				'user' => 'joel', | ||||
| 				'pass' => 'hunter2' | ||||
| 			) | ||||
| 		)); | ||||
| 		$this->assertEquals($this->Socket->request['auth'], array('Basic' => array('user' => 'joel', 'pass' => 'hunter2'))); | ||||
| 		$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic am9lbDpodW50ZXIy') !== false); | ||||
| 
 | ||||
| 		$this->Socket->configAuth('Basic', 'mark', 'password'); | ||||
| 		$this->Socket->request(array( | ||||
| 			'method' => 'GET', | ||||
| 			'uri' => 'http://example.com/test', | ||||
| 			'header' => array( | ||||
| 				'Authorization' => 'OtherAuth Hi.There' | ||||
| 			) | ||||
| 		)); | ||||
| 		$this->assertPattern('/Authorization: OtherAuth Hi\.There/m', $this->Socket->request['header']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1056,17 +1173,28 @@ class HttpSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testConsecutiveGetResetsAuthCredentials() { | ||||
| 		$socket = new MockHttpSocket(); | ||||
| 		$socket->get('http://mark:secret@example.com/test'); | ||||
| 		$this->assertEquals('mark', $socket->request['uri']['user']); | ||||
| 		$this->assertEquals('secret', $socket->request['uri']['pass']); | ||||
| 		$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read')->will($this->returnValue(false)); | ||||
| 
 | ||||
| 		$socket->get('/test2'); | ||||
| 		$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); | ||||
| 		$this->Socket->get('http://mark:secret@example.com/test'); | ||||
| 		$this->assertEquals('mark', $this->Socket->request['uri']['user']); | ||||
| 		$this->assertEquals('secret', $this->Socket->request['uri']['pass']); | ||||
| 		$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); | ||||
| 
 | ||||
| 		$socket->get('/test3'); | ||||
| 		$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); | ||||
| 		$this->Socket->get('/test2'); | ||||
| 		$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); | ||||
| 
 | ||||
| 		$this->Socket->request(array( | ||||
| 			'method' => 'GET', | ||||
| 			'uri' => 'http://example.com/test', | ||||
| 			'header' => array( | ||||
| 				'Authorization' => 'OtherAuth Hi.There' | ||||
| 			) | ||||
| 		)); | ||||
| 		$this->assertPattern('/Authorization: OtherAuth Hi\.There/m', $this->Socket->request['header']); | ||||
| 
 | ||||
| 		$this->Socket->get('/test3'); | ||||
| 		$this->assertTrue(strpos($this->Socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1117,6 +1245,30 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		$this->RequestSocket->put('http://www.google.com/', null, array('line' => 'Hey Server')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testPatch | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testPatch() { | ||||
| 		$this->RequestSocket->reset(); | ||||
| 		$this->RequestSocket->expects($this->at(0)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'PATCH', 'uri' => 'http://www.google.com/', 'body' => array())); | ||||
| 
 | ||||
| 		$this->RequestSocket->expects($this->at(1)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'PATCH', 'uri' => 'http://www.google.com/', 'body' => array('Foo' => 'bar'))); | ||||
| 
 | ||||
| 		$this->RequestSocket->expects($this->at(2)) | ||||
| 			->method('request') | ||||
| 			->with(array('method' => 'PATCH', 'uri' => 'http://www.google.com/', 'body' => null, 'line' => 'Hey Server')); | ||||
| 
 | ||||
| 		$this->RequestSocket->patch('http://www.google.com/'); | ||||
| 		$this->RequestSocket->patch('http://www.google.com/', array('Foo' => 'bar')); | ||||
| 		$this->RequestSocket->patch('http://www.google.com/', null, array('line' => 'Hey Server')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDelete | ||||
|  * | ||||
|  | @ -1177,9 +1329,6 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		$r = $this->Socket->buildRequestLine($request); | ||||
| 		$this->assertEquals("GET /search?q=socket HTTP/1.1\r\n", $r); | ||||
| 
 | ||||
| 		$r = $this->Socket->buildRequestLine($request, 'CAKE-HTTP/0.1'); | ||||
| 		$this->assertEquals("GET /search?q=socket CAKE-HTTP/0.1\r\n", $r); | ||||
| 
 | ||||
| 		$request = array('method' => 'OPTIONS', 'uri' => '*'); | ||||
| 		$r = $this->Socket->buildRequestLine($request); | ||||
| 		$this->assertEquals("OPTIONS * HTTP/1.1\r\n", $r); | ||||
|  | @ -1191,6 +1340,17 @@ class HttpSocketTest extends CakeTestCase { | |||
| 
 | ||||
| 		$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n"); | ||||
| 		$this->assertEquals("GET * HTTP/1.1\r\n", $r); | ||||
| 
 | ||||
| 		$request = array( | ||||
| 			'version' => '1.0', | ||||
| 			'method' => 'GET', | ||||
| 			'uri' => array( | ||||
| 				'path' => '/search', | ||||
| 				'query' => array('q' => 'socket') | ||||
| 			) | ||||
| 		); | ||||
| 		$r = $this->Socket->buildRequestLine($request); | ||||
| 		$this->assertEquals("GET /search?q=socket HTTP/1.0\r\n", $r); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1200,7 +1360,7 @@ class HttpSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testBadBuildRequestLine() { | ||||
| 		$r = $this->Socket->buildRequestLine('Foo'); | ||||
| 		$this->Socket->buildRequestLine('Foo'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1210,7 +1370,7 @@ class HttpSocketTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testBadBuildRequestLine2() { | ||||
| 		$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n"); | ||||
| 		$this->Socket->buildRequestLine("GET * HTTP/1.1\r\n"); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -1489,8 +1649,8 @@ class HttpSocketTest extends CakeTestCase { | |||
| 					'name' => 'jim', | ||||
| 					'items' => array( | ||||
| 						'personal' => array( | ||||
| 							'book' | ||||
| 							, 'pen' | ||||
| 							'book', | ||||
| 							'pen' | ||||
| 						), | ||||
| 						'ball' | ||||
| 					) | ||||
|  | @ -1560,9 +1720,10 @@ class HttpSocketTest extends CakeTestCase { | |||
| 			'people' => array( | ||||
| 				'value' => 'jim,jack,johnny;', | ||||
| 				'path' => '/accounts' | ||||
| 			) | ||||
| 			), | ||||
| 			'key' => 'value' | ||||
| 		); | ||||
| 		$expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"\r\n"; | ||||
| 		$expect = "Cookie: foo=bar; people=jim,jack,johnny\";\"; key=value\r\n"; | ||||
| 		$result = $this->Socket->buildCookies($cookies); | ||||
| 		$this->assertEquals($expect, $result); | ||||
| 	} | ||||
|  | @ -1576,10 +1737,10 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		$this->Socket->reset(); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'\x22','\x28','\x29','\x3c','\x3e','\x40','\x2c','\x3b','\x3a','\x5c','\x2f','\x5b','\x5d','\x3f','\x3d','\x7b', | ||||
| 			'\x7d','\x20','\x00','\x01','\x02','\x03','\x04','\x05','\x06','\x07','\x08','\x09','\x0a','\x0b','\x0c','\x0d', | ||||
| 			'\x0e','\x0f','\x10','\x11','\x12','\x13','\x14','\x15','\x16','\x17','\x18','\x19','\x1a','\x1b','\x1c','\x1d', | ||||
| 			'\x1e','\x1f','\x7f' | ||||
| 			'\x22', '\x28', '\x29', '\x3c', '\x3e', '\x40', '\x2c', '\x3b', '\x3a', '\x5c', '\x2f', '\x5b', '\x5d', '\x3f', '\x3d', '\x7b', | ||||
| 			'\x7d', '\x20', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', | ||||
| 			'\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', | ||||
| 			'\x1e', '\x1f', '\x7f' | ||||
| 		); | ||||
| 		$r = $this->Socket->tokenEscapeChars(); | ||||
| 		$this->assertEquals($expected, $r); | ||||
|  | @ -1618,7 +1779,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * This tests asserts HttpSocket::reset() resets a HttpSocket instance to it's initial state (before Object::__construct | ||||
|  * This tests asserts HttpSocket::reset() resets a HttpSocket instance to it's initial state (before CakeObject::__construct | ||||
|  * got executed) | ||||
|  * | ||||
|  * @return void | ||||
|  | @ -1642,7 +1803,7 @@ class HttpSocketTest extends CakeTestCase { | |||
| 
 | ||||
| /** | ||||
|  * This tests asserts HttpSocket::reset(false) resets certain HttpSocket properties to their initial state (before | ||||
|  * Object::__construct got executed). | ||||
|  * CakeObject::__construct got executed). | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
|  | @ -1667,4 +1828,63 @@ class HttpSocketTest extends CakeTestCase { | |||
| 		} | ||||
| 		$this->assertEquals(true, $return); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that requests fail when peer verification fails. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testVerifyPeer() { | ||||
| 		$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.'); | ||||
| 		$socket = new HttpSocket(); | ||||
| 		try { | ||||
| 			$socket->get('https://tv.eurosport.com/'); | ||||
| 			$this->markTestSkipped('Found valid certificate, was expecting invalid certificate.'); | ||||
| 		} catch (SocketException $e) { | ||||
| 			$message = $e->getMessage(); | ||||
| 			$this->skipIf(strpos($message, 'Invalid HTTP') !== false, 'Invalid HTTP Response received, skipping.'); | ||||
| 			$this->assertContains('Failed to enable crypto', $message); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Data provider for status codes. | ||||
|  * | ||||
|  * @return array | ||||
|  */ | ||||
| 	public function statusProvider() { | ||||
| 		return array( | ||||
| 			array('HTTP/1.1 200 ', '200'), | ||||
| 			array('HTTP/1.1 200    ', '200'), | ||||
| 			array('HTTP/1.1 200', '200'), | ||||
| 			array('HTTP/1.1 200  OK', '200', 'OK'), | ||||
| 			array('HTTP/1.1 404 Not Found', '404', 'Not Found'), | ||||
| 			array('HTTP/1.1 404    Not Found', '404', 'Not Found'), | ||||
| 		); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test response status parsing | ||||
|  * | ||||
|  * @dataProvider statusProvider | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testResponseStatusParsing($status, $code, $msg = '') { | ||||
| 		$this->Socket->connected = true; | ||||
| 		$serverResponse = $status . "\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\n\r\n<h1>This is a test!</h1>"; | ||||
| 
 | ||||
| 		$this->Socket->expects($this->any()) | ||||
| 			->method('read') | ||||
| 			->will($this->onConsecutiveCalls($serverResponse, false)); | ||||
| 
 | ||||
| 		$response = $this->Socket->request('http://www.cakephp.org/'); | ||||
| 		$this->assertInstanceOf('HttpSocketResponse', $response); | ||||
| 		$expected = array( | ||||
| 			'http-version' => 'HTTP/1.1', | ||||
| 			'code' => $code, | ||||
| 			'reason-phrase' => $msg | ||||
| 		); | ||||
| 		$this->assertEquals($expected, $response['status']); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko