-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timezones #32 #33
Merged
Merged
Timezones #32 #33
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c70f4f7
Create timezone migration, model & factory #32
drewroberts 38c9453
Seed USA timezone data in migration #32
drewroberts c81801a
Seed USA timezone data in migration #32
drewroberts f4504a8
Rename migration to add permissions
drewroberts 8adac28
Fix class name
drewroberts f1ea299
Create & register timezone policy + permissions #32
drewroberts f10c838
Create test for seeded timezones #2 #32
drewroberts dec6fba
Create test for timezones model #2 #32
drewroberts 25b9acf
misspelled namespace
wolfrednicolas f541e17
resolve issue to enable the migration
wolfrednicolas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tipoff\Addresses\Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Tipoff\Addresses\Models\Timezone; | ||
|
||
class TimezoneFactory extends Factory | ||
{ | ||
protected $model = Timezone::class; | ||
|
||
public function definition() | ||
{ | ||
return [ | ||
'name' => $this->faker->timezone, | ||
'title' => $this->faker->timezone, | ||
'php' => $this->faker->timezone, | ||
'is_daylight_saving' => $this->faker->boolean | ||
]; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
database/migrations/2014_01_01_100000_create_timezones_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateTimezonesTable extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::create('timezones', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name')->unique(); // Abbreviation | ||
$table->string('title')->unique(); | ||
$table->string('php')->unique(); // Supported PHP Timezone: https://www.php.net/manual/en/timezones.php | ||
$table->boolean('is_daylight_saving')->default(1); // Just for reference, Carbon has this. | ||
$table->decimal('dst', 4, 2)->nullable(); // Just for reference, Carbon has this. | ||
$table->decimal('standard', 4, 2)->nullable(); // Just for reference, Carbon has this. | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Tipoff\Addresses\Models\Timezone; | ||
|
||
class AddTimezones extends Migration | ||
{ | ||
public function up() | ||
{ | ||
|
||
if (class_exists(Timezone::class)) { | ||
foreach ([ | ||
[ | ||
'id' => 1, | ||
'name' => 'EST', | ||
'title' => 'Eastern', | ||
'php' => 'America/New_York', | ||
'is_daylight_saving' => 1, | ||
'dst' => '-4.00', | ||
'standard' => '-5.00', | ||
], | ||
[ | ||
'id' => 2, | ||
'name' => 'CST', | ||
'title' => 'Central', | ||
'php' => 'America/Chicago', | ||
'is_daylight_saving' => 1, | ||
'dst' => '-5.00', | ||
'standard' => '-6.00', | ||
], | ||
[ | ||
'id' => 3, | ||
'name' => 'MST', | ||
'title' => 'Mountain', | ||
'php' => 'America/Denver', | ||
'is_daylight_saving' => 1, | ||
'dst' => '-6.00', | ||
'standard' => '-7.00', | ||
], | ||
[ | ||
'id' => 4, | ||
'name' => 'MDT', | ||
'title' => 'Mountain no DST', | ||
'php' => 'America/Phoenix', | ||
'is_daylight_saving' => 0, | ||
'dst' => '-7.00', | ||
'standard' => '-8.00', | ||
], | ||
[ | ||
'id' => 5, | ||
'name' => 'PST', | ||
'title' => 'Pacific', | ||
'php' => 'America/Los_Angeles', | ||
'is_daylight_saving' => 1, | ||
'dst' => '-8.00', | ||
'standard' => '-8.00', | ||
], | ||
[ | ||
'id' => 6, | ||
'name' => 'AKST', | ||
'title' => 'Alaska', | ||
'php' => 'America/Anchorage', | ||
'is_daylight_saving' => 1, | ||
'dst' => '-8.00', | ||
'standard' => '-9.00', | ||
], | ||
[ | ||
'id' => 7, | ||
'name' => 'HAST', | ||
'title' => 'Hawaii–Aleutian', | ||
'php' => 'America/Adak', | ||
'is_daylight_saving' => 1, | ||
'dst' => '-9.00', | ||
'standard' => '-10.00', | ||
], | ||
[ | ||
'id' => 8, | ||
'name' => 'HADT', | ||
'title' => 'Hawaii no DST', | ||
'php' => 'Pacific/Honolulu', | ||
'is_daylight_saving' => 0, | ||
'dst' => '-9.00', | ||
'standard' => '-9.00', | ||
] | ||
] as $timezone) { | ||
Timezone::firstOrCreate($timezone); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tipoff\Addresses\Models; | ||
|
||
use Tipoff\Support\Models\BaseModel; | ||
use Tipoff\Support\Traits\HasCreator; | ||
use Tipoff\Support\Traits\HasPackageFactory; | ||
use Tipoff\Support\Traits\HasUpdater; | ||
|
||
class Timezone extends BaseModel | ||
{ | ||
use HasPackageFactory; | ||
use HasCreator; | ||
use HasUpdater; | ||
|
||
public $timestamps = false; | ||
|
||
public function markets() | ||
{ | ||
return $this->belongsToMany(app('market')); | ||
} | ||
|
||
public function locations() | ||
{ | ||
return $this->belongsToMany(app('location')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tipoff\Addresses\Policies; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I couldn't see the problem right in front of me! |
||
|
||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
use Tipoff\Addresses\Models\Timezone; | ||
use Tipoff\Support\Contracts\Models\UserInterface; | ||
|
||
class TimezonePolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
public function viewAny(UserInterface $user): bool | ||
{ | ||
return $user->hasPermissionTo('view timezones') ? true : false; | ||
} | ||
|
||
public function view(UserInterface $user, Timezone $timezone): bool | ||
{ | ||
return $user->hasPermissionTo('view timezones') ? true : false; | ||
} | ||
|
||
public function create(UserInterface $user): bool | ||
{ | ||
return $user->hasPermissionTo('create timezones') ? true : false; | ||
} | ||
|
||
public function update(UserInterface $user, Timezone $timezone): bool | ||
{ | ||
return $user->hasPermissionTo('update timezones') ? true : false; | ||
} | ||
|
||
public function delete(UserInterface $user, Timezone $timezone): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function restore(UserInterface $user, Timezone $timezone): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function forceDelete(UserInterface $user, Timezone $timezone): bool | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tipoff\Adddresses\Tests\Unit\Migrations; | ||
|
||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Schema; | ||
use Spatie\Permission\Models\Permission; | ||
use Tipoff\Addresses\Tests\TestCase; | ||
|
||
class PermissionsMigrationTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function permissions_seeded() | ||
{ | ||
$this->assertTrue(Schema::hasTable('permissions')); | ||
|
||
$seededPermissions = app(Permission::class)->whereIn('name', [ | ||
'view customers', | ||
'create customers', | ||
'update customers', | ||
'view timezones', | ||
'create timezones', | ||
'update timezones', | ||
])->pluck('name'); | ||
|
||
$this->assertCount(6, $seededPermissions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tipoff\Addresses\Tests\Unit\Migrations; | ||
|
||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Illuminate\Support\Facades\Schema; | ||
use Tipoff\Addresses\Models\Timezone; | ||
use Tipoff\Addresses\Tests\TestCase; | ||
|
||
class TimezonesMigrationTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function timezones_seeded() | ||
{ | ||
$this->assertTrue(Schema::hasTable('timezones')); | ||
|
||
$seededTimezones = Timezone::whereIn('name', [ | ||
'EST', | ||
'CST', | ||
'MST', | ||
'MDT', | ||
'PST', | ||
'AKST', | ||
'HAST', | ||
'HADT', | ||
])->pluck('name'); | ||
|
||
$this->assertCount(8, $seededTimezones); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tipoff\Addresses\Tests\Unit\Models; | ||
|
||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Tipoff\Addresses\Models\Timezone; | ||
use Tipoff\Addresses\Tests\TestCase; | ||
|
||
class TimezoneModelTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function create() | ||
{ | ||
$model = Timezone::factory()->create(); | ||
$this->assertNotNull($model); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!