diff --git a/readme.md b/readme.md index c25c36de39..19ad08233e 100644 --- a/readme.md +++ b/readme.md @@ -1610,6 +1610,15 @@ echo $faker->personalIdentityNumber() // '950910-0799' //Since the numbers are different for male and female persons, optionally you can specify gender. echo $faker->personalIdentityNumber('female') // '950910-0781' ``` +### `Faker\Provider\tr_TR\Person` + +```php +tcNo // '55300634882' + +``` ### `Faker\Provider\zh_CN\Payment` diff --git a/src/Faker/Calculator/TCNo.php b/src/Faker/Calculator/TCNo.php new file mode 100644 index 0000000000..392d455241 --- /dev/null +++ b/src/Faker/Calculator/TCNo.php @@ -0,0 +1,52 @@ + $digit) { + if ($index % 2 == 0) { + $evenSum += $digit; + } else { + $oddSum += $digit; + } + } + + $tenthDigit = (7 * $evenSum - $oddSum) % 10; + $eleventhDigit = ($evenSum + $oddSum + $tenthDigit) % 10; + + return $tenthDigit . $eleventhDigit; + } + + /** + * Checks whether an TCNo has a valid checksum + * + * @param string $tcNo + * @return boolean + */ + public static function isValid($tcNo) + { + return self::checksum(substr($tcNo, 0, -2)) === substr($tcNo, -2, 2); + } +} diff --git a/src/Faker/Provider/tr_TR/Person.php b/src/Faker/Provider/tr_TR/Person.php index 2d37d62e28..a937377fba 100644 --- a/src/Faker/Provider/tr_TR/Person.php +++ b/src/Faker/Provider/tr_TR/Person.php @@ -2,6 +2,8 @@ namespace Faker\Provider\tr_TR; +use Faker\Calculator\TCNo; + class Person extends \Faker\Provider\Person { /** @@ -94,4 +96,17 @@ public static function titleFemale() { return static::titleMale(); } + + /** + * National Personal Identity number (tc kimlik no) + * @link https://en.wikipedia.org/wiki/Turkish_Identification_Number + * @return string on format XXXXXXXXXXX + */ + public function tcNo() + { + $randomDigits = static::numerify('#########'); + $checksum = TCNo::checksum($randomDigits); + + return $randomDigits . $checksum; + } } diff --git a/test/Faker/Calculator/TCNoTest.php b/test/Faker/Calculator/TCNoTest.php new file mode 100644 index 0000000000..9e40d79471 --- /dev/null +++ b/test/Faker/Calculator/TCNoTest.php @@ -0,0 +1,54 @@ +assertEquals($checksum, TCNo::checksum($tcNo), $tcNo); + } + + public function validatorProvider() + { + return array( + array('22978160678', true), + array('26480045324', true), + array('47278360658', true), + array('34285002510', true), + array('19874561012', true), + + array('11111111111', false), + array('11234567899', false), + ); + } + + /** + * @dataProvider validatorProvider + * @param $tcNo + * @param $isValid + */ + public function testIsValid($tcNo, $isValid) + { + $this->assertEquals($isValid, TCNo::isValid($tcNo), $tcNo); + } +} diff --git a/test/Faker/Provider/tr_TR/CompanyTest.php b/test/Faker/Provider/tr_TR/CompanyTest.php new file mode 100644 index 0000000000..badf905fd1 --- /dev/null +++ b/test/Faker/Provider/tr_TR/CompanyTest.php @@ -0,0 +1,28 @@ +addProvider(new Company($faker)); + $this->faker = $faker; + } + + public function testCompany() + { + $company = $this->faker->companyField; + $this->assertNotNull($company); + } +} diff --git a/test/Faker/Provider/tr_TR/PaymentTest.php b/test/Faker/Provider/tr_TR/PaymentTest.php new file mode 100644 index 0000000000..7c8ffdb2ad --- /dev/null +++ b/test/Faker/Provider/tr_TR/PaymentTest.php @@ -0,0 +1,29 @@ +addProvider(new Payment($faker)); + $this->faker = $faker; + } + + public function testBankAccountNumber() + { + $accNo = $this->faker->bankAccountNumber; + $this->assertEquals(substr($accNo, 0, 2), 'TR'); + $this->assertEquals(26, strlen($accNo)); + } +} diff --git a/test/Faker/Provider/tr_TR/PersonTest.php b/test/Faker/Provider/tr_TR/PersonTest.php new file mode 100644 index 0000000000..ad9db9c7fd --- /dev/null +++ b/test/Faker/Provider/tr_TR/PersonTest.php @@ -0,0 +1,34 @@ +addProvider(new Person($faker)); + $this->faker = $faker; + } + + public function testTCNo() + { + for ($i = 0; $i < 100; $i++) { + $number = $this->faker->tcNo; + + $this->assertEquals(11, strlen($number)); + $this->assertTrue(TCNo::isValid($number)); + } + } +} diff --git a/test/Faker/Provider/tr_TR/PhoneNumberTest.php b/test/Faker/Provider/tr_TR/PhoneNumberTest.php new file mode 100644 index 0000000000..0971d04b8e --- /dev/null +++ b/test/Faker/Provider/tr_TR/PhoneNumberTest.php @@ -0,0 +1,34 @@ +addProvider(new PhoneNumber($faker)); + $this->faker = $faker; + } + + public function testPhoneNumber() + { + for ($i = 0; $i < 100; $i++) { + $number = $this->faker->phoneNumber; + $baseNumber = preg_replace('/ *x.*$/', '', $number); // Remove possible extension + $digits = array_values(array_filter(str_split($baseNumber), 'ctype_digit')); + + $this->assertGreaterThan(10, count($digits)); + } + } +}