| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Azine\EmailUpdateConfirmationBundle\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Azine\EmailUpdateConfirmationBundle\Services\EmailEncryption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Validator\ConstraintViolationList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\Validator\Validator\ValidatorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class EmailEncryptionTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     /** @var ValidatorInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     private $emailValidator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** @var ConstraintViolationList */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     private $constraintViolationList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     protected function setUp() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->emailValidator = $this->getMockBuilder('Symfony\Component\Validator\Validator\RecursiveValidator')->disableOriginalConstructor()->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->constraintViolationList = new ConstraintViolationList(array($this->getMockBuilder('Symfony\Component\Validator\ConstraintViolation')->disableOriginalConstructor()->getMock())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @expectedException \InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public function testIntegerIsSetInsteadOfEmailString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $emailEncryption = new EmailEncryption($this->emailValidator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $emailEncryption->setEmail(123); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @expectedException \InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function testIntegerIsSetInsteadOfConfirmationTokenString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $emailEncryption = new EmailEncryption($this->emailValidator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $emailEncryption->setUserConfirmationToken(123); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @expectedException \InvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function testNullIsSetInsteadOfConfirmationTokenString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $emailEncryption = new EmailEncryption($this->emailValidator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $emailEncryption->setUserConfirmationToken(null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function testGetConfirmationToken() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->constraintViolationList->remove(0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $emailEncryption = new EmailEncryption($this->emailValidator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $emailEncryption->setUserConfirmationToken('test_token'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $confirmationToken = $emailEncryption->getConfirmationToken(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $expectedConfirmationToken = pack('H*', hash('sha256', 'test_token')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->assertSame($expectedConfirmationToken, $confirmationToken); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @expectedException \InvalidArgumentException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |     public function testGetConfirmationTokenIfUserConfirmationTokenIsNotSet() | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |         $emailEncryption = new EmailEncryption($this->emailValidator); | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |         $emailEncryption->getConfirmationToken(); | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 68 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |  |