Skip to content

Commit 8d3fbdb

Browse files
committed
Merge pull request #97 from cakephp/more-postal
Add postal validation for Croatia.
2 parents d0bbc3c + 3d809de commit 8d3fbdb

File tree

6 files changed

+148
-18
lines changed

6 files changed

+148
-18
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ You can also access the localized validators any time you would call `Validation
6161
}
6262
```
6363

64-
## Po files
64+
## PO files
6565

66-
This plugin also houses translations for the client-facing translated strings in the core (the cake domain). to use these files link or copy them
67-
into their expected location: `APP/locale/<locale>/LC_MESSAGES/cake.po`
66+
This plugin also houses translations for the client-facing translated strings in the core (the `cake` domain). to use these files link or copy them
67+
into their expected location: `APP/Locale/<locale>/LC_MESSAGES/cake.po`
6868

6969
## LC_TIME files
7070

7171
This plugin also houses POSIX compliant LC_TIME files which are used for translating
7272
time related string of LC_TIME domain. To use these files link or copy them into
73-
their expected location: `APP/locale/<locale>/LC_TIME`.
73+
their expected location: `APP/Locale/<locale>/LC_TIME`.
7474

7575
## Migration Guide
7676

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Slovak Localized Validation class test case
4+
*
5+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7+
*
8+
* Licensed under The MIT License
9+
* Redistributions of files must retain the above copyright notice.
10+
*
11+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
12+
* @link http://cakephp.org
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
App::uses('HrValidation', 'Localized.Validation');
16+
17+
/**
18+
* HrValidationTest
19+
*
20+
*/
21+
class HrValidationTest extends CakeTestCase {
22+
23+
/**
24+
* test the postal method of HrValidation
25+
*
26+
* @return void
27+
*/
28+
public function testPostal() {
29+
$this->assertTrue(HrValidation::postal('25616'));
30+
$this->assertFalse(HrValidation::postal('0989'));
31+
}
32+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Indonesian Localized Validation class test case
4+
*
5+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7+
*
8+
* Licensed under The MIT License
9+
* Redistributions of files must retain the above copyright notice.
10+
*
11+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
12+
* @link http://cakephp.org
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
App::uses('IdValidation', 'Localized.Validation');
16+
17+
/**
18+
* Indonesian Validation Test Case
19+
*/
20+
class IdValidationTest extends CakeTestCase {
21+
22+
/**
23+
* Test the mobile method of IdValidation
24+
*
25+
* @return void
26+
*/
27+
public function testMobile() {
28+
$this->assertTrue(IdValidation::mobile('08125985608'));
29+
$this->assertFalse(IdValidation::mobile('8125985608'));
30+
}
31+
32+
/**
33+
* Test the postal method of IdValidation
34+
*
35+
* @return void
36+
*/
37+
public function testPostal() {
38+
$this->assertTrue(IdValidation::postal('15000'));
39+
$this->assertFalse(IdValidation::postal('00091'));
40+
}
41+
42+
}

Test/Case/Validation/RsValidationTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ class RsValidationTest extends CakeTestCase {
2626
*
2727
* @return void
2828
*/
29-
public function testJMBG() {
30-
$this->assertTrue(RsValidation::jmbg('1707017170007'));
31-
$this->assertFalse(RsValidation::jmbg('1707017170008'));
32-
$this->assertFalse(RsValidation::jmbg('170701717000'));
33-
$this->assertFalse(RsValidation::jmbg('A707017170007'));
29+
public function testPersonId() {
30+
$this->assertTrue(RsValidation::personId('1707017170007'));
31+
$this->assertFalse(RsValidation::personId('1707017170008'));
32+
$this->assertFalse(RsValidation::personId('170701717000'));
33+
$this->assertFalse(RsValidation::personId('A707017170007'));
3434
}
3535

3636
/**
3737
* test the postal_number method of RsValidation
3838
*
3939
* @return void
4040
*/
41-
public function testPostalNumber() {
42-
$this->assertTrue(RsValidation::postal_number('11090'));
43-
$this->assertFalse(RsValidation::postal_number('111000'));
44-
$this->assertFalse(RsValidation::postal_number('A1100'));
41+
public function testPostal() {
42+
$this->assertTrue(RsValidation::postal('11090'));
43+
$this->assertFalse(RsValidation::postal('111000'));
44+
$this->assertFalse(RsValidation::postal('A1100'));
4545
}
4646

4747
/**
@@ -50,8 +50,8 @@ public function testPostalNumber() {
5050
* @return void
5151
*/
5252
public function testAddressCode() {
53-
$this->assertTrue(RsValidation::address_code('122407'));
54-
$this->assertFalse(RsValidation::address_code('11090'));
55-
$this->assertFalse(RsValidation::address_code('A11090'));
53+
$this->assertTrue(RsValidation::addressCode('122407'));
54+
$this->assertFalse(RsValidation::addressCode('11090'));
55+
$this->assertFalse(RsValidation::addressCode('A11090'));
5656
}
5757
}

Validation/HrValidation.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Localized Validation class. Handles localized validation for Croatia.
4+
*
5+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
6+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7+
*
8+
* Licensed under The MIT License
9+
* Redistributions of files must retain the above copyright notice.
10+
*
11+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
12+
* @link http://cakephp.org
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
App::uses('LocalizedValidation', 'Localized.Validation');
16+
17+
/**
18+
* HrValidation
19+
*
20+
*/
21+
class HrValidation extends LocalizedValidation {
22+
23+
/**
24+
* Checks a postal code for Croatia.
25+
*
26+
* @param string $check The value to check.
27+
* @return bool Success.
28+
*/
29+
public static function postal($check) {
30+
$pattern = '/^\d{5}$/';
31+
return (bool)preg_match($pattern, $check);
32+
}
33+
34+
/**
35+
* Checks a phone number.
36+
*
37+
* @param string $check The value to check.
38+
* @return bool Success.
39+
* @throws NotImplementedException
40+
*/
41+
public static function phone($check) {
42+
throw new NotImplementedException('Validation method not implemented yet.');
43+
}
44+
45+
/**
46+
* Checks a country specific identification number.
47+
*
48+
* @param string $check The value to check.
49+
* @return bool Success.
50+
* @throws NotImplementedException
51+
*/
52+
public static function personId($check) {
53+
throw new NotImplementedException('Validation method not implemented yet.');
54+
}
55+
56+
}

Validation/IdValidation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class IdValidation extends LocalizedValidation {
2929
*/
3030
public static function postal($check) {
3131
$pattern = '/[1-9][0-9]{4}/';
32-
return preg_match($pattern, $check);
32+
return (bool)preg_match($pattern, $check);
3333
}
3434

3535
/**
@@ -40,7 +40,7 @@ public static function postal($check) {
4040
*/
4141
public static function mobile($check) {
4242
$pattern = '/(^0|^62|\+62)(8[0-9]{8,10})$/';
43-
return preg_match($pattern, $check);
43+
return (bool)preg_match($pattern, $check);
4444
}
4545

4646
/**

0 commit comments

Comments
 (0)