-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
368 additions
and
26 deletions.
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
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
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
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,38 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Name> | ||
*/ | ||
class NameFactory extends Factory | ||
{ | ||
protected static ?string $password; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition(): array | ||
{ | ||
return [ | ||
'gender' => 'male', | ||
'name' => fake()->name(), | ||
'origins' => fake()->sentence(), | ||
'personality' => fake()->sentence(), | ||
'country_of_origin' => fake()->word(), | ||
'celebrities' => fake()->sentence(), | ||
'elfic_traits' => fake()->sentence(), | ||
'name_day' => fake()->sentence(), | ||
'litterature_artistics_references' => fake()->sentence(), | ||
'similar_names_in_other_languages' => fake()->sentence(), | ||
'klingon_translation' => fake()->sentence(), | ||
'unisex' => true, | ||
'total' => 1, | ||
'page_views' => 1, | ||
]; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Helpers; | ||
|
||
use App\Helpers\StringHelper; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Tests\TestCase; | ||
|
||
class StringHelperTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function it_sanitizes_the_name_for_the_URL(): void | ||
{ | ||
$this->assertEquals( | ||
'heloise', | ||
StringHelper::sanitizeNameForURL('Héloïse') | ||
); | ||
|
||
$this->assertEquals( | ||
'cedricceheeeliuse', | ||
StringHelper::sanitizeNameForURL('CédriçceHeèélïûse') | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_formats_the_name_from_the_BD(): void | ||
{ | ||
$this->assertEquals( | ||
'Héloïse', | ||
StringHelper::formatNameFromDB('HÉLOÏSE') | ||
); | ||
|
||
$this->assertEquals( | ||
'Jean-Jacques', | ||
StringHelper::formatNameFromDB('JEAN-JACQUES') | ||
); | ||
} | ||
} |
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,93 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\ViewModels\Home; | ||
|
||
use App\Http\ViewModels\Home\HomeViewModel; | ||
use App\Models\Name; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Tests\TestCase; | ||
|
||
class HomeViewModelTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function it_gets_the_twenty_popular_names(): void | ||
{ | ||
$maleName = Name::factory()->create([ | ||
'gender' => 'male', | ||
'name' => 'JEAN-JACQUES', | ||
]); | ||
$femaleName = Name::factory()->create([ | ||
'gender' => 'female', | ||
'name' => 'HÉLOÏSE', | ||
]); | ||
|
||
$array = HomeViewModel::twentyMostPopularNames(); | ||
|
||
$this->assertCount(3, $array); | ||
$this->assertArrayHasKey('male_names', $array); | ||
$this->assertArrayHasKey('female_names', $array); | ||
$this->assertArrayHasKey('random_names', $array); | ||
|
||
$this->assertEquals( | ||
[ | ||
0 => [ | ||
'id' => $maleName->id, | ||
'name' => 'Jean-Jacques', | ||
'avatar' => $maleName->avatar, | ||
'url' => env('APP_URL') . '/prenoms/' . $maleName->id . '/jean-jacques', | ||
], | ||
], | ||
$array['male_names']->toArray() | ||
); | ||
|
||
$this->assertEquals( | ||
[ | ||
0 => [ | ||
'id' => $femaleName->id, | ||
'name' => 'Héloïse', | ||
'avatar' => $femaleName->avatar, | ||
'url' => env('APP_URL') . '/prenoms/' . $femaleName->id . '/heloise', | ||
], | ||
], | ||
$array['female_names']->toArray() | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_gets_the_name_that_is_in_the_spotlight(): void | ||
{ | ||
$name = Name::factory()->create([ | ||
'name' => 'JEAN-JACQUES', | ||
'total' => 10000, | ||
'origins' => 'This is the origins of the name Jean-Jacques and it is very long and this is insane because i want to test if Occaecat tempor aliqua nostrud magna adipisicing nulla excepteur ea. Occaecat tempor aliqua nostrud magna adipisicing nulla excepteur ea. This is the origins of the name Jean-Jacques and it is very long and this is insane because i want to test if Occaecat tempor aliqua nostrud magna adipisicing nulla excepteur ea. Occaecat tempor aliqua nostrud magna adipisicing nulla excepteur ea.', | ||
]); | ||
$array = HomeViewModel::nameSpotlight(); | ||
|
||
$this->assertEquals( | ||
[ | ||
'id' => $name->id, | ||
'name' => 'Jean-Jacques', | ||
'avatar' => $name->avatar, | ||
'origins' => 'This is the origins of the name Jean-Jacques and it is very long and this is insane because i want to test if Occaecat tempor aliqua nostrud magna adipisicing nulla excepteur ea. Occaecat tempor aliqua nostrud magna adipisicing nulla excepteur ea. This is the origins of the name Jean-Jacques and...', | ||
'url' => env('APP_URL') . '/prenoms/' . $name->id . '/jean-jacques', | ||
], | ||
$array | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_gets_the_stats_of_the_server(): void | ||
{ | ||
$name = Name::factory()->create(); | ||
$array = HomeViewModel::serverStats(); | ||
|
||
$this->assertEquals( | ||
[ | ||
'total_names' => 1, | ||
], | ||
$array | ||
); | ||
} | ||
} |
Oops, something went wrong.