chore: remove pragmarx/countries-laravel dependency (#6237)
This commit is contained in:
@@ -9,7 +9,7 @@ on:
|
||||
types: [completed]
|
||||
|
||||
env:
|
||||
php-version: '8.1'
|
||||
php-version: '8.0'
|
||||
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -31,7 +31,7 @@ jobs:
|
||||
matrix:
|
||||
php-version: ['8.0', '8.1']
|
||||
connection: [mysql]
|
||||
testsuite: [Api, Feature, Unit-Models, Unit-Services]
|
||||
testsuite: [Api, Feature, Commands-Other, Commands-Scheduling, Unit-Models, Unit-Services]
|
||||
# exclude:
|
||||
# - php-version: '8.1'
|
||||
# testsuite: Feature
|
||||
|
||||
@@ -61,18 +61,18 @@ class ImportCSV extends Command
|
||||
$user = User::where('email', $this->argument('user'))->first();
|
||||
}
|
||||
|
||||
if (! file_exists($file)) {
|
||||
$this->error('You need to provide a valid file path.');
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (! $user) {
|
||||
$this->error('You need to provide a valid User ID or email address!');
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (! file_exists($file)) {
|
||||
$this->error('You need to provide a valid file path.');
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (is_string($file)) {
|
||||
$this->info("Importing CSV file {$file} to user {$user->id}");
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class ImportVCards extends Command
|
||||
// show an error and exist if the user does not exist
|
||||
$this->error('No user with that email.');
|
||||
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
$path = $this->option('path');
|
||||
@@ -63,7 +63,7 @@ class ImportVCards extends Command
|
||||
if (! $filesystem->exists($path) || ! $this->acceptedExtensions($filesystem, $path)) {
|
||||
$this->error('The provided vcard file was not found or is not valid!');
|
||||
|
||||
return;
|
||||
return -2;
|
||||
}
|
||||
|
||||
$importJob = $this->import($path, $user);
|
||||
|
||||
@@ -29,26 +29,28 @@ class SendTestEmail extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// retrieve the email from the option
|
||||
/** retrieve the email from the option.
|
||||
* @var string $email
|
||||
*/
|
||||
$email = $this->option('email');
|
||||
|
||||
// if no email was passed to the option, prompt the user to enter the email
|
||||
if (! $email) {
|
||||
$email = $this->ask('What email address should I send the test email to?');
|
||||
$email = (string) $this->ask('What email address should I send the test email to?');
|
||||
}
|
||||
|
||||
// Validate user provided email address
|
||||
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
||||
$this->error('Invalid email address: "'.$email.'".');
|
||||
$this->error("Invalid email address: \"$email\".");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
$this->info('Preparing and sending email to "'.$email.'"');
|
||||
$this->info("Preparing and sending email to \"$email\"");
|
||||
|
||||
// immediately deliver the test email (bypassing the queue)
|
||||
Mail::raw(
|
||||
'Hi '.$email.', you requested a test email from Monica.',
|
||||
"Hi $email, you requested a test email from Monica.",
|
||||
function ($message) use ($email) {
|
||||
$message->to($email)
|
||||
->subject('Monica email delivery test');
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Rinvex\Country\Country;
|
||||
use Rinvex\Country\CountryLoader;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use PragmaRX\CountriesLaravel\Package\Facade as Countries;
|
||||
use PragmaRX\Countries\Package\Support\Collection as Country;
|
||||
|
||||
class CountriesHelper
|
||||
{
|
||||
@@ -17,10 +16,10 @@ class CountriesHelper
|
||||
*/
|
||||
public static function getAll(): Collection
|
||||
{
|
||||
$x = Countries::all();
|
||||
$countries = $x->map(function ($item) {
|
||||
$x = collect(countries(true, true));
|
||||
$countries = $x->map(function (Country $item) {
|
||||
return [
|
||||
'id' => $item->cca2,
|
||||
'id' => $item->getIsoAlpha2(),
|
||||
'country' => static::getCommonNameLocale($item),
|
||||
];
|
||||
});
|
||||
@@ -48,61 +47,59 @@ class CountriesHelper
|
||||
* Find a country by the (english) name of the country.
|
||||
*
|
||||
* @param string $name Common name of a country
|
||||
* @return string cca2 code of the country
|
||||
* @return string iso_3166_1_alpha2 code of the country
|
||||
*/
|
||||
public static function find($name): string
|
||||
{
|
||||
$country = Countries::where('name.common', $name)->first();
|
||||
$country = collect(CountryLoader::where('name.common', $name));
|
||||
if ($country->count() === 0) {
|
||||
$country = Countries::where('cca2', mb_strtoupper($name))->first();
|
||||
$country = collect(CountryLoader::where('iso_3166_1_alpha2', mb_strtoupper($name)));
|
||||
}
|
||||
if ($country->count() === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $country->cca2;
|
||||
return (new Country($country->first()))->getIsoAlpha2();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the common name of country, in locale version.
|
||||
*
|
||||
* @param \ArrayAccess $country
|
||||
* @param \Rinvex\Country\Country $country
|
||||
* @return string
|
||||
*/
|
||||
private static function getCommonNameLocale($country): string
|
||||
private static function getCommonNameLocale(Country $country): string
|
||||
{
|
||||
$locale = App::getLocale();
|
||||
$lang = LocaleHelper::getLocaleAlpha($locale);
|
||||
|
||||
return Arr::get($country, 'translations.'.$lang.'.common',
|
||||
Arr::get($country, 'name.common', '')
|
||||
);
|
||||
return $country->getTranslation($lang)['common'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get country for a specific iso code.
|
||||
*
|
||||
* @param string $iso
|
||||
* @return Country|null the Country element
|
||||
* @return \Rinvex\Country\Country|null the Country element
|
||||
*/
|
||||
public static function getCountry($iso): ?Country
|
||||
{
|
||||
$country = Countries::where('cca2', mb_strtoupper($iso))->first();
|
||||
$country = collect(CountryLoader::where('iso_3166_1_alpha2', mb_strtoupper($iso)));
|
||||
if ($country->count() === 0) {
|
||||
$country = Countries::where('alt_spellings', mb_strtoupper($iso))->first();
|
||||
$country = collect(CountryLoader::where('alt_spellings', mb_strtoupper($iso)));
|
||||
}
|
||||
if ($country->count() === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $country;
|
||||
return new Country($country->first());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get country for a specific language.
|
||||
*
|
||||
* @param string $locale language code (iso)
|
||||
* @return Country|null the Country element
|
||||
* @return \Rinvex\Country\Country|null the Country element
|
||||
*/
|
||||
public static function getCountryFromLocale($locale): ?Country
|
||||
{
|
||||
@@ -113,22 +110,22 @@ class CountriesHelper
|
||||
|
||||
if (is_null($countryCode)) {
|
||||
$lang = LocaleHelper::getLocaleAlpha($locale);
|
||||
$country = Countries::whereISO639_3($lang);
|
||||
$country = collect(CountryLoader::where("languages.$lang", '>', '0'));
|
||||
if ($country->count() === 0) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
$country = Countries::where('cca2', $countryCode);
|
||||
$country = collect(CountryLoader::where('iso_3166_1_alpha2', mb_strtoupper($countryCode)));
|
||||
}
|
||||
|
||||
return $country->first();
|
||||
return new Country($country->first());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default country for a language.
|
||||
*
|
||||
* @param string $locale language code (iso)
|
||||
* @return string|null cca2 code
|
||||
* @return string|null iso_3166_1_alpha2 code
|
||||
*/
|
||||
private static function getDefaultCountryFromLocale($locale): ?string
|
||||
{
|
||||
@@ -174,7 +171,7 @@ class CountriesHelper
|
||||
{
|
||||
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
||||
// https://en.wikipedia.org/wiki/List_of_time_zones_by_country
|
||||
switch ($country->cca3) {
|
||||
switch ($country->getIsoAlpha3()) {
|
||||
case 'AUS':
|
||||
$timezone = 'Australia/Melbourne';
|
||||
break;
|
||||
@@ -197,7 +194,7 @@ class CountriesHelper
|
||||
$timezone = 'America/Chicago';
|
||||
break;
|
||||
default:
|
||||
$timezone = $country->hydrate('timezones')->timezones->first()->zone_name;
|
||||
$timezone = collect($country->getTimezones())->first();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class LocaleHelper
|
||||
|
||||
if (is_null($countryCode)) {
|
||||
$country = CountriesHelper::getCountryFromLocale($locale);
|
||||
$countryCode = $country->cca2;
|
||||
$countryCode = $country->getIsoAlpha2();
|
||||
}
|
||||
|
||||
return mb_strtoupper($countryCode);
|
||||
|
||||
@@ -14,7 +14,7 @@ class RequestHelper
|
||||
/**
|
||||
* Get client ip.
|
||||
*
|
||||
* @return array|string
|
||||
* @return array|string|null
|
||||
*/
|
||||
public static function ip()
|
||||
{
|
||||
|
||||
@@ -18,9 +18,6 @@ class Country extends JsonResource
|
||||
if (is_array($this->resource)) {
|
||||
$id = $this->resource['id'];
|
||||
$name = $this->resource['country'];
|
||||
} elseif ($this->resource instanceof \PragmaRX\Countries\Package\Support\Collection) {
|
||||
$id = $this->resource->id;
|
||||
$name = $this->resource->country;
|
||||
} else {
|
||||
$id = $this->resource;
|
||||
$name = CountriesHelper::get($this->resource);
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Models\Contact;
|
||||
use DateTime;
|
||||
use App\Traits\HasUuid;
|
||||
use App\Traits\Searchable;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Helpers\LocaleHelper;
|
||||
use App\Models\Account\Photo;
|
||||
@@ -22,7 +23,6 @@ use App\Models\Account\AddressBook;
|
||||
use App\Models\Instance\SpecialDate;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use IlluminateAgnostic\Arr\Support\Arr;
|
||||
use App\Models\Account\ActivityStatistic;
|
||||
use App\Models\Relationship\Relationship;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
@@ -15,12 +15,5 @@ class BroadcastServiceProvider extends ServiceProvider
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
/*
|
||||
* Authenticate the user's personal channel...
|
||||
*/
|
||||
Broadcast::channel('App.User.*', function ($user, $userId) {
|
||||
return (int) $user->id === (int) $userId;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Services\DavClient\Utils;
|
||||
|
||||
use App\Jobs\Dav\PushVCard;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Jobs\Dav\DeleteVCard;
|
||||
use Illuminate\Support\Collection;
|
||||
use IlluminateAgnostic\Collection\Support\Arr;
|
||||
use App\Services\DavClient\Utils\Model\SyncDto;
|
||||
use App\Services\DavClient\Utils\Model\ContactDto;
|
||||
use App\Services\DavClient\Utils\Traits\WithSyncDto;
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace App\Services\DavClient\Utils;
|
||||
|
||||
use App\Jobs\Dav\PushVCard;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Support\Collection;
|
||||
use IlluminateAgnostic\Collection\Support\Arr;
|
||||
use App\Services\DavClient\Utils\Model\SyncDto;
|
||||
use App\Services\DavClient\Utils\Model\ContactDto;
|
||||
use App\Services\DavClient\Utils\Traits\WithSyncDto;
|
||||
|
||||
@@ -104,11 +104,11 @@ class CreateUser extends BaseService
|
||||
}
|
||||
|
||||
// Currency
|
||||
if (! is_null($currencyCode)) {
|
||||
$this->associateCurrency($user, $currencyCode);
|
||||
} elseif (! is_null($country)) {
|
||||
foreach ($country->currencies as $currency) {
|
||||
if ($this->associateCurrency($user, $currency)) {
|
||||
if ((! is_null($currencyCode)
|
||||
&& ! $this->associateCurrency($user, $currencyCode))
|
||||
|| ! is_null($country)) {
|
||||
foreach ($country->getCurrencies() as $currency) {
|
||||
if ($this->associateCurrency($user, $currency['iso_4217_code'])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ class CreateUser extends BaseService
|
||||
|
||||
// Temperature scale
|
||||
if (! is_null($country)) {
|
||||
switch ($country->cca2) {
|
||||
switch ($country->getIsoAlpha2()) {
|
||||
case 'US':
|
||||
case 'BZ':
|
||||
case 'KY':
|
||||
|
||||
+2
-2
@@ -40,11 +40,11 @@
|
||||
"monicahq/laravel-sabre": "^1.2",
|
||||
"ok/ipstack-client": "^1.2",
|
||||
"phar-io/version": "^3.1",
|
||||
"pragmarx/countries-laravel": "^0",
|
||||
"pragmarx/google2fa": "^8.0",
|
||||
"pragmarx/google2fa-laravel": "^1.3",
|
||||
"pragmarx/random": "^0",
|
||||
"predis/predis": "^1.1",
|
||||
"rinvex/countries": "^8.1",
|
||||
"sabre/dav": "^4.0",
|
||||
"sentry/sentry-laravel": "^2.0",
|
||||
"spatie/macroable": "^1.0",
|
||||
@@ -74,7 +74,7 @@
|
||||
"nunomaduro/larastan": "^0",
|
||||
"phpunit/phpcov": "^8.0",
|
||||
"phpunit/phpunit": "^9.0",
|
||||
"psalm/plugin-laravel": "^1.4",
|
||||
"psalm/plugin-laravel": "^1.0",
|
||||
"roave/security-advisories": "dev-master",
|
||||
"thecodingmachine/phpstan-safe-rule": "^1.0",
|
||||
"vimeo/psalm": "^4.0"
|
||||
|
||||
Generated
+1069
-1452
File diff suppressed because it is too large
Load Diff
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'cache' => [
|
||||
'enabled' => true,
|
||||
|
||||
'service' => PragmaRX\Countries\Package\Services\Cache\Service::class,
|
||||
|
||||
'duration' => 180,
|
||||
|
||||
'directory' => sys_get_temp_dir().'/__PRAGMARX_COUNTRIES__/cache',
|
||||
],
|
||||
|
||||
'hydrate' => [
|
||||
'before' => false,
|
||||
|
||||
'after' => false,
|
||||
|
||||
'elements' => [
|
||||
'borders' => false,
|
||||
'cities' => false,
|
||||
'currencies' => false,
|
||||
'flag' => false,
|
||||
'geometry' => false,
|
||||
'states' => false,
|
||||
'taxes' => false,
|
||||
'timezones' => true,
|
||||
'timezones_times' => false,
|
||||
'topology' => false,
|
||||
],
|
||||
],
|
||||
|
||||
'maps' => [
|
||||
'lca3' => 'cca3',
|
||||
'currencies' => 'currency',
|
||||
],
|
||||
|
||||
'validation' => [
|
||||
'enabled' => false,
|
||||
'rules' => [
|
||||
'country' => 'name.common',
|
||||
'name' => 'name.common',
|
||||
'nameCommon' => 'name.common',
|
||||
'cca2',
|
||||
'cca2',
|
||||
'cca3',
|
||||
'ccn3',
|
||||
'cioc',
|
||||
'currencies' => 'ISO4217',
|
||||
'language_short' => 'ISO639_3',
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
@@ -28,15 +28,17 @@ class DefaultTemperatureScale extends Migration
|
||||
$currentLocale = $user->locale;
|
||||
}
|
||||
|
||||
switch ($country->cca2) {
|
||||
case 'US':
|
||||
case 'BZ':
|
||||
case 'KY':
|
||||
$user->temperature_scale = 'fahrenheit';
|
||||
break;
|
||||
default:
|
||||
$user->temperature_scale = 'celsius';
|
||||
break;
|
||||
if ($country !== null) {
|
||||
switch ($country->getIsoAlpha2()) {
|
||||
case 'US':
|
||||
case 'BZ':
|
||||
case 'KY':
|
||||
$user->temperature_scale = 'fahrenheit';
|
||||
break;
|
||||
default:
|
||||
$user->temperature_scale = 'celsius';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$user->save();
|
||||
|
||||
@@ -12,7 +12,7 @@ class FakeUserTableSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Account::createDefault('John', 'Doe', 'admin@admin.com', 'admin0');
|
||||
Account::createDefault('Blank', 'State', 'blank@blank.com', 'blank0');
|
||||
Account::createDefault('John', 'Doe', 'admin@admin.com', 'admin0', null, 'en');
|
||||
Account::createDefault('Blank', 'State', 'blank@blank.com', 'blank0', null, 'en');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ parameters:
|
||||
ignoreErrors:
|
||||
- '#Call to an undefined method Illuminate\\View\\View::with[a-zA-Z0-9\\_]+\(\)\.#'
|
||||
- '#Access to an undefined property Sabre\\VObject\\Component\\[a-zA-Z0-9\\_]+::\$[a-zA-Z0-9_]+\.#'
|
||||
- '#Access to an undefined property PragmaRX\\Countries\\Package\\Support\\Collection::\$[a-zA-Z0-9_]+\.#'
|
||||
|
||||
- message: '#Call to an undefined static method PragmaRX\\CountriesLaravel\\Package\\Facade::[a-zA-Z0-9_]+\(\)\.#'
|
||||
path: */Helpers/CountriesHelper.php
|
||||
- message: '#Access to an undefined property Illuminate\\Support\\Fluent::\$[a-zA-Z0-9_]+\.#'
|
||||
path: */Http/Location/Drivers/CloudflareDriver.php
|
||||
- message: '#Access to an undefined property App\\Interfaces\\IsJournalableInterface::\$account_id\.#'
|
||||
|
||||
+10
-1
@@ -25,10 +25,19 @@
|
||||
</testsuite>
|
||||
|
||||
<testsuite name="Feature">
|
||||
<directory suffix="Test.php">./tests/Commands</directory>
|
||||
<directory suffix="Test.php">./tests/Feature</directory>
|
||||
</testsuite>
|
||||
|
||||
<testsuite name="Commands-Other">
|
||||
<directory suffix="Test.php">./tests/Commands/OneTime</directory>
|
||||
<directory suffix="Test.php">./tests/Commands/Other</directory>
|
||||
</testsuite>
|
||||
|
||||
<testsuite name="Commands-Scheduling">
|
||||
<directory suffix="Test.php">./tests/Commands/Scheduling</directory>
|
||||
<directory suffix="Test.php">./tests/Commands/Tests</directory>
|
||||
</testsuite>
|
||||
|
||||
<testsuite name="Unit-Models">
|
||||
<directory suffix="Test.php">./tests/Unit/Controllers</directory>
|
||||
<directory suffix="Test.php">./tests/Unit/Events</directory>
|
||||
|
||||
@@ -112,11 +112,9 @@
|
||||
</errorLevel>
|
||||
</UndefinedPropertyAssignment>
|
||||
|
||||
<UndefinedMagicPropertyAssignment>
|
||||
<errorLevel type="suppress">
|
||||
<file name="database/migrations/2017_08_06_153253_move_kids_to_contacts.php" />
|
||||
</errorLevel>
|
||||
</UndefinedMagicPropertyAssignment>
|
||||
<UndefinedMagicPropertyAssignment errorLevel="suppress" />
|
||||
<UndefinedThisPropertyFetch errorLevel="suppress" />
|
||||
<UndefinedThisPropertyAssignment errorLevel="suppress" />
|
||||
|
||||
<UndefinedPropertyFetch>
|
||||
<errorLevel type="suppress">
|
||||
@@ -136,6 +134,10 @@
|
||||
<InvalidReturnType>
|
||||
<errorLevel type="suppress">
|
||||
<file name="app/Http/Controllers/Auth/RegisterController.php" />
|
||||
<file name="app/Services/Account/Activity/ActivityType/CreateActivityType.php" />
|
||||
<file name="app/Services/Account/Activity/ActivityTypeCategory/CreateActivityTypeCategory.php" />
|
||||
<file name="app/Services/Account/LifeEvent/LifeEventType/CreateLifeEventType.php" />
|
||||
<file name="app/Services/Contact/LifeEvent/CreateLifeEvent.php" />
|
||||
</errorLevel>
|
||||
</InvalidReturnType>
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class ApiCountriesTest extends ApiTestCase
|
||||
'data' => ['*' => $this->jsonCountries],
|
||||
]);
|
||||
$response->assertJsonFragment([
|
||||
'DEU' => [
|
||||
'de' => [
|
||||
'id' => 'DE',
|
||||
'iso' => 'DE',
|
||||
'name' => 'Germany',
|
||||
@@ -38,7 +38,7 @@ class ApiCountriesTest extends ApiTestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_gets_a_specific_country_in_a_specific_country()
|
||||
public function it_gets_a_specific_country_in_a_specific_locale()
|
||||
{
|
||||
$user = $this->signin();
|
||||
$user->locale = 'fr';
|
||||
@@ -51,7 +51,7 @@ class ApiCountriesTest extends ApiTestCase
|
||||
'data' => ['*' => $this->jsonCountries],
|
||||
]);
|
||||
$response->assertJsonFragment([
|
||||
'DEU' => [
|
||||
'de' => [
|
||||
'id' => 'DE',
|
||||
'iso' => 'DE',
|
||||
'name' => 'Allemagne',
|
||||
|
||||
+3
-4
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\OneTime;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use App\Models\Account\Photo;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
@@ -49,7 +48,7 @@ class MoveAvatarsToPhotosDirectoryTest extends TestCase
|
||||
|
||||
Storage::disk('public')->assertExists('avatars/avatar.jpg');
|
||||
|
||||
$exitCode = Artisan::call('monica:moveavatarstophotosdirectory');
|
||||
$this->artisan('monica:moveavatarstophotosdirectory')->run();
|
||||
|
||||
Storage::disk('public')->assertMissing('avatars/avatar.jpg');
|
||||
Storage::disk('public')->assertMissing('avatars/avatar_110.jpg');
|
||||
@@ -79,7 +78,7 @@ class MoveAvatarsToPhotosDirectoryTest extends TestCase
|
||||
$contact->has_avatar = true;
|
||||
$contact->save();
|
||||
|
||||
$exitCode = Artisan::call('monica:moveavatarstophotosdirectory');
|
||||
$this->artisan('monica:moveavatarstophotosdirectory')->run();
|
||||
|
||||
Storage::disk('public')->assertMissing('avatars/avatar.jpg');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Other;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
@@ -90,7 +90,7 @@ class CleanCommandTest extends TestCase
|
||||
'timestamp' => now()->addDays(-10),
|
||||
]);
|
||||
|
||||
$this->artisan('monica:clean --dry-run')->run();
|
||||
$this->artisan('monica:clean', ['--dry-run' => true])->run();
|
||||
|
||||
$this->assertDatabaseHas('synctoken', [
|
||||
'id' => $s1->id,
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Other;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
@@ -15,11 +15,11 @@ class CreateAccountTest extends TestCase
|
||||
public function it_creates_account()
|
||||
{
|
||||
$email = 'user1@example.com';
|
||||
$this->artisan('account:create', ['--email' => 'user1@example.com', '--password' => 'astrongpassword']);
|
||||
$this->artisan('account:create', ['--email' => 'user1@example.com', '--password' => 'astrongpassword'])
|
||||
->run();
|
||||
|
||||
$user = User::where('email', '=', $email)->first();
|
||||
$this->assertNotEmpty($user);
|
||||
$account = $user->account;
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -33,35 +33,28 @@ class CreateAccountTest extends TestCase
|
||||
'--password' => 'astrongpassword',
|
||||
'--firstname' => $firstname,
|
||||
'--lastname' => $lastname,
|
||||
]);
|
||||
])->run();
|
||||
|
||||
$user = User::where('email', '=', $email)->first();
|
||||
$this->assertNotEmpty($user);
|
||||
$account = $user->account;
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_creation_without_email()
|
||||
{
|
||||
$firstname = 'firstname';
|
||||
$lastname = 'lastname';
|
||||
$this->artisan('account:create', [
|
||||
'--password' => 'astrongpassword',
|
||||
])
|
||||
->expectsOutput(CreateAccount::ERROR_MISSING_EMAIL)
|
||||
->doesntExpectOutput(CreateAccount::ERROR_MISSING_PASSWORD);
|
||||
$this->artisan('account:create', ['--password' => 'astrongpassword'])
|
||||
->expectsOutput(CreateAccount::ERROR_MISSING_EMAIL)
|
||||
->doesntExpectOutput(CreateAccount::ERROR_MISSING_PASSWORD)
|
||||
->run();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_fails_creation_without_password()
|
||||
{
|
||||
$email = 'user1@example.com';
|
||||
$firstname = 'firstname';
|
||||
$lastname = 'lastname';
|
||||
$this->artisan('account:create', [
|
||||
'--email' => $email,
|
||||
])
|
||||
->expectsOutput(CreateAccount::ERROR_MISSING_PASSWORD)
|
||||
->doesntExpectOutput(CreateAccount::ERROR_MISSING_EMAIL);
|
||||
$this->artisan('account:create', ['--email' => $email])
|
||||
->expectsOutput(CreateAccount::ERROR_MISSING_PASSWORD)
|
||||
->doesntExpectOutput(CreateAccount::ERROR_MISSING_EMAIL)
|
||||
->run();
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Other;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
use Mockery\MockInterface;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use App\Services\DavClient\CreateAddressBookSubscription;
|
||||
|
||||
@@ -34,11 +33,11 @@ class CreateAddressBookSubscriptionTest extends TestCase
|
||||
});
|
||||
});
|
||||
|
||||
Artisan::call('monica:newaddressbooksubscription', [
|
||||
$this->artisan('monica:newaddressbooksubscription', [
|
||||
'--email' => $user->email,
|
||||
'--url' => 'https://test',
|
||||
'--login' => 'login',
|
||||
'--password' => 'password',
|
||||
]);
|
||||
])->run();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Other;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
@@ -16,7 +15,6 @@ class ImportCSVTest extends TestCase
|
||||
/** @test */
|
||||
public function csv_import_contacts()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
Storage::fake('public');
|
||||
|
||||
$user = $this->getUser();
|
||||
@@ -24,7 +22,12 @@ class ImportCSVTest extends TestCase
|
||||
|
||||
$totalContacts = Contact::where('account_id', $user->account_id)->count();
|
||||
|
||||
$exitCode = $this->artisan('import:csv '.$user->email.' '.$path);
|
||||
$this->artisan('import:csv', [
|
||||
'user' => $user->email,
|
||||
'file' => $path,
|
||||
])
|
||||
->assertSuccessful()
|
||||
->run();
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'first_name' => 'Bono',
|
||||
@@ -45,49 +48,39 @@ class ImportCSVTest extends TestCase
|
||||
$totalContacts + 1,
|
||||
Contact::where('account_id', $user->account_id)->count()
|
||||
);
|
||||
|
||||
$this->assertEquals(0, $exitCode);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function csv_import_validates_user()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$path = base_path('tests/stubs/single_contact_stub.csv');
|
||||
|
||||
$command = m::mock('\App\Console\Commands\ImportCSV[error]', [new \Illuminate\Filesystem\Filesystem()]);
|
||||
|
||||
$command->shouldReceive('error')->once()->with('You need to provide a valid User ID or email address!');
|
||||
|
||||
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
|
||||
|
||||
$exitCode = $this->artisan('import:csv test@test.com '.$path);
|
||||
|
||||
$this->assertEquals(-1, $exitCode);
|
||||
$this->artisan('import:csv', [
|
||||
'user' => 'test@test.com',
|
||||
'file' => $path,
|
||||
])
|
||||
->assertFailed()
|
||||
->expectsOutput('You need to provide a valid User ID or email address!')
|
||||
->run();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function csv_import_validates_file()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$user = $this->getUser();
|
||||
|
||||
$command = m::mock('\App\Console\Commands\ImportCSV[error]', [new \Illuminate\Filesystem\Filesystem()]);
|
||||
|
||||
$command->shouldReceive('error')->once()->with('You need to provide a valid file path.');
|
||||
|
||||
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
|
||||
|
||||
$exitCode = $this->artisan('import:csv '.$user->email.' xxx');
|
||||
|
||||
$this->assertEquals(-1, $exitCode);
|
||||
$this->artisan('import:csv', [
|
||||
'user' => $user->email,
|
||||
'file' => 'xxx',
|
||||
])
|
||||
->assertFailed()
|
||||
->expectsOutput('You need to provide a valid file path.')
|
||||
->run();
|
||||
}
|
||||
|
||||
private function getUser()
|
||||
{
|
||||
$account = Account::createDefault('John', 'Doe', 'johndoe@example.com', 'secret');
|
||||
$account = Account::createDefault('John', 'Doe', 'johndoe@example.com', 'secret', null, 'en');
|
||||
|
||||
return $account->users()->first();
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Other;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
@@ -16,43 +15,28 @@ class ImportVCardsTest extends TestCase
|
||||
/** @test */
|
||||
public function it_validates_user()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$path = base_path('tests/stubs/vcard_stub.vcf');
|
||||
|
||||
$command = m::mock('\App\Console\Commands\ImportVCards[error]', [new \Illuminate\Filesystem\Filesystem()]);
|
||||
|
||||
$command->shouldReceive('error')->once()->with('No user with that email.');
|
||||
|
||||
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
|
||||
|
||||
$exitCode = $this->artisan('import:vcard', ['--user' => 'notfound@example.com', '--path' => $path, '--no-interaction' => true]);
|
||||
|
||||
$this->assertEquals(0, $exitCode);
|
||||
$this->artisan('import:vcard', ['--user' => 'notfound@example.com', '--path' => $path, '--no-interaction' => true])
|
||||
->assertFailed()
|
||||
->expectsOutput('No user with that email.')
|
||||
->run();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_validates_file()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$user = $this->getUser();
|
||||
|
||||
$command = m::mock('\App\Console\Commands\ImportVCards[error]', [new \Illuminate\Filesystem\Filesystem()]);
|
||||
|
||||
$command->shouldReceive('error')->once()->with('The provided vcard file was not found or is not valid!');
|
||||
|
||||
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
|
||||
|
||||
$exitCode = $this->artisan('import:vcard', ['--user' => $user->email, '--path' => 'not_found', '--no-interaction' => true]);
|
||||
|
||||
$this->assertEquals(0, $exitCode);
|
||||
$this->artisan('import:vcard', ['--user' => $user->email, '--path' => 'not_found', '--no-interaction' => true])
|
||||
->assertFailed()
|
||||
->expectsOutput('The provided vcard file was not found or is not valid!')
|
||||
->run();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_imports_contacts()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
Storage::fake('public');
|
||||
|
||||
$user = $this->getUser();
|
||||
@@ -60,7 +44,9 @@ class ImportVCardsTest extends TestCase
|
||||
|
||||
$totalContacts = Contact::where('account_id', $user->account_id)->count();
|
||||
|
||||
$exitCode = $this->artisan('import:vcard', ['--user' => $user->email, '--path' => $path, '--no-interaction' => true]);
|
||||
$this->artisan('import:vcard', ['--user' => $user->email, '--path' => $path, '--no-interaction' => true])
|
||||
->assertSuccessful()
|
||||
->run();
|
||||
|
||||
$this->assertDatabaseHas('contacts', [
|
||||
'first_name' => 'John',
|
||||
@@ -107,13 +93,11 @@ class ImportVCardsTest extends TestCase
|
||||
$totalContacts + 3,
|
||||
Contact::where('account_id', $user->account_id)->count()
|
||||
);
|
||||
|
||||
$this->assertEquals(0, $exitCode);
|
||||
}
|
||||
|
||||
private function getUser()
|
||||
{
|
||||
$account = Account::createDefault('John', 'Doe', 'johndoe@example.com', 'secret');
|
||||
$account = Account::createDefault('John', 'Doe', 'johndoe@example.com', 'secret', null, 'en');
|
||||
|
||||
return $account->users()->first();
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Other;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Console\Commands\Helpers\Command;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
@@ -17,7 +16,7 @@ class UpdateCommandTest extends TestCase
|
||||
/** @var \Tests\Helpers\CommandCallerFake */
|
||||
$fake = Command::fake();
|
||||
|
||||
Artisan::call('monica:update');
|
||||
$this->artisan('monica:update')->run();
|
||||
|
||||
$this->assertCount(9, $fake->buffer);
|
||||
$this->assertCommandContains($fake->buffer[0], 'Maintenance mode: on', 'php artisan down');
|
||||
@@ -37,7 +36,7 @@ class UpdateCommandTest extends TestCase
|
||||
/** @var \Tests\Helpers\CommandCallerFake */
|
||||
$fake = Command::fake();
|
||||
|
||||
Artisan::call('monica:update', ['--composer-install' => true]);
|
||||
$this->artisan('monica:update', ['--composer-install' => true])->run();
|
||||
|
||||
$this->assertCount(10, $fake->buffer);
|
||||
$this->assertCommandContains($fake->buffer[0], 'Maintenance mode: on', 'php artisan down');
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Scheduling;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Database\QueryException;
|
||||
@@ -16,7 +16,7 @@ class CalculateStatisticsTest extends TestCase
|
||||
$runsWell = true;
|
||||
|
||||
try {
|
||||
$this->artisan('monica:calculatestatistics');
|
||||
$this->artisan('monica:calculatestatistics')->run();
|
||||
} catch (QueryException $e) {
|
||||
$runsWell = false;
|
||||
}
|
||||
+2
-3
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Scheduling;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Jobs\SynchronizeAddressBooks;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Models\Account\AddressBookSubscription;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
@@ -20,7 +19,7 @@ class DavClientsUpdateTest extends TestCase
|
||||
|
||||
$subscription = AddressBookSubscription::factory()->create();
|
||||
|
||||
Artisan::call('monica:davclients', []);
|
||||
$this->artisan('monica:davclients')->run();
|
||||
|
||||
Queue::assertPushed(SynchronizeAddressBooks::class, function ($job) use ($subscription) {
|
||||
return $job->subscription->id === $subscription->id;
|
||||
+26
-3
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Scheduling;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\Instance\Instance;
|
||||
@@ -34,7 +34,7 @@ class PingVersionServerTest extends TestCase
|
||||
'https://version.test/*' => Http::response($ret, 200),
|
||||
]);
|
||||
|
||||
$this->artisan('monica:ping');
|
||||
$this->artisan('monica:ping')->run();
|
||||
|
||||
$instance->refresh();
|
||||
|
||||
@@ -67,7 +67,7 @@ class PingVersionServerTest extends TestCase
|
||||
'https://version.test/*' => Http::response($ret, 200),
|
||||
]);
|
||||
|
||||
$this->artisan('monica:ping');
|
||||
$this->artisan('monica:ping')->run();
|
||||
|
||||
$instance->refresh();
|
||||
|
||||
@@ -75,4 +75,27 @@ class PingVersionServerTest extends TestCase
|
||||
$this->assertNull($instance->latest_release_notes);
|
||||
$this->assertNull($instance->number_of_versions_since_current_version);
|
||||
}
|
||||
|
||||
/**
|
||||
* If an instance sets `version_check` env variable to false, the command
|
||||
* should exit with 0.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_check_version_set_to_false_disables_the_check()
|
||||
{
|
||||
config(['monica.weekly_ping_server_url' => 'https://version.test/ping']);
|
||||
config(['monica.app_version' => '2.9.0']);
|
||||
config(['monica.check_version' => false]);
|
||||
|
||||
$fake = Http::fake([
|
||||
'https://version.test/*' => Http::response([], 500),
|
||||
]);
|
||||
|
||||
$this->artisan('monica:ping')
|
||||
->assertSuccessful()
|
||||
->run();
|
||||
|
||||
$fake->assertNothingSent();
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Scheduling;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
@@ -10,7 +10,6 @@ use App\Models\Contact\Contact;
|
||||
use App\Models\Contact\Reminder;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use App\Models\Contact\ReminderOutbox;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Jobs\Reminder\NotifyUserAboutReminder;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
@@ -42,7 +41,7 @@ class SendRemindersTest extends TestCase
|
||||
'planned_date' => '2017-01-01',
|
||||
]);
|
||||
|
||||
$exitCode = Artisan::call('send:reminders', []);
|
||||
$this->artisan('send:reminders')->run();
|
||||
Bus::assertDispatched(NotifyUserAboutReminder::class);
|
||||
}
|
||||
|
||||
@@ -73,7 +72,7 @@ class SendRemindersTest extends TestCase
|
||||
'planned_date' => '2017-01-01',
|
||||
]);
|
||||
|
||||
$exitCode = Artisan::call('send:reminders', []);
|
||||
$this->artisan('send:reminders')->run();
|
||||
Bus::assertNotDispatched(NotifyUserAboutReminder::class);
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Scheduling;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Jobs\StayInTouch\ScheduleStayInTouch;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
@@ -29,7 +28,7 @@ class SendStayInTouchTest extends TestCase
|
||||
'stay_in_touch_frequency' => 30,
|
||||
]);
|
||||
|
||||
$exitCode = Artisan::call('send:stay_in_touch', []);
|
||||
$this->artisan('send:stay_in_touch')->run();
|
||||
|
||||
Bus::assertDispatched(ScheduleStayInTouch::class);
|
||||
}
|
||||
@@ -48,7 +47,7 @@ class SendStayInTouchTest extends TestCase
|
||||
'stay_in_touch_frequency' => 30,
|
||||
]);
|
||||
|
||||
$exitCode = Artisan::call('send:stay_in_touch', []);
|
||||
$this->artisan('send:stay_in_touch')->run();
|
||||
|
||||
Bus::assertNotDispatched(ScheduleStayInTouch::class);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
|
||||
use Mockery as m;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SendTestEmailTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function error_for_bad_email()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$exampleEmail = 'no.at.symbol';
|
||||
|
||||
$command = m::mock('\App\Console\Commands\SendTestEmail[error]');
|
||||
|
||||
$command
|
||||
->shouldReceive('error')
|
||||
->once()
|
||||
->with("Invalid email address: \"$exampleEmail\".");
|
||||
|
||||
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
|
||||
|
||||
$exitCode = $this->artisan('monica:test-email', ['--email' => $exampleEmail]);
|
||||
$this->assertEquals(-1, $exitCode);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function command_prompts_for_email()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$command = m::mock('\App\Console\Commands\SendTestEmail[ask]');
|
||||
|
||||
$command
|
||||
->shouldReceive('ask')
|
||||
->once()
|
||||
->with('What email address should I send the test email to?');
|
||||
|
||||
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
|
||||
|
||||
$exitCode = $this->artisan('monica:test-email');
|
||||
$this->assertEquals(-1, $exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* test deactivated.
|
||||
*
|
||||
* Required to prevent alias mock breaking other tests:
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function command_attempts_to_send_email()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$exampleEmail = 'test@example.org';
|
||||
|
||||
$externalMock = m::mock('alias:\Illuminate\Support\Facades\Mail');
|
||||
$externalMock
|
||||
->shouldReceive('raw')
|
||||
->once()
|
||||
->with("Hi $exampleEmail, you requested a test email from Monica.", m::any());
|
||||
|
||||
$command = m::mock('\App\Console\Commands\SendTestEmail[Mail::raw]');
|
||||
|
||||
$this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
|
||||
|
||||
$exitCode = $this->artisan('monica:test-email', ['--email' => $exampleEmail]);
|
||||
$this->assertEquals(0, $exitCode);
|
||||
}
|
||||
}
|
||||
+22
-18
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Tests;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use App\Console\Commands\Helpers\Command;
|
||||
use Laravel\Passport\PersonalAccessClient;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
@@ -12,21 +11,28 @@ class PassportCommandTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (! file_exists(base_path('storage/oauth-private.key')) || ! file_exists(base_path('storage/oauth-public.key'))) {
|
||||
$this->markTestSkipped('Run "php artisan key:generate" before executing these tests.');
|
||||
}
|
||||
|
||||
foreach (PersonalAccessClient::all() as $client) {
|
||||
$client->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function passport_command_create()
|
||||
{
|
||||
/** @var \Tests\Helpers\CommandCallerFake */
|
||||
$fake = Command::fake();
|
||||
|
||||
$app = $this->createApplication();
|
||||
$app->make('config')->set(['passport.private_key' => '', 'passport.public_key' => '']);
|
||||
foreach (PersonalAccessClient::all() as $client) {
|
||||
$client->delete();
|
||||
}
|
||||
$this->artisan('monica:passport')->run();
|
||||
|
||||
Artisan::call('monica:passport');
|
||||
|
||||
$this->assertCount(1, $fake->buffer);
|
||||
$this->assertCount(1, $fake->buffer, $fake->buffer->implode(','));
|
||||
$this->assertCommandContains($fake->buffer[0], '✓ Creating personal access client', 'php artisan passport:client');
|
||||
}
|
||||
|
||||
@@ -36,13 +42,11 @@ class PassportCommandTest extends TestCase
|
||||
/** @var \Tests\Helpers\CommandCallerFake */
|
||||
$fake = Command::fake();
|
||||
|
||||
$app = $this->createApplication();
|
||||
$app->make('config')->set(['passport.private_key' => '', 'passport.public_key' => '']);
|
||||
PersonalAccessClient::create();
|
||||
|
||||
Artisan::call('monica:passport');
|
||||
$this->artisan('monica:passport')->run();
|
||||
|
||||
$this->assertCount(0, $fake->buffer);
|
||||
$this->assertCount(0, $fake->buffer, $fake->buffer->implode(','));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -51,12 +55,12 @@ class PassportCommandTest extends TestCase
|
||||
/** @var \Tests\Helpers\CommandCallerFake */
|
||||
$fake = Command::fake();
|
||||
|
||||
$app = $this->createApplication();
|
||||
$app->make('config')->set(['passport.private_key' => '-', 'passport.public_key' => '-']);
|
||||
config(['passport.private_key' => '-', 'passport.public_key' => '-']);
|
||||
|
||||
Artisan::call('monica:passport');
|
||||
$this->artisan('monica:passport')->run();
|
||||
|
||||
$this->assertCount(0, $fake->buffer);
|
||||
$this->assertCount(1, $fake->buffer, $fake->buffer->implode(','));
|
||||
$this->assertCommandContains($fake->buffer[0], '✓ Creating personal access client', 'php artisan passport:client');
|
||||
}
|
||||
|
||||
private function assertCommandContains($array, $message, $command)
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands\Tests;
|
||||
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class SendTestEmailTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function error_for_bad_email()
|
||||
{
|
||||
$exampleEmail = 'no.at.symbol';
|
||||
|
||||
$this->artisan('monica:test-email', ['--email' => $exampleEmail])
|
||||
->expectsOutput("Invalid email address: \"$exampleEmail\".")
|
||||
->assertFailed()
|
||||
->run();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function command_prompts_for_email()
|
||||
{
|
||||
$exampleEmail = 'no.at.symbol';
|
||||
|
||||
$this->artisan('monica:test-email')
|
||||
->expectsQuestion('What email address should I send the test email to?', $exampleEmail)
|
||||
->expectsOutput("Invalid email address: \"$exampleEmail\".")
|
||||
->assertFailed()
|
||||
->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function command_attempts_to_send_email()
|
||||
{
|
||||
$exampleEmail = 'test@example.org';
|
||||
|
||||
Mail::shouldReceive('raw')
|
||||
->once()
|
||||
->withArgs(function ($message, $closure) use ($exampleEmail) {
|
||||
$this->assertEquals(
|
||||
"Hi $exampleEmail, you requested a test email from Monica.",
|
||||
$message
|
||||
);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$this->artisan('monica:test-email', ['--email' => $exampleEmail])
|
||||
->assertSuccessful()
|
||||
->run();
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
namespace Tests\Commands\Tests;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User\User;
|
||||
@@ -14,12 +14,10 @@ class SetupFrontEndTestUserTest extends TestCase
|
||||
/** @test */
|
||||
public function it_create_a_test_user()
|
||||
{
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$accountCount = Account::count();
|
||||
$userCount = User::count();
|
||||
|
||||
$exitCode = $this->artisan('setup:frontendtestuser');
|
||||
$this->artisan('setup:frontendtestuser')->run();
|
||||
|
||||
$this->assertEquals($accountCount + 1, Account::count());
|
||||
$this->assertEquals($userCount + 1, User::count());
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Tests\FeatureTestCase;
|
||||
use App\Models\Contact\Reminder;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ReminderTest extends FeatureTestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_it_calculates_next_expected_date_in_timezone()
|
||||
{
|
||||
$user = $this->signin();
|
||||
$user->timezone = 'Europe/Paris';
|
||||
$user->save();
|
||||
|
||||
$reminder = new Reminder;
|
||||
$reminder->initial_date = '1980-05-01';
|
||||
$reminder->frequency_type = 'year';
|
||||
$reminder->frequency_number = 1;
|
||||
|
||||
Carbon::setTestNow(Carbon::create(2000, 4, 30, 21, 59, 59));
|
||||
$this->assertEquals(
|
||||
'2000-05-01',
|
||||
$reminder->calculateNextExpectedDateOnTimezone()->toDateString()
|
||||
);
|
||||
|
||||
Carbon::setTestNow(Carbon::create(2000, 4, 30, 22, 00, 00));
|
||||
$this->assertEquals(
|
||||
'2001-05-01',
|
||||
$reminder->calculateNextExpectedDateOnTimezone()->toDateString()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\FeatureTestCase;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class VersionCheckTest extends FeatureTestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* If an instance sets `version_check` env variable to false, the command
|
||||
* should exit with 0.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_check_version_set_to_false_disables_the_check()
|
||||
{
|
||||
config(['monica.check_version' => false]);
|
||||
$this->withoutMockingConsoleOutput();
|
||||
|
||||
$resultCommand = $this->artisan('monica:ping');
|
||||
$this->assertEquals(0, $resultCommand);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class CountryHelperTest extends FeatureTestCase
|
||||
$this->assertNotNull($country);
|
||||
$this->assertEquals(
|
||||
$expect,
|
||||
$country->cca2
|
||||
$country->getIsoAlpha2()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -85,4 +85,41 @@ class CountryHelperTest extends FeatureTestCase
|
||||
['fr-BE', 'BE'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider timezoneFromLocaleProvider
|
||||
* @test
|
||||
*/
|
||||
public function it_get_default_timezone($locale, $expect)
|
||||
{
|
||||
$country = CountriesHelper::getCountryFromLocale($locale);
|
||||
$timezone = CountriesHelper::getDefaultTimezone($country);
|
||||
|
||||
$this->assertNotNull($timezone);
|
||||
$this->assertEquals(
|
||||
$expect,
|
||||
$timezone
|
||||
);
|
||||
}
|
||||
|
||||
public function timezoneFromLocaleProvider()
|
||||
{
|
||||
return [
|
||||
['en', 'America/Chicago'],
|
||||
['cs', 'Europe/Prague'],
|
||||
['he', 'Asia/Jerusalem'],
|
||||
['zh', 'Asia/Shanghai'],
|
||||
['de', 'Europe/Berlin'],
|
||||
['es', 'Europe/Madrid'],
|
||||
['fr', 'Europe/Paris'],
|
||||
['hr', 'Europe/Zagreb'],
|
||||
['id', 'Asia/Jakarta'],
|
||||
['it', 'Europe/Rome'],
|
||||
['nl', 'Europe/Amsterdam'],
|
||||
['pt', 'Europe/Lisbon'],
|
||||
['ru', 'Europe/Moscow'],
|
||||
['tr', 'Europe/Istanbul'],
|
||||
['ja', 'Asia/Tokyo'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,29 @@ class ReminderTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_calculates_next_expected_date_in_timezone()
|
||||
{
|
||||
config(['app.timezone' => 'Europe/Paris']);
|
||||
|
||||
$reminder = new Reminder;
|
||||
$reminder->initial_date = '1980-05-01';
|
||||
$reminder->frequency_type = 'year';
|
||||
$reminder->frequency_number = 1;
|
||||
|
||||
Carbon::setTestNow(Carbon::create(2000, 4, 30, 21, 59, 59));
|
||||
$this->assertEquals(
|
||||
'2000-05-01',
|
||||
$reminder->calculateNextExpectedDateOnTimezone()->toDateString()
|
||||
);
|
||||
|
||||
Carbon::setTestNow(Carbon::create(2000, 4, 30, 22, 00, 00));
|
||||
$this->assertEquals(
|
||||
'2001-05-01',
|
||||
$reminder->calculateNextExpectedDateOnTimezone()->toDateString()
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_schedules_a_reminder_for_one_user()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user