| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace LeKoala\Tin\Test; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use LeKoala\Tin\TINValid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Credits to czechphp for real test data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @link https://github.com/czechphp/national-identification-number-validator/blob/master/Tests/NationalIdentificationNumberValidatorTest.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class CZAlgorithmTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @dataProvider validProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * @param $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public function testValid(string $value, $message) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->assertTrue(TINValid::checkTIN('cz', $value), $message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function validProvider() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             ['000101999', 'spec1'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ['000101999C', 'spec2'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             ['103224/0000', 'male born 2010-12-24 with +20'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             ['108224/0016', 'female born 2010-12-24 with +20'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ['901224/0006', 'male born 1990-12-24'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             ['906224/0011', 'female born 1990-12-24'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ['401224/001', 'male born 1940-12-24'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ['406224/002', 'female born 1940-12-24'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     public function testInvalidLength() | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         $this->assertFalse( | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |             TINValid::checkTIN('cz', '01224/0006') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     public function testInvalidCharacter() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             TINValid::checkTIN('cz', '90A224/0006') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     public function testInvalidMonth() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             TINValid::checkTIN('cz', '901524/0006') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     // public function testPlus20InMonthInWrongYear() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     //     $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     //         TINValid::checkTIN('cz', '902124/0003') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     //     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     // public function testPlus20InMonthInSeeminglyCorrectYearDifferentiatedByMissingModulo() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     //     $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     //         TINValid::checkTIN('cz', '052124/001') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     //     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     public function testDayShouldNotBeZero() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             TINValid::checkTIN('cz', '501200/001') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     public function testDayShouldNotBeGreaterThan31() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             TINValid::checkTIN('cz', '500132/001') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     // public function testAfterYear53ModuloIsRequired() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     //     $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     //         TINValid::checkTIN('cz', '540101/001') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     //     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     // public function testWithoutModuloSequenceShouldNotBeZero() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     //     $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     //         TINValid::checkTIN('cz', '500101/000') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     //     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     // public function testIncorrectModulo() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     //     $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     //         TINValid::checkTIN('cz', '540101/0008') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     //     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     // } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     // public function testIncorrectModuloIsCorrectIfItShouldBe10() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     //     $this->assertFalse( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     //         TINValid::checkTIN('cz', '540101/0110') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     //     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     // } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 119 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |  |