|
4 | 4 |
|
5 | 5 | use CodeIgniter\Entity\Exceptions\CastException; |
6 | 6 | use CodeIgniter\I18n\Time; |
| 7 | +use CodeIgniter\HTTP\URI; |
7 | 8 | use CodeIgniter\Test\CIUnitTestCase; |
8 | 9 | use CodeIgniter\Test\ReflectionHelper; |
9 | 10 | use DateTime; |
@@ -497,6 +498,32 @@ public function testCastNullable() |
497 | 498 |
|
498 | 499 | //-------------------------------------------------------------------- |
499 | 500 |
|
| 501 | + public function testCastURI() |
| 502 | + { |
| 503 | + $entity = $this->getCastEntity(); |
| 504 | + |
| 505 | + $data = 'https://codeigniter.com/banana'; |
| 506 | + |
| 507 | + $entity->thirteenth = $data; |
| 508 | + $this->assertInstanceOf(URI::class, $entity->thirteenth); |
| 509 | + $this->assertSame($data, (string) $entity->thirteenth); |
| 510 | + $this->assertSame('/banana', $entity->thirteenth->getPath()); |
| 511 | + } |
| 512 | + |
| 513 | + public function testURICastURI() |
| 514 | + { |
| 515 | + $entity = $this->getCastEntity(); |
| 516 | + |
| 517 | + $data = 'https://codeigniter.com/banana'; |
| 518 | + |
| 519 | + $entity->thirteenth = new URI($data); |
| 520 | + $this->assertInstanceOf(URI::class, $entity->thirteenth); |
| 521 | + $this->assertSame($data, (string) $entity->thirteenth); |
| 522 | + $this->assertSame('/banana', $entity->thirteenth->getPath()); |
| 523 | + } |
| 524 | + |
| 525 | + //-------------------------------------------------------------------- |
| 526 | + |
500 | 527 | public function testCastAsJSON() |
501 | 528 | { |
502 | 529 | $entity = $this->getCastEntity(); |
@@ -1050,49 +1077,52 @@ protected function getCastEntity($data = null) : Entity |
1050 | 1077 | return new class($data) extends Entity |
1051 | 1078 | { |
1052 | 1079 | protected $attributes = [ |
1053 | | - 'first' => null, |
1054 | | - 'second' => null, |
1055 | | - 'third' => null, |
1056 | | - 'fourth' => null, |
1057 | | - 'fifth' => null, |
1058 | | - 'sixth' => null, |
1059 | | - 'seventh' => null, |
1060 | | - 'eighth' => null, |
1061 | | - 'ninth' => null, |
1062 | | - 'tenth' => null, |
1063 | | - 'eleventh' => null, |
1064 | | - 'twelfth' => null, |
| 1080 | + 'first' => null, |
| 1081 | + 'second' => null, |
| 1082 | + 'third' => null, |
| 1083 | + 'fourth' => null, |
| 1084 | + 'fifth' => null, |
| 1085 | + 'sixth' => null, |
| 1086 | + 'seventh' => null, |
| 1087 | + 'eighth' => null, |
| 1088 | + 'ninth' => null, |
| 1089 | + 'tenth' => null, |
| 1090 | + 'eleventh' => null, |
| 1091 | + 'twelfth' => null, |
| 1092 | + 'thirteenth' => null, |
1065 | 1093 | ]; |
1066 | 1094 |
|
1067 | 1095 | protected $_original = [ |
1068 | | - 'first' => null, |
1069 | | - 'second' => null, |
1070 | | - 'third' => null, |
1071 | | - 'fourth' => null, |
1072 | | - 'fifth' => null, |
1073 | | - 'sixth' => null, |
1074 | | - 'seventh' => null, |
1075 | | - 'eighth' => null, |
1076 | | - 'ninth' => null, |
1077 | | - 'tenth' => null, |
1078 | | - 'eleventh' => null, |
1079 | | - 'twelfth' => null, |
| 1096 | + 'first' => null, |
| 1097 | + 'second' => null, |
| 1098 | + 'third' => null, |
| 1099 | + 'fourth' => null, |
| 1100 | + 'fifth' => null, |
| 1101 | + 'sixth' => null, |
| 1102 | + 'seventh' => null, |
| 1103 | + 'eighth' => null, |
| 1104 | + 'ninth' => null, |
| 1105 | + 'tenth' => null, |
| 1106 | + 'eleventh' => null, |
| 1107 | + 'twelfth' => null, |
| 1108 | + 'thirteenth' => null, |
1080 | 1109 | ]; |
1081 | 1110 |
|
1082 | 1111 | // 'bar' is db column, 'foo' is internal representation |
1083 | 1112 | protected $casts = [ |
1084 | | - 'first' => 'integer', |
1085 | | - 'second' => 'float', |
1086 | | - 'third' => 'double', |
1087 | | - 'fourth' => 'string', |
1088 | | - 'fifth' => 'boolean', |
1089 | | - 'sixth' => 'object', |
1090 | | - 'seventh' => 'array', |
1091 | | - 'eighth' => 'datetime', |
1092 | | - 'ninth' => 'timestamp', |
1093 | | - 'tenth' => 'json', |
1094 | | - 'eleventh' => 'json-array', |
1095 | | - 'twelfth' => 'csv', |
| 1113 | + 'first' => 'integer', |
| 1114 | + 'second' => 'float', |
| 1115 | + 'third' => 'double', |
| 1116 | + 'fourth' => 'string', |
| 1117 | + 'fifth' => 'boolean', |
| 1118 | + 'sixth' => 'object', |
| 1119 | + 'seventh' => 'array', |
| 1120 | + 'eighth' => 'datetime', |
| 1121 | + 'ninth' => 'timestamp', |
| 1122 | + 'tenth' => 'json', |
| 1123 | + 'eleventh' => 'json-array', |
| 1124 | + 'twelfth' => 'csv', |
| 1125 | + 'thirteenth' => 'uri', |
1096 | 1126 | ]; |
1097 | 1127 |
|
1098 | 1128 | public function setSeventh($seventh) |
|
0 commit comments