| 
									
										
										
										
											2012-11-22 16:24:21 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Mockery as m; | 
					
						
							| 
									
										
										
										
											2013-02-11 14:02:14 +00:00
										 |  |  | use JacobKiers\OAuth\SignatureMethod\PlainText; | 
					
						
							| 
									
										
										
										
											2012-11-22 16:24:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class PlainTextTest extends PHPUnit_Framework_TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function tearDown() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m::close(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSignatureName() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $plaintext = $this->getSignatureMethod(); | 
					
						
							|  |  |  |         $this->assertEquals('PLAINTEXT', $plaintext->getName()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testBuildSignatureWithoutToken() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Create instance of class to test
 | 
					
						
							|  |  |  |         $plaintext = $this->getSignatureMethod(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Get mock objects
 | 
					
						
							|  |  |  |         $request = $this->getRequest(); | 
					
						
							| 
									
										
										
										
											2013-02-11 14:02:14 +00:00
										 |  |  |         $client = $this->getConsumer(); | 
					
						
							| 
									
										
										
										
											2012-11-22 16:24:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Run method being tested
 | 
					
						
							|  |  |  |         $signature = $plaintext->buildSignature($request, $client); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Check results
 | 
					
						
							|  |  |  |         $this->assertEquals('secret&', $signature); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testBuildSignatureWithToken() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Create instance of class to test
 | 
					
						
							|  |  |  |         $plaintext = $this->getSignatureMethod(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Get mock objects
 | 
					
						
							|  |  |  |         $request = $this->getRequest(); | 
					
						
							| 
									
										
										
										
											2013-02-11 14:02:14 +00:00
										 |  |  |         $client = $this->getConsumer(); | 
					
						
							| 
									
										
										
										
											2012-11-22 16:24:21 +00:00
										 |  |  |         $token = $this->getToken(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Run method being tested
 | 
					
						
							|  |  |  |         $signature = $plaintext->buildSignature($request, $client, $token); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Check results
 | 
					
						
							|  |  |  |         $this->assertEquals('secret&token_secret', $signature); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private function getSignatureMethod() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return new PlainText; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private function getRequest() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-02-11 14:02:14 +00:00
										 |  |  |         return m::mock('JacobKiers\OAuth\Request\Request'); | 
					
						
							| 
									
										
										
										
											2012-11-22 16:24:21 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-11 14:02:14 +00:00
										 |  |  |     private function getConsumer() | 
					
						
							| 
									
										
										
										
											2012-11-22 16:24:21 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-02-11 14:02:14 +00:00
										 |  |  |         return m::mock('JacobKiers\OAuth\Consumer\Consumer', function ($mock) { | 
					
						
							| 
									
										
										
										
											2012-11-22 16:24:21 +00:00
										 |  |  |             $mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private function getToken() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-02-11 14:02:14 +00:00
										 |  |  |         return m::mock('JacobKiers\OAuth\Token\Token', function ($mock) { | 
					
						
							| 
									
										
										
										
											2012-11-22 16:24:21 +00:00
										 |  |  |             $mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |