first standalone plugin commit

This commit is contained in:
2025-11-18 00:43:34 -08:00
commit 5dc7aa87cd
86 changed files with 86844 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* AddressesFixture
*/
class AddressesFixture extends TestFixture
{
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => 1,
'address_name' => 'Apple Headquarters',
'contact_name' => 'Steve Jobs',
'address_line1' => '1 Apple Park Way',
'address_line2' => null,
'city' => 'San Francisco',
'city_id' => 125809,
'state' => 'California',
'state_id' => 1416,
'postal_code' => '95014',
'country' => 'United States',
'country_id' => 233,
'phone_number' => 'Lorem ipsum dolor sit a',
'email' => 'test@test.com',
'notes' => 'Lorem ipsum dolor sit amet, aliquet feugiat. Convallis morbi fringilla gravida, phasellus feugiat dapibus velit nunc, pulvinar eget sollicitudin venenatis cum nullam, vivamus ut a sed, mollitia lectus. Nulla vestibulum massa neque ut et, id hendrerit sit, feugiat in taciti enim proin nibh, tempor dignissim, rhoncus duis vestibulum nunc mattis convallis.',
],
];
parent::init();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,344 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
use PhpCollective\DecimalObject\Decimal;
use ReflectionClass;
/**
* CountriesFixture
*/
class CountriesFixture extends TestFixture
{
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => 25,
'name' => 'Bermuda',
'iso3' => 'BMU',
'numeric_code' => '060',
'iso2' => 'BM',
'phonecode' => '+1-441',
'capital' => 'Hamilton',
'currency' => 'BMD',
'currency_name' => 'Bermudian dollar',
'currency_symbol' => '$',
'tld' => '.bm',
'native' => 'Bermuda',
'region' => 'Americas',
'region_id' => 2,
'subregion' => 'Northern America',
'subregion_id' => 6,
'nationality' => 'Bermudian, Bermudan',
'timezones' => '[{"zoneName":"Atlantic/Bermuda","gmtOffset":-14400,"gmtOffsetName":"UTC-04:00","abbreviation":"AST","tzName":"Atlantic Standard Time"}]',
'translations' => '{"kr":"버뮤다","pt-BR":"Bermudas","pt":"Bermudas","nl":"Bermuda","hr":"Bermudi","fa":"برمودا","de":"Bermuda","es":"Bermudas","fr":"Bermudes","ja":"バミューダ","it":"Bermuda","cn":"百慕大","tr":"Bermuda"}',
'latitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '32';
$this->fractionalPart = '33333333';
$this->negative = false;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'longitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '64';
$this->fractionalPart = '75000000';
$this->negative = true;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'emoji' => '🇧🇲',
'emojiU' => 'U+1F1E7 U+1F1F2',
'created_at' => '2018-07-21 16:11:03',
'updated_at' => '2023-08-09 06:04:58',
'flag' => true,
'wikiDataId' => null,
],
[
'id' => 39,
'name' => 'Canada',
'iso3' => 'CAN',
'numeric_code' => '124',
'iso2' => 'CA',
'phonecode' => '1',
'capital' => 'Ottawa',
'currency' => 'CAD',
'currency_name' => 'Canadian dollar',
'currency_symbol' => '$',
'tld' => '.ca',
'native' => 'Canada',
'region' => 'Americas',
'region_id' => 2,
'subregion' => 'Northern America',
'subregion_id' => 6,
'nationality' => 'Canadian',
'timezones' => '[{"zoneName":"America/Atikokan","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America)"},{"zoneName":"America/Blanc-Sablon","gmtOffset":-14400,"gmtOffsetName":"UTC-04:00","abbreviation":"AST","tzName":"Atlantic Standard Time"},{"zoneName":"America/Cambridge_Bay","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America)"},{"zoneName":"America/Creston","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America)"},{"zoneName":"America/Dawson","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America)"},{"zoneName":"America/Dawson_Creek","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America)"},{"zoneName":"America/Edmonton","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America)"},{"zoneName":"America/Fort_Nelson","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America)"},{"zoneName":"America/Glace_Bay","gmtOffset":-14400,"gmtOffsetName":"UTC-04:00","abbreviation":"AST","tzName":"Atlantic Standard Time"},{"zoneName":"America/Goose_Bay","gmtOffset":-14400,"gmtOffsetName":"UTC-04:00","abbreviation":"AST","tzName":"Atlantic Standard Time"},{"zoneName":"America/Halifax","gmtOffset":-14400,"gmtOffsetName":"UTC-04:00","abbreviation":"AST","tzName":"Atlantic Standard Time"},{"zoneName":"America/Inuvik","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America"},{"zoneName":"America/Iqaluit","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Moncton","gmtOffset":-14400,"gmtOffsetName":"UTC-04:00","abbreviation":"AST","tzName":"Atlantic Standard Time"},{"zoneName":"America/Nipigon","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Pangnirtung","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Rainy_River","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Rankin_Inlet","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Regina","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Resolute","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/St_Johns","gmtOffset":-12600,"gmtOffsetName":"UTC-03:30","abbreviation":"NST","tzName":"Newfoundland Standard Time"},{"zoneName":"America/Swift_Current","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Thunder_Bay","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Toronto","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Vancouver","gmtOffset":-28800,"gmtOffsetName":"UTC-08:00","abbreviation":"PST","tzName":"Pacific Standard Time (North America"},{"zoneName":"America/Whitehorse","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America"},{"zoneName":"America/Winnipeg","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Yellowknife","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America"}]',
'translations' => '{"kr":"캐나다","pt-BR":"Canadá","pt":"Canadá","nl":"Canada","hr":"Kanada","fa":"کانادا","de":"Kanada","es":"Canadá","fr":"Canada","ja":"カナダ","it":"Canada","cn":"加拿大","tr":"Kanada"}',
'latitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '60';
$this->fractionalPart = '00000000';
$this->negative = false;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'longitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '95';
$this->fractionalPart = '00000000';
$this->negative = true;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'emoji' => '🇨🇦',
'emojiU' => 'U+1F1E8 U+1F1E6',
'created_at' => '2018-07-21 16:11:03',
'updated_at' => '2023-08-09 06:04:58',
'flag' => true,
'wikiDataId' => 'Q16',
],
[
'id' => 86,
'name' => 'Greenland',
'iso3' => 'GRL',
'numeric_code' => '304',
'iso2' => 'GL',
'phonecode' => '299',
'capital' => 'Nuuk',
'currency' => 'DKK',
'currency_name' => 'Danish krone',
'currency_symbol' => 'Kr.',
'tld' => '.gl',
'native' => 'Kalaallit Nunaat',
'region' => 'Americas',
'region_id' => 2,
'subregion' => 'Northern America',
'subregion_id' => 6,
'nationality' => 'Greenlandic',
'timezones' => '[{"zoneName":"America/Danmarkshavn","gmtOffset":0,"gmtOffsetName":"UTC±00","abbreviation":"GMT","tzName":"Greenwich Mean Time"},{"zoneName":"America/Nuuk","gmtOffset":-10800,"gmtOffsetName":"UTC-03:00","abbreviation":"WGT","tzName":"West Greenland Time"},{"zoneName":"America/Scoresbysund","gmtOffset":-3600,"gmtOffsetName":"UTC-01:00","abbreviation":"EGT","tzName":"Eastern Greenland Time"},{"zoneName":"America/Thule","gmtOffset":-14400,"gmtOffsetName":"UTC-04:00","abbreviation":"AST","tzName":"Atlantic Standard Time"}]',
'translations' => '{"kr":"그린란드","pt-BR":"Groelândia","pt":"Gronelândia","nl":"Groenland","hr":"Grenland","fa":"گرینلند","de":"Grönland","es":"Groenlandia","fr":"Groenland","ja":"グリーンランド","it":"Groenlandia","cn":"格陵兰岛","tr":"Grönland"}',
'latitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '72';
$this->fractionalPart = '00000000';
$this->negative = false;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'longitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '40';
$this->fractionalPart = '00000000';
$this->negative = true;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'emoji' => '🇬🇱',
'emojiU' => 'U+1F1EC U+1F1F1',
'created_at' => '2018-07-21 16:11:03',
'updated_at' => '2023-08-09 06:04:58',
'flag' => true,
'wikiDataId' => null,
],
[
'id' => 187,
'name' => 'Saint Pierre and Miquelon',
'iso3' => 'SPM',
'numeric_code' => '666',
'iso2' => 'PM',
'phonecode' => '508',
'capital' => 'Saint-Pierre',
'currency' => 'EUR',
'currency_name' => 'Euro',
'currency_symbol' => '€',
'tld' => '.pm',
'native' => 'Saint-Pierre-et-Miquelon',
'region' => 'Americas',
'region_id' => 2,
'subregion' => 'Northern America',
'subregion_id' => 6,
'nationality' => 'Saint-Pierrais or Miquelonnais',
'timezones' => '[{"zoneName":"America/Miquelon","gmtOffset":-10800,"gmtOffsetName":"UTC-03:00","abbreviation":"PMDT","tzName":"Pierre & Miquelon Daylight Time"}]',
'translations' => '{"kr":"생피에르 미클롱","pt-BR":"Saint-Pierre e Miquelon","pt":"São Pedro e Miquelon","nl":"Saint Pierre en Miquelon","hr":"Sveti Petar i Mikelon","fa":"سن پیر و میکلن","de":"Saint-Pierre und Miquelon","es":"San Pedro y Miquelón","fr":"Saint-Pierre-et-Miquelon","ja":"サンピエール島・ミクロン島","it":"Saint-Pierre e Miquelon","cn":"圣皮埃尔和密克隆","tr":"Saint Pierre Ve Miquelon"}',
'latitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '46';
$this->fractionalPart = '83333333';
$this->negative = false;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'longitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '56';
$this->fractionalPart = '33333333';
$this->negative = true;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'emoji' => '🇵🇲',
'emojiU' => 'U+1F1F5 U+1F1F2',
'created_at' => '2018-07-21 16:11:03',
'updated_at' => '2023-08-10 04:23:19',
'flag' => true,
'wikiDataId' => null,
],
[
'id' => 233,
'name' => 'United States',
'iso3' => 'USA',
'numeric_code' => '840',
'iso2' => 'US',
'phonecode' => '1',
'capital' => 'Washington',
'currency' => 'USD',
'currency_name' => 'United States dollar',
'currency_symbol' => '$',
'tld' => '.us',
'native' => 'United States',
'region' => 'Americas',
'region_id' => 2,
'subregion' => 'Northern America',
'subregion_id' => 6,
'nationality' => 'American',
'timezones' => '[{"zoneName":"America/Adak","gmtOffset":-36000,"gmtOffsetName":"UTC-10:00","abbreviation":"HST","tzName":"HawaiiAleutian Standard Time"},{"zoneName":"America/Anchorage","gmtOffset":-32400,"gmtOffsetName":"UTC-09:00","abbreviation":"AKST","tzName":"Alaska Standard Time"},{"zoneName":"America/Boise","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America"},{"zoneName":"America/Chicago","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Denver","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America"},{"zoneName":"America/Detroit","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Indiana/Indianapolis","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Indiana/Knox","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Indiana/Marengo","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Indiana/Petersburg","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Indiana/Tell_City","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Indiana/Vevay","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Indiana/Vincennes","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Indiana/Winamac","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Juneau","gmtOffset":-32400,"gmtOffsetName":"UTC-09:00","abbreviation":"AKST","tzName":"Alaska Standard Time"},{"zoneName":"America/Kentucky/Louisville","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Kentucky/Monticello","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Los_Angeles","gmtOffset":-28800,"gmtOffsetName":"UTC-08:00","abbreviation":"PST","tzName":"Pacific Standard Time (North America"},{"zoneName":"America/Menominee","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Metlakatla","gmtOffset":-32400,"gmtOffsetName":"UTC-09:00","abbreviation":"AKST","tzName":"Alaska Standard Time"},{"zoneName":"America/New_York","gmtOffset":-18000,"gmtOffsetName":"UTC-05:00","abbreviation":"EST","tzName":"Eastern Standard Time (North America"},{"zoneName":"America/Nome","gmtOffset":-32400,"gmtOffsetName":"UTC-09:00","abbreviation":"AKST","tzName":"Alaska Standard Time"},{"zoneName":"America/North_Dakota/Beulah","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/North_Dakota/Center","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/North_Dakota/New_Salem","gmtOffset":-21600,"gmtOffsetName":"UTC-06:00","abbreviation":"CST","tzName":"Central Standard Time (North America"},{"zoneName":"America/Phoenix","gmtOffset":-25200,"gmtOffsetName":"UTC-07:00","abbreviation":"MST","tzName":"Mountain Standard Time (North America"},{"zoneName":"America/Sitka","gmtOffset":-32400,"gmtOffsetName":"UTC-09:00","abbreviation":"AKST","tzName":"Alaska Standard Time"},{"zoneName":"America/Yakutat","gmtOffset":-32400,"gmtOffsetName":"UTC-09:00","abbreviation":"AKST","tzName":"Alaska Standard Time"},{"zoneName":"Pacific/Honolulu","gmtOffset":-36000,"gmtOffsetName":"UTC-10:00","abbreviation":"HST","tzName":"HawaiiAleutian Standard Time"}]',
'translations' => '{"kr":"미국","pt-BR":"Estados Unidos","pt":"Estados Unidos","nl":"Verenigde Staten","hr":"Sjedinjene Američke Države","fa":"ایالات متحده آمریکا","de":"Vereinigte Staaten von Amerika","es":"Estados Unidos","fr":"États-Unis","ja":"アメリカ合衆国","it":"Stati Uniti D\'America","cn":"美国","tr":"Amerika"}',
'latitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '38';
$this->fractionalPart = '00000000';
$this->negative = false;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'longitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '97';
$this->fractionalPart = '00000000';
$this->negative = true;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'emoji' => '🇺🇸',
'emojiU' => 'U+1F1FA U+1F1F8',
'created_at' => '2018-07-21 16:11:03',
'updated_at' => '2023-08-10 04:23:19',
'flag' => true,
'wikiDataId' => 'Q30',
],
[
'id' => 234,
'name' => 'United States Minor Outlying Islands',
'iso3' => 'UMI',
'numeric_code' => '581',
'iso2' => 'UM',
'phonecode' => '1',
'capital' => '',
'currency' => 'USD',
'currency_name' => 'United States dollar',
'currency_symbol' => '$',
'tld' => '.us',
'native' => 'United States Minor Outlying Islands',
'region' => 'Americas',
'region_id' => 2,
'subregion' => 'Northern America',
'subregion_id' => 6,
'nationality' => 'American',
'timezones' => '[{"zoneName":"Pacific/Midway","gmtOffset":-39600,"gmtOffsetName":"UTC-11:00","abbreviation":"SST","tzName":"Samoa Standard Time"},{"zoneName":"Pacific/Wake","gmtOffset":43200,"gmtOffsetName":"UTC+12:00","abbreviation":"WAKT","tzName":"Wake Island Time"}]',
'translations' => '{"kr":"미국령 군소 제도","pt-BR":"Ilhas Menores Distantes dos Estados Unidos","pt":"Ilhas Menores Distantes dos Estados Unidos","nl":"Kleine afgelegen eilanden van de Verenigde Staten","hr":"Mali udaljeni otoci SAD-a","fa":"جزایر کوچک حاشیه‌ای ایالات متحده آمریکا","de":"Kleinere Inselbesitzungen der Vereinigten Staaten","es":"Islas Ultramarinas Menores de Estados Unidos","fr":"Îles mineures éloignées des États-Unis","ja":"合衆国領有小離島","it":"Isole minori esterne degli Stati Uniti d\'America","cn":"美国本土外小岛屿","tr":"Abd Küçük Harici Adalari"}',
'latitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '0';
$this->fractionalPart = '00000000';
$this->negative = false;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'longitude' => (static function() {
$class = new ReflectionClass(Decimal::class);
$object = $class->newInstanceWithoutConstructor();
(function() {
$this->integralPart = '0';
$this->fractionalPart = '00000000';
$this->negative = false;
$this->scale = 8;
})->bindTo($object, Decimal::class)();
return $object;
})(),
'emoji' => '🇺🇲',
'emojiU' => 'U+1F1FA U+1F1F2',
'created_at' => '2018-07-21 16:11:03',
'updated_at' => '2023-08-10 04:23:19',
'flag' => true,
'wikiDataId' => null,
],
];
parent::init();
}
}

View File

@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* RegionsFixture
*/
class RegionsFixture extends TestFixture
{
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => 1,
'name' => 'Africa',
// 'translations' => '{"kr":"아프리카","pt-BR":"África","pt":"África","nl":"Afrika","hr":"Afrika","fa":"آفریقا","de":"Afrika","es":"África","fr":"Afrique","ja":"アフリカ","it":"Africa","cn":"非洲","tr":"Afrika"}',
'translations' => '',
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-14 14:11:03',
'flag' => true,
'wikiDataId' => 'Q15',
],
[
'id' => 2,
'name' => 'Americas',
// 'translations' => '{"kr":"아메리카","pt-BR":"América","pt":"América","nl":"Amerika","hr":"Amerika","fa":"قاره آمریکا","de":"Amerika","es":"América","fr":"Amérique","ja":"アメリカ州","it":"America","cn":"美洲","tr":"Amerika"}',
'translations' => '',
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-14 14:11:03',
'flag' => true,
'wikiDataId' => 'Q828',
],
[
'id' => 3,
'name' => 'Asia',
// 'translations' => '{"kr":"아시아","pt-BR":"Ásia","pt":"Ásia","nl":"Azië","hr":"Ázsia","fa":"آسیا","de":"Asien","es":"Asia","fr":"Asie","ja":"アジア","it":"Asia","cn":"亚洲","tr":"Asya"}',
'translations' => '',
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-14 14:11:03',
'flag' => true,
'wikiDataId' => 'Q48',
],
[
'id' => 4,
'name' => 'Europe',
// 'translations' => '{"kr":"유럽","pt-BR":"Europa","pt":"Europa","nl":"Europa","hr":"Európa","fa":"اروپا","de":"Europa","es":"Europa","fr":"Europe","ja":"ヨーロッパ","it":"Europa","cn":"欧洲","tr":"Avrupa"}',
'translations' => '',
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-14 14:11:03',
'flag' => true,
'wikiDataId' => 'Q46',
],
[
'id' => 5,
'name' => 'Oceania',
// 'translations' => '{"kr":"오세아니아","pt-BR":"Oceania","pt":"Oceania","nl":"Oceanië en Australië","hr":"Óceánia és Ausztrália","fa":"اقیانوسیه","de":"Ozeanien und Australien","es":"Oceanía","fr":"Océanie","ja":"オセアニア","it":"Oceania","cn":"大洋洲","tr":"Okyanusya"}',
'translations' => '',
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-14 14:11:03',
'flag' => true,
'wikiDataId' => 'Q55643',
],
[
'id' => 6,
'name' => 'Polar',
// 'translations' => '{"kr":"남극","pt-BR":"Antártida","pt":"Antártida","nl":"Antarctica","hr":"Antarktika","fa":"جنوبگان","de":"Antarktika","es":"Antártida","fr":"Antarctique","ja":"南極大陸","it":"Antartide","cn":"南極洲","tr":"Antarktika"}',
'translations' => '',
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-14 14:11:03',
'flag' => true,
'wikiDataId' => 'Q51',
],
];
parent::init();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,244 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\Fixture;
use Cake\TestSuite\Fixture\TestFixture;
/**
* SubregionsFixture
*/
class SubregionsFixture extends TestFixture
{
/**
* Init method
*
* @return void
*/
public function init(): void
{
$this->records = [
[
'id' => 1,
'name' => 'Northern Africa',
'translations' => '{"korean":"북아프리카","portuguese":"Norte de África","dutch":"Noord-Afrika","croatian":"Sjeverna Afrika","persian":"شمال آفریقا","german":"Nordafrika","spanish":"Norte de África","french":"Afrique du Nord","japanese":"北アフリカ","italian":"Nordafrica","chinese":"北部非洲"}',
'region_id' => 1,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:10:23',
'flag' => true,
'wikiDataId' => 'Q27381',
],
[
'id' => 2,
'name' => 'Middle Africa',
'translations' => '{"korean":"중앙아프리카","portuguese":"África Central","dutch":"Centraal-Afrika","croatian":"Srednja Afrika","persian":"مرکز آفریقا","german":"Zentralafrika","spanish":"África Central","french":"Afrique centrale","japanese":"中部アフリカ","italian":"Africa centrale","chinese":"中部非洲"}',
'region_id' => 1,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:09',
'flag' => true,
'wikiDataId' => 'Q27433',
],
[
'id' => 3,
'name' => 'Western Africa',
'translations' => '{"korean":"서아프리카","portuguese":"África Ocidental","dutch":"West-Afrika","croatian":"Zapadna Afrika","persian":"غرب آفریقا","german":"Westafrika","spanish":"África Occidental","french":"Afrique de l\'Ouest","japanese":"西アフリカ","italian":"Africa occidentale","chinese":"西非"}',
'region_id' => 1,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:09',
'flag' => true,
'wikiDataId' => 'Q4412',
],
[
'id' => 4,
'name' => 'Eastern Africa',
'translations' => '{"korean":"동아프리카","portuguese":"África Oriental","dutch":"Oost-Afrika","croatian":"Istočna Afrika","persian":"شرق آفریقا","german":"Ostafrika","spanish":"África Oriental","french":"Afrique de l\'Est","japanese":"東アフリカ","italian":"Africa orientale","chinese":"东部非洲"}',
'region_id' => 1,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:10',
'flag' => true,
'wikiDataId' => 'Q27407',
],
[
'id' => 5,
'name' => 'Southern Africa',
'translations' => '{"korean":"남아프리카","portuguese":"África Austral","dutch":"Zuidelijk Afrika","croatian":"Južna Afrika","persian":"جنوب آفریقا","german":"Südafrika","spanish":"África austral","french":"Afrique australe","japanese":"南部アフリカ","italian":"Africa australe","chinese":"南部非洲"}',
'region_id' => 1,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:10',
'flag' => true,
'wikiDataId' => 'Q27394',
],
[
'id' => 6,
'name' => 'Northern America',
'translations' => '{"korean":"북미","portuguese":"América Setentrional","dutch":"Noord-Amerika","persian":"شمال آمریکا","german":"Nordamerika","spanish":"América Norteña","french":"Amérique septentrionale","japanese":"北部アメリカ","italian":"America settentrionale","chinese":"北美地區"}',
'region_id' => 2,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:10',
'flag' => true,
'wikiDataId' => 'Q2017699',
],
[
'id' => 7,
'name' => 'Caribbean',
'translations' => '{"korean":"카리브","portuguese":"Caraíbas","dutch":"Caraïben","croatian":"Karibi","persian":"کارائیب","german":"Karibik","spanish":"Caribe","french":"Caraïbes","japanese":"カリブ海地域","italian":"Caraibi","chinese":"加勒比地区"}',
'region_id' => 2,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:10',
'flag' => true,
'wikiDataId' => 'Q664609',
],
[
'id' => 8,
'name' => 'South America',
'translations' => '{"korean":"남아메리카","portuguese":"América do Sul","dutch":"Zuid-Amerika","croatian":"Južna Amerika","persian":"آمریکای جنوبی","german":"Südamerika","spanish":"América del Sur","french":"Amérique du Sud","japanese":"南アメリカ","italian":"America meridionale","chinese":"南美洲"}',
'region_id' => 2,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:10',
'flag' => true,
'wikiDataId' => 'Q18',
],
[
'id' => 9,
'name' => 'Central America',
'translations' => '{"korean":"중앙아메리카","portuguese":"América Central","dutch":"Centraal-Amerika","croatian":"Srednja Amerika","persian":"آمریکای مرکزی","german":"Zentralamerika","spanish":"América Central","french":"Amérique centrale","japanese":"中央アメリカ","italian":"America centrale","chinese":"中美洲"}',
'region_id' => 2,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:11',
'flag' => true,
'wikiDataId' => 'Q27611',
],
[
'id' => 10,
'name' => 'Central Asia',
'translations' => '{"korean":"중앙아시아","portuguese":"Ásia Central","dutch":"Centraal-Azië","croatian":"Srednja Azija","persian":"آسیای میانه","german":"Zentralasien","spanish":"Asia Central","french":"Asie centrale","japanese":"中央アジア","italian":"Asia centrale","chinese":"中亚"}',
'region_id' => 3,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:11',
'flag' => true,
'wikiDataId' => 'Q27275',
],
[
'id' => 11,
'name' => 'Western Asia',
'translations' => '{"korean":"서아시아","portuguese":"Sudoeste Asiático","dutch":"Zuidwest-Azië","croatian":"Jugozapadna Azija","persian":"غرب آسیا","german":"Vorderasien","spanish":"Asia Occidental","french":"Asie de l\'Ouest","japanese":"西アジア","italian":"Asia occidentale","chinese":"西亚"}',
'region_id' => 3,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:11',
'flag' => true,
'wikiDataId' => 'Q27293',
],
[
'id' => 12,
'name' => 'Eastern Asia',
'translations' => '{"korean":"동아시아","portuguese":"Ásia Oriental","dutch":"Oost-Azië","croatian":"Istočna Azija","persian":"شرق آسیا","german":"Ostasien","spanish":"Asia Oriental","french":"Asie de l\'Est","japanese":"東アジア","italian":"Asia orientale","chinese":"東亞"}',
'region_id' => 3,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:11',
'flag' => true,
'wikiDataId' => 'Q27231',
],
[
'id' => 13,
'name' => 'South-Eastern Asia',
'translations' => '{"korean":"동남아시아","portuguese":"Sudeste Asiático","dutch":"Zuidoost-Azië","croatian":"Jugoistočna Azija","persian":"جنوب شرق آسیا","german":"Südostasien","spanish":"Sudeste Asiático","french":"Asie du Sud-Est","japanese":"東南アジア","italian":"Sud-est asiatico","chinese":"东南亚"}',
'region_id' => 3,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:12',
'flag' => true,
'wikiDataId' => 'Q11708',
],
[
'id' => 14,
'name' => 'Southern Asia',
'translations' => '{"korean":"남아시아","portuguese":"Ásia Meridional","dutch":"Zuid-Azië","croatian":"Južna Azija","persian":"جنوب آسیا","german":"Südasien","spanish":"Asia del Sur","french":"Asie du Sud","japanese":"南アジア","italian":"Asia meridionale","chinese":"南亚"}',
'region_id' => 3,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:12',
'flag' => true,
'wikiDataId' => 'Q771405',
],
[
'id' => 15,
'name' => 'Eastern Europe',
'translations' => '{"korean":"동유럽","portuguese":"Europa de Leste","dutch":"Oost-Europa","croatian":"Istočna Europa","persian":"شرق اروپا","german":"Osteuropa","spanish":"Europa Oriental","french":"Europe de l\'Est","japanese":"東ヨーロッパ","italian":"Europa orientale","chinese":"东欧"}',
'region_id' => 4,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:12',
'flag' => true,
'wikiDataId' => 'Q27468',
],
[
'id' => 16,
'name' => 'Southern Europe',
'translations' => '{"korean":"남유럽","portuguese":"Europa meridional","dutch":"Zuid-Europa","croatian":"Južna Europa","persian":"جنوب اروپا","german":"Südeuropa","spanish":"Europa del Sur","french":"Europe du Sud","japanese":"南ヨーロッパ","italian":"Europa meridionale","chinese":"南欧"}',
'region_id' => 4,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:12',
'flag' => true,
'wikiDataId' => 'Q27449',
],
[
'id' => 17,
'name' => 'Western Europe',
'translations' => '{"korean":"서유럽","portuguese":"Europa Ocidental","dutch":"West-Europa","croatian":"Zapadna Europa","persian":"غرب اروپا","german":"Westeuropa","spanish":"Europa Occidental","french":"Europe de l\'Ouest","japanese":"西ヨーロッパ","italian":"Europa occidentale","chinese":"西欧"}',
'region_id' => 4,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:12',
'flag' => true,
'wikiDataId' => 'Q27496',
],
[
'id' => 18,
'name' => 'Northern Europe',
'translations' => '{"korean":"북유럽","portuguese":"Europa Setentrional","dutch":"Noord-Europa","croatian":"Sjeverna Europa","persian":"شمال اروپا","german":"Nordeuropa","spanish":"Europa del Norte","french":"Europe du Nord","japanese":"北ヨーロッパ","italian":"Europa settentrionale","chinese":"北歐"}',
'region_id' => 4,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:13',
'flag' => true,
'wikiDataId' => 'Q27479',
],
[
'id' => 19,
'name' => 'Australia and New Zealand',
'translations' => '{"korean":"오스트랄라시아","portuguese":"Australásia","dutch":"Australazië","croatian":"Australazija","persian":"استرالزی","german":"Australasien","spanish":"Australasia","french":"Australasie","japanese":"オーストララシア","italian":"Australasia","chinese":"澳大拉西亞"}',
'region_id' => 5,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:13',
'flag' => true,
'wikiDataId' => 'Q45256',
],
[
'id' => 20,
'name' => 'Melanesia',
'translations' => '{"korean":"멜라네시아","portuguese":"Melanésia","dutch":"Melanesië","croatian":"Melanezija","persian":"ملانزی","german":"Melanesien","spanish":"Melanesia","french":"Mélanésie","japanese":"メラネシア","italian":"Melanesia","chinese":"美拉尼西亚"}',
'region_id' => 5,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:13',
'flag' => true,
'wikiDataId' => 'Q37394',
],
[
'id' => 21,
'name' => 'Micronesia',
'translations' => '{"korean":"미크로네시아","portuguese":"Micronésia","dutch":"Micronesië","croatian":"Mikronezija","persian":"میکرونزی","german":"Mikronesien","spanish":"Micronesia","french":"Micronésie","japanese":"ミクロネシア","italian":"Micronesia","chinese":"密克罗尼西亚群岛"}',
'region_id' => 5,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:13',
'flag' => true,
'wikiDataId' => 'Q3359409',
],
[
'id' => 22,
'name' => 'Polynesia',
'translations' => '{"korean":"폴리네시아","portuguese":"Polinésia","dutch":"Polynesië","croatian":"Polinezija","persian":"پلی‌نزی","german":"Polynesien","spanish":"Polinesia","french":"Polynésie","japanese":"ポリネシア","italian":"Polinesia","chinese":"玻里尼西亞"}',
'region_id' => 5,
'created_at' => '2023-08-14 14:11:03',
'updated_at' => '2023-08-25 03:22:13',
'flag' => true,
'wikiDataId' => 'Q35942',
],
];
parent::init();
}
}

View File

@@ -0,0 +1,481 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Controller;
use CakeAddresses\Controller\AddressesController;
use CakeAddresses\Model\Table\AddressesTable;
use PHPUnit\Exception;
/**
* CakeAddresses\Controller\AddressesController Test Case
*
* @uses \CakeAddresses\Controller\AddressesController
*/
class AddressesControllerTest extends BaseControllerTest
{
/**
* Addresses Table
*
* @var \CakeAddresses\Model\Table\AddressesTable
*/
protected $Addresses;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Addresses',
// 'plugin.CakeAddresses.Cities',
'plugin.CakeAddresses.Countries',
// 'plugin.CakeAddresses.Regions',
'plugin.CakeAddresses.States',
// 'plugin.CakeAddresses.Subregions',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->Addresses = $this->getTableLocator()->get('CakeAddresses.Addresses');
$this->enableCsrfToken();
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Addresses);
parent::tearDown();
}
/**
* Test index method
*
* Tests the index action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\AddressesController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetUnauthenticated(): void
{
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetLoggedIn(): void
{
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
* Test view method
*
* Tests the view action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\AddressesController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetUnauthenticated(): void
{
$id = 1;
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetLoggedIn(): void
{
$id = 1;
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
* Test add method
*
* Tests the add action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\AddressesController::add()
* @throws Exception
*
* @return void
*/
public function testAddGetUnauthenticated(): void
{
$cntBefore = $this->Addresses->find()->count();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
$cntAfter = $this->Addresses->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
* Test add method
*
* Tests the add action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::add()
* @throws Exception
*
* @return void
*/
public function testAddGetLoggedIn(): void
{
$cntBefore = $this->Addresses->find()->count();
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'add',
];
$this->get($url);
$this->assertResponseCode(200);
$cntAfter = $this->Addresses->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::add()
* @throws Exception
*
* @return void
*/
public function testAddPostLoggedInSuccess(): void
{
$cntBefore = $this->Addresses->find()->count();
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'add',
];
$data = [
'address_name' => 'new address',
'contact_name' => 'john doe',
'address_line1' => '123 Test ST',
'address_line2' => '',
'city' => 'Seattle',
'city_id' => '',
'state_id' => 1462,
'postal_code' => '98056',
'country_id' => 233,
'phone_number' => '',
'email' => '',
'notes' => '',
];
$this->post($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('addresses');
$cntAfter = $this->Addresses->find()->count();
$this->assertEquals($cntBefore + 1, $cntAfter);
}
/**
* Test add method
*
* Tests a POST request to the add action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::add()
* @throws Exception
*
* @return void
*/
public function testAddPostLoggedInFailure(): void
{
$cntBefore = $this->Addresses->find()->count();
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'add',
];
$data = [
'address_name' => '',
'contact_name' => '',
'address_line1' => '',
'address_line2' => '',
'city' => 'Seattle',
'city_id' => '',
'state_id' => 1462,
'postal_code' => '98056',
'country_id' => 233,
'phone_number' => '',
'email' => '',
'notes' => '',
];
$this->post($url, $data);
$this->assertResponseCode(200);
$cntAfter = $this->Addresses->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
* Test edit method
*
* Tests the edit action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\AddressesController::edit()
* @throws Exception
*
* @return void
*/
public function testEditGetUnauthenticated(): void
{
$id = 1;
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'edit',
$id,
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test edit method
*
* Tests the edit action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::edit()
* @throws Exception
*
* @return void
*/
public function testEditGetLoggedIn(): void
{
$id = 1;
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'edit',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::edit()
* @throws Exception
*
* @return void
*/
public function testEditPutLoggedInSuccess(): void
{
$this->loginUserByRole();
$id = 1;
$before = $this->Addresses->get($id);
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'edit',
$id,
];
$data = [
// test new data here
'address_name' => 'new address',
'contact_name' => 'john doe',
'address_line1' => '123 Test ST',
'address_line2' => '',
'city' => 'Seattle',
'city_id' => '',
'state_id' => 1462,
'postal_code' => '98056',
'country_id' => 233,
'phone_number' => '',
'email' => '',
'notes' => '',
];
$this->put($url, $data);
$this->assertResponseCode(302);
$this->assertRedirectContains('addresses');
$after = $this->Addresses->get($id);
// assert saved properly below
}
/**
* Test edit method
*
* Tests a PUT request to the edit action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::edit()
* @throws Exception
*
* @return void
*/
public function testEditPutLoggedInFailure(): void
{
$this->loginUserByRole();
$id = 1;
$before = $this->Addresses->get($id);
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'edit',
$id,
];
$data = [
'address_name' => '',
'contact_name' => '',
'address_line1' => '',
'address_line2' => '',
'city' => 'Seattle',
'city_id' => '',
'state_id' => 1462,
'postal_code' => '98056',
'country_id' => 233,
'phone_number' => '',
'email' => '',
'notes' => '',
];
$this->put($url, $data);
$this->assertResponseCode(200);
$after = $this->Addresses->get($id);
// assert save failed below
}
/**
* Test delete method
*
* Tests the delete action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\AddressesController::delete()
* @throws Exception
*
* @return void
*/
public function testDeleteUnauthenticated(): void
{
$cntBefore = $this->Addresses->find()->count();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'delete',
1,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
$cntAfter = $this->Addresses->find()->count();
$this->assertEquals($cntBefore, $cntAfter);
}
/**
* Test delete method
*
* Tests the delete action with a logged in user
*
* @uses \CakeAddresses\Controller\AddressesController::delete()
* @throws Exception
*
* @return void
*/
public function testDeleteLoggedIn(): void
{
$cntBefore = $this->Addresses->find()->count();
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Addresses',
'action' => 'delete',
1,
];
$this->delete($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('addresses');
$cntAfter = $this->Addresses->find()->count();
$this->assertEquals($cntBefore - 1, $cntAfter);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace CakeAddresses\Test\TestCase\Controller;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
class BaseControllerTest extends TestCase
{
use IntegrationTestTrait;
public function loginUserByRole(string $role = 'admin'): void
{
$this->session(['Auth.User.id' => 1]);
$this->session(['Auth.id' => 1]);
}
/**
* @return void
*/
public function testTest()
{
$this->assertEquals(1, 1);
}
}

View File

@@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Controller;
use CakeAddresses\Controller\CitiesController;
use PHPUnit\Exception;
/**
* CakeAddresses\Controller\CitiesController Test Case
*
* @uses \CakeAddresses\Controller\CitiesController
*/
class CitiesControllerTest extends BaseControllerTest
{
/**
* Cities Table
*
* @var \CakeAddresses\Model\Table\CitiesTable
*/
protected $Cities;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
// 'plugin.CakeAddresses.Regions',
// 'plugin.CakeAddresses.Subregions',
'plugin.CakeAddresses.Countries',
'plugin.CakeAddresses.States',
'plugin.CakeAddresses.Cities',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->Cities = $this->getTableLocator()->get('Cities');
$this->enableCsrfToken();
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Cities);
parent::tearDown();
}
/**
* Test select method
*
* Tests the select action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\CitiesController::select()
* @throws Exception
*
* @return void
*/
public function testSelectGetUnauthenticated(): void
{
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Cities',
'action' => 'select',
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test select method
*
* Tests the select action with a logged in user
*
* @uses \CakeAddresses\Controller\CitiesController::select()
* @throws Exception
*
* @return void
*/
public function testSelectGetLoggedIn(): void
{
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Cities',
'action' => 'select',
];
$this->get($url);
$this->assertResponseCode(200);
}
}

View File

@@ -0,0 +1,151 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Controller;
use CakeAddresses\Controller\CountriesController;
use PHPUnit\Exception;
/**
* CakeAddresses\Controller\CountriesController Test Case
*
* @uses \CakeAddresses\Controller\CountriesController
*/
class CountriesControllerTest extends BaseControllerTest
{
/**
* AnsibleGroups Table
*
* @var \CakeAddresses\Model\Table\CountriesTable
*/
protected $Countries;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Regions',
'plugin.CakeAddresses.Subregions',
'plugin.CakeAddresses.Countries',
'plugin.CakeAddresses.States',
// 'plugin.CakeAddresses.Cities',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->Countries = $this->getTableLocator()->get('Countries');
$this->enableCsrfToken();
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Countries);
parent::tearDown();
}
/**
* Test index method
*
* Tests the index action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\CountriesController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetUnauthenticated(): void
{
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Countries',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeAddresses\Controller\CountriesController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetLoggedIn(): void
{
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Countries',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
* Test view method
*
* Tests the view action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\CountriesController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetUnauthenticated(): void
{
$id = 233;
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Countries',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeAddresses\Controller\CountriesController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetLoggedIn(): void
{
$id = 233;
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Countries',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
}

View File

@@ -0,0 +1,154 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Controller;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeAddresses\Controller\RegionsController;
use PHPUnit\Exception;
/**
* CakeAddresses\Controller\RegionsController Test Case
*
* @uses \CakeAddresses\Controller\RegionsController
*/
class RegionsControllerTest extends BaseControllerTest
{
/**
* Regions Table
*
* @var \CakeAddresses\Model\Table\RegionsTable
*/
protected $Regions;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Regions',
// 'plugin.CakeAddresses.Subregions',
// 'plugin.CakeAddresses.Countries',
// 'plugin.CakeAddresses.States',
// 'plugin.CakeAddresses.Cities',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->Regions = $this->getTableLocator()->get('Regions');
$this->enableCsrfToken();
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Regions);
parent::tearDown();
}
/**
* Test index method
*
* Tests the index action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\RegionsController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetUnauthenticated(): void
{
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Regions',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeAddresses\Controller\RegionsController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetLoggedIn(): void
{
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Regions',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
* Test view method
*
* Tests the view action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\RegionsController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetUnauthenticated(): void
{
$id = 1;
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Regions',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeAddresses\Controller\RegionsController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetLoggedIn(): void
{
$id = 1;
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Regions',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
}

View File

@@ -0,0 +1,150 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Controller;
use CakeAddresses\Controller\StatesController;
use PHPUnit\Exception;
/**
* CakeAddresses\Controller\StatesController Test Case
*
* @uses \CakeAddresses\Controller\StatesController
*/
class StatesControllerTest extends BaseControllerTest
{
/**
* States Table
*
* @var \CakeAddresses\Model\Table\StatesTable
*/
protected $States;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
// 'plugin.CakeAddresses.Regions',
// 'plugin.CakeAddresses.Subregions',
'plugin.CakeAddresses.Countries',
'plugin.CakeAddresses.States',
// 'plugin.CakeAddresses.Cities',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->States = $this->getTableLocator()->get('States');
$this->enableCsrfToken();
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->States);
parent::tearDown();
}
/**
* Test index method
*
* Tests the index action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\StatesController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetUnauthenticated(): void
{
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'States',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeAddresses\Controller\StatesController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetLoggedIn(): void
{
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'States',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
* Test view method
*
* Tests the view action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\StatesController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetUnauthenticated(): void
{
$id = 1462;
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'States',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeAddresses\Controller\StatesController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetLoggedIn(): void
{
$id = 1462;
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'States',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
}

View File

@@ -0,0 +1,154 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Controller;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
use CakeAddresses\Controller\SubregionsController;
use PHPUnit\Exception;
/**
* CakeAddresses\Controller\SubregionsController Test Case
*
* @uses \CakeAddresses\Controller\SubregionsController
*/
class SubregionsControllerTest extends BaseControllerTest
{
/**
* Subregions Table
*
* @var \CakeAddresses\Model\Table\SubregionsTable
*/
protected $Subregions;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Regions',
'plugin.CakeAddresses.Subregions',
'plugin.CakeAddresses.Countries',
// 'plugin.CakeAddresses.States',
// 'plugin.CakeAddresses.Cities',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->Subregions = $this->getTableLocator()->get('Subregions');
$this->enableCsrfToken();
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Subregions);
parent::tearDown();
}
/**
* Test index method
*
* Tests the index action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\SubregionsController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetUnauthenticated(): void
{
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Subregions',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test index method
*
* Tests the index action with a logged in user
*
* @uses \CakeAddresses\Controller\SubregionsController::index()
* @throws Exception
*
* @return void
*/
public function testIndexGetLoggedIn(): void
{
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Subregions',
'action' => 'index',
];
$this->get($url);
$this->assertResponseCode(200);
}
/**
* Test view method
*
* Tests the view action with an unauthenticated user (not logged in)
*
* @uses \CakeAddresses\Controller\SubregionsController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetUnauthenticated(): void
{
$id = 1;
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Subregions',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(302);
$this->assertRedirectContains('login');
}
/**
* Test view method
*
* Tests the view action with a logged in user
*
* @uses \CakeAddresses\Controller\SubregionsController::view()
* @throws Exception
*
* @return void
*/
public function testViewGetLoggedIn(): void
{
$id = 1;
$this->loginUserByRole();
$url = [
'plugin' => 'CakeAddresses',
'controller' => 'Subregions',
'action' => 'view',
$id,
];
$this->get($url);
$this->assertResponseCode(200);
}
}

View File

@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Model\Table;
use Cake\TestSuite\TestCase;
use CakeAddresses\Model\Table\AddressesTable;
/**
* CakeAddresses\Model\Table\AddressesTable Test Case
*/
class AddressesTableTest extends TestCase
{
/**
* Test subject
*
* @var \CakeAddresses\Model\Table\AddressesTable
*/
protected $Addresses;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Addresses',
'plugin.CakeAddresses.Cities',
'plugin.CakeAddresses.States',
'plugin.CakeAddresses.Countries',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('Addresses') ? [] : ['className' => AddressesTable::class];
$this->Addresses = $this->getTableLocator()->get('Addresses', $config);
}
/**
* TestInitialize method
*
* @return void
* @uses \CakeAddresses\Model\Table\AddressesTable::initialize()
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'Cities',
'States',
'Countries',
];
$associations = $this->Addresses->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->Addresses->hasAssociation($expectedAssociation), 'Failed asserting Addresses has the association: ' . $expectedAssociation);
}
// verify all behaviors loaded
$expectedBehaviors = [
];
$behaviors = $this->Addresses->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->Addresses->hasBehavior($expectedBehavior));
}
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Addresses);
parent::tearDown();
}
/**
* Test validationDefault method
*
* @return void
* @uses \CakeAddresses\Model\Table\AddressesTable::validationDefault()
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test buildRules method
*
* @return void
* @uses \CakeAddresses\Model\Table\AddressesTable::buildRules()
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
}

View File

@@ -0,0 +1,111 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Model\Table;
use Cake\TestSuite\TestCase;
use CakeAddresses\Model\Table\CitiesTable;
/**
* CakeAddresses\Model\Table\CitiesTable Test Case
*/
class CitiesTableTest extends TestCase
{
/**
* Test subject
*
* @var \CakeAddresses\Model\Table\CitiesTable
*/
protected $Cities;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Cities',
'plugin.CakeAddresses.States',
'plugin.CakeAddresses.Countries',
'plugin.CakeAddresses.Addresses',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('Cities') ? [] : ['className' => CitiesTable::class];
$this->Cities = $this->getTableLocator()->get('Cities', $config);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Cities);
parent::tearDown();
}
/**
* TestInitialize method
*
* @return void
* @uses \CakeAddresses\Model\Table\CitiesTable::initialize()
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'States',
'Countries',
'Addresses',
];
$associations = $this->Cities->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->Cities->hasAssociation($expectedAssociation), 'Failed asserting Cities has the association: ' . $expectedAssociation);
}
// verify all behaviors loaded
$expectedBehaviors = [
];
$behaviors = $this->Cities->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->Cities->hasBehavior($expectedBehavior));
}
}
/**
* Test validationDefault method
*
* @return void
* @uses \CakeAddresses\Model\Table\CitiesTable::validationDefault()
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test buildRules method
*
* @return void
* @uses \CakeAddresses\Model\Table\CitiesTable::buildRules()
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
}

View File

@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Model\Table;
use Cake\TestSuite\TestCase;
use CakeAddresses\Model\Table\CountriesTable;
/**
* CakeAddresses\Model\Table\CountriesTable Test Case
*/
class CountriesTableTest extends TestCase
{
/**
* Test subject
*
* @var \CakeAddresses\Model\Table\CountriesTable
*/
protected $Countries;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Countries',
'plugin.CakeAddresses.Regions',
'plugin.CakeAddresses.Subregions',
'plugin.CakeAddresses.Addresses',
'plugin.CakeAddresses.Cities',
'plugin.CakeAddresses.States',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('Countries') ? [] : ['className' => CountriesTable::class];
$this->Countries = $this->getTableLocator()->get('Countries', $config);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Countries);
parent::tearDown();
}
/**
* Test validationDefault method
*
* @return void
* @uses \CakeAddresses\Model\Table\CountriesTable::validationDefault()
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test buildRules method
*
* @return void
* @uses \CakeAddresses\Model\Table\CountriesTable::buildRules()
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
}

View File

@@ -0,0 +1,97 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Model\Table;
use Cake\TestSuite\TestCase;
use CakeAddresses\Model\Table\RegionsTable;
/**
* CakeAddresses\Model\Table\RegionsTable Test Case
*/
class RegionsTableTest extends TestCase
{
/**
* Test subject
*
* @var \CakeAddresses\Model\Table\RegionsTable
*/
protected $Regions;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Regions',
'plugin.CakeAddresses.Countries',
'plugin.CakeAddresses.Subregions',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('Regions') ? [] : ['className' => RegionsTable::class];
$this->Regions = $this->getTableLocator()->get('Regions', $config);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Regions);
parent::tearDown();
}
/**
* TestInitialize method
*
* @return void
* @uses \CakeAddresses\Model\Table\RegionsTable::initialize()
*/
public function testInitialize(): void
{
// verify all associations loaded
$expectedAssociations = [
'Countries',
'Subregions',
// 'States',
];
$associations = $this->Regions->associations();
$this->assertCount(count($expectedAssociations), $associations);
foreach ($expectedAssociations as $expectedAssociation) {
$this->assertTrue($this->Regions->hasAssociation($expectedAssociation));
}
// verify all behaviors loaded
$expectedBehaviors = [];
$behaviors = $this->Regions->behaviors();
$this->assertCount(count($expectedBehaviors), $behaviors);
foreach ($expectedBehaviors as $expectedBehavior) {
$this->assertTrue($this->Regions->hasBehavior($expectedBehavior));
}
}
/**
* Test validationDefault method
*
* @return void
* @uses \CakeAddresses\Model\Table\RegionsTable::validationDefault()
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
}

View File

@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Model\Table;
use Cake\TestSuite\TestCase;
use CakeAddresses\Model\Table\StatesTable;
/**
* CakeAddresses\Model\Table\StatesTable Test Case
*/
class StatesTableTest extends TestCase
{
/**
* Test subject
*
* @var \CakeAddresses\Model\Table\StatesTable
*/
protected $States;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.States',
'plugin.CakeAddresses.Countries',
'plugin.CakeAddresses.Addresses',
'plugin.CakeAddresses.Cities',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('States') ? [] : ['className' => StatesTable::class];
$this->States = $this->getTableLocator()->get('States', $config);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->States);
parent::tearDown();
}
/**
* Test validationDefault method
*
* @return void
* @uses \CakeAddresses\Model\Table\StatesTable::validationDefault()
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test buildRules method
*
* @return void
* @uses \CakeAddresses\Model\Table\StatesTable::buildRules()
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
}

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace CakeAddresses\Test\TestCase\Model\Table;
use Cake\TestSuite\TestCase;
use CakeAddresses\Model\Table\SubregionsTable;
/**
* CakeAddresses\Model\Table\SubregionsTable Test Case
*/
class SubregionsTableTest extends TestCase
{
/**
* Test subject
*
* @var \CakeAddresses\Model\Table\SubregionsTable
*/
protected $Subregions;
/**
* Fixtures
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.CakeAddresses.Subregions',
'plugin.CakeAddresses.Regions',
'plugin.CakeAddresses.Countries',
];
/**
* setUp method
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$config = $this->getTableLocator()->exists('Subregions') ? [] : ['className' => SubregionsTable::class];
$this->Subregions = $this->getTableLocator()->get('Subregions', $config);
}
/**
* tearDown method
*
* @return void
*/
protected function tearDown(): void
{
unset($this->Subregions);
parent::tearDown();
}
/**
* Test validationDefault method
*
* @return void
* @uses \CakeAddresses\Model\Table\SubregionsTable::validationDefault()
*/
public function testValidationDefault(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test buildRules method
*
* @return void
* @uses \CakeAddresses\Model\Table\SubregionsTable::buildRules()
*/
public function testBuildRules(): void
{
$this->markTestIncomplete('Not implemented yet.');
}
}

119
tests/bootstrap.php Normal file
View File

@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
use Cake\Cache\Cache;
use Cake\Chronos\Chronos;
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\Database\Connection;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\Fixture\SchemaLoader;
use CakeAddresses\CakeAddressesPlugin;
use CakeProducts\CakeProductsPlugin;
use Migrations\TestSuite\Migrator;
use TestApp\Controller\AppController;
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('WINDOWS')) {
if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
define('WINDOWS', true);
} else {
define('WINDOWS', false);
}
}
define('PLUGIN_ROOT', dirname(__DIR__));
define('ROOT', PLUGIN_ROOT . DS . 'tests' . DS . 'test_app');
define('TMP', PLUGIN_ROOT . DS . 'tmp' . DS);
define('LOGS', TMP . 'logs' . DS);
define('CACHE', TMP . 'cache' . DS);
define('APP', ROOT . DS . 'src' . DS);
define('APP_DIR', 'src');
define('CAKE_CORE_INCLUDE_PATH', PLUGIN_ROOT . '/vendor/cakephp/cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . APP_DIR . DS);
define('WWW_ROOT', PLUGIN_ROOT . DS . 'webroot' . DS);
define('TESTS', __DIR__ . DS);
define('CONFIG', TESTS . 'config' . DS);
ini_set('intl.default_locale', 'de-DE');
require PLUGIN_ROOT . '/vendor/autoload.php';
require CORE_PATH . 'config/bootstrap.php';
require CAKE . 'functions.php';
Configure::write('App', [
'namespace' => 'TestApp',
'encoding' => 'UTF-8',
'paths' => [
'testWebroot' => PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'webroot' . DS,
'webroot' => PLUGIN_ROOT . DS . 'webroot' . DS,
'templates' => [
PLUGIN_ROOT . DS . 'tests' . DS . 'test_app' . DS . 'templates' . DS,
],
],
]);
Configure::write('debug', true);
Configure::write('CakeAddresses', []);
$cache = [
'default' => [
'engine' => 'File',
'path' => CACHE,
],
'_cake_translations_' => [
'className' => 'File',
'prefix' => 'crud_myapp_cake_core_',
'path' => CACHE . 'persistent/',
'serialize' => true,
'duration' => '+10 seconds',
],
'_cake_model_' => [
'className' => 'File',
'prefix' => 'crud_my_app_cake_model_',
'path' => CACHE . 'models/',
'serialize' => 'File',
'duration' => '+10 seconds',
],
];
Cache::setConfig($cache);
class_alias(AppController::class, 'App\Controller\AppController');
Plugin::getCollection()->add(new CakeAddressesPlugin());
Chronos::setTestNow(Chronos::now());
if (!getenv('DB_URL')) {
putenv('DB_URL=sqlite:///:memory:');
}
ConnectionManager::setConfig('test', [
'className' => Connection::class,
'url' => getenv('DB_URL') ?: null,
'timezone' => 'UTC',
'quoteIdentifiers' => false,
'cacheMetadata' => true,
]);
/**
* Load schema from a SQL dump file.
*
* If your plugin does not use database fixtures you can
* safely delete this.
*
* If you want to support multiple databases, consider
* using migrations to provide schema for your plugin,
* and using \Migrations\TestSuite\Migrator to load schema.
*/
// Load a schema dump file.
//(new SchemaLoader())->loadSqlFiles('tests/schema.sql', 'test');
$migrator = new Migrator();
$migrator->run(['plugin' => 'CakeAddresses']);

View File

@@ -0,0 +1 @@
<?php

1
tests/config/routes.php Normal file
View File

@@ -0,0 +1 @@
<?php

43
tests/schema.php Normal file
View File

@@ -0,0 +1,43 @@
<?php
/**
* Based entirely off of dereuromark's plugins as I was having trouble getting fixtures to load
* after moving the plugins outside of an existing cakephp app's plugins folder
*
* @link https://github.com/dereuromark/cakephp-tools/blob/master/tests/schema.php
*/
use Cake\Utility\Inflector;
$tables = [];
/**
* @var \DirectoryIterator<\DirectoryIterator> $iterator
*/
$iterator = new DirectoryIterator(__DIR__ . DS . 'Fixture');
foreach ($iterator as $file) {
if (!preg_match('/(\w+)Fixture.php$/', (string)$file, $matches)) {
continue;
}
$name = $matches[1];
$tableName = Inflector::underscore($name);
$class = 'CakeAddresses\\Test\\Fixture\\' . $name . 'Fixture';
try {
$object = (new ReflectionClass($class))->getProperty('fields');
} catch (ReflectionException $e) {
continue;
}
$array = $object->getDefaultValue();
$constraints = $array['_constraints'] ?? [];
$indexes = $array['_indexes'] ?? [];
unset($array['_constraints'], $array['_indexes'], $array['_options']);
$table = [
'table' => $tableName,
'columns' => $array,
'constraints' => $constraints,
'indexes' => $indexes,
];
$tables[$tableName] = $table;
}
return $tables;

1
tests/schema.sql Normal file
View File

@@ -0,0 +1 @@
-- Test database schema for CakeAddresses

View File

@@ -0,0 +1,39 @@
<?php
namespace TestApp;
use Cake\Http\BaseApplication;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
class Application extends BaseApplication {
/**
* @inheritDoc
*/
public function bootstrap(): void {
$this->addPlugin('CakeAddresses');
}
/**
* @inheritDoc
*/
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue {
$middleware->add(new RoutingMiddleware($this));
return $middleware;
}
public function routes(RouteBuilder $routes): void
{
parent::routes($routes); // TODO: Change the autogenerated stub
$routes->setRouteClass(DashedRoute::class);
$routes->plugin('CakeAddresses', ['path' => '/cake-addresses'], function (RouteBuilder $pluginRoutes):void {
$pluginRoutes->fallbacks();
});
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace TestApp\Controller;
use Cake\Controller\Controller;
class AppController extends Controller {
/**
* @return void
*/
public function initialize(): void {
parent::initialize();
$this->loadComponent('Flash');
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace TestApp\View;
use Cake\View\View;
/**
* @property \TinyAuth\View\Helper\AuthUserHelper $AuthUser
*/
class AppView extends View {
}

View File

@@ -0,0 +1,44 @@
<?php
use Cake\Core\Configure;
use Cake\Error\Debugger;
$this->layout = 'error';
if (Configure::read('debug')):
$this->layout = 'dev_error';
$this->assign('title', $message);
$this->assign('templateName', 'error500.ctp');
$this->start('file');
?>
<?php if (!empty($error->queryString)) : ?>
<p class="notice">
<strong>SQL Query: </strong>
<?= h($error->queryString) ?>
</p>
<?php endif; ?>
<?php if (!empty($error->params)) : ?>
<strong>SQL Query Params: </strong>
<?php Debugger::dump($error->params) ?>
<?php endif; ?>
<?php if ($error instanceof Error) : ?>
<strong>Error in: </strong>
<?= sprintf('%s, line %s', str_replace(ROOT, 'ROOT', $error->getFile()), $error->getLine()) ?>
<?php endif; ?>
<?php
echo $this->element('auto_table_warning');
if (extension_loaded('xdebug')):
xdebug_print_function_stack();
endif;
$this->end();
endif;
?>
<h2><?= __d('cake', 'An Internal Error Has Occurred') ?></h2>
<p class="error">
<strong><?= __d('cake', 'Error') ?>: </strong>
<?= h($message) ?>
</p>

View File

@@ -0,0 +1,6 @@
<?php
/**
* @var \App\View\AppView $this
*/
?>
<?= $this->fetch('content') ?>

View File

@@ -0,0 +1,6 @@
<?php
/**
* @var \App\View\AppView $this
*/
?>
<?= $this->fetch('content') ?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 B