forked from userfrosting/UserFrosting
-
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.
Merge branch 'hotfix' into feature-docker-refinements
- Loading branch information
Showing
7 changed files
with
94 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
use UserFrosting\Sprinkle\Core\Tests\RefreshDatabase; | ||
use UserFrosting\Sprinkle\Account\Account\Registration; | ||
use UserFrosting\Sprinkle\Account\Database\Models\Interfaces\UserInterface; | ||
use UserFrosting\Support\Exception\HttpException; | ||
use UserFrosting\Sprinkle\Account\Database\Models\User; | ||
|
||
/** | ||
* RegistrationTest Class | ||
|
@@ -26,6 +26,17 @@ class RegistrationTest extends TestCase | |
use TestDatabase; | ||
use RefreshDatabase; | ||
|
||
/** | ||
* @var array Test user data | ||
*/ | ||
protected $fakeUserData = [ | ||
'user_name' => 'FooBar', | ||
'first_name' => 'Foo', | ||
'last_name' => 'Bar', | ||
'email' => '[email protected]', | ||
'password' => 'FooBarFooBar123' | ||
]; | ||
|
||
public function tearDown() | ||
{ | ||
parent::tearDown(); | ||
|
@@ -45,7 +56,43 @@ public function setUp() | |
} | ||
|
||
/** | ||
* testNormalRegistration | ||
* Test validation works | ||
*/ | ||
public function testValidation() | ||
{ | ||
$registration = new Registration($this->ci, [ | ||
'user_name' => 'OwlFancy', | ||
'first_name' => 'Owl', | ||
'last_name' => 'Fancy', | ||
'email' => '[email protected]', | ||
'password' => 'owlFancy1234' | ||
]); | ||
|
||
$validation = $registration->validate(); | ||
$this->assertTrue($validation); | ||
} | ||
|
||
/** | ||
* Test the $requiredProperties property | ||
* @depends testValidation | ||
* @expectedException UserFrosting\Support\Exception\HttpException | ||
* @expectedExceptionMessage Account can't be registrated as 'first_name' is required to create a new user. | ||
*/ | ||
public function testMissingFields() | ||
{ | ||
$registration = new Registration($this->ci, [ | ||
'user_name' => 'OwlFancy', | ||
//'first_name' => 'Owl', | ||
'last_name' => 'Fancy', | ||
'email' => '[email protected]', | ||
'password' => 'owlFancy1234' | ||
]); | ||
|
||
$validation = $registration->validate(); | ||
} | ||
|
||
/** | ||
* @depends testValidation | ||
*/ | ||
public function testNormalRegistration() | ||
{ | ||
|
@@ -56,77 +103,53 @@ public function testNormalRegistration() | |
// Tests can't mail properly | ||
$this->ci->config['site.registration.require_email_verification'] = false; | ||
|
||
// Genereate user data | ||
$fakeUserData = [ | ||
'user_name' => 'FooBar', | ||
'first_name' => 'Foo', | ||
'last_name' => 'Bar', | ||
'email' => '[email protected]', | ||
'password' => 'FooBarFooBar123' | ||
]; | ||
|
||
// Get class | ||
$registration = new Registration($this->ci, $fakeUserData); | ||
$registration = new Registration($this->ci, $this->fakeUserData); | ||
$this->assertInstanceOf(Registration::class, $registration); | ||
|
||
// Register user | ||
$user = $registration->register(); | ||
|
||
// Registration should return a valid user | ||
// Registration should return a valid user, with a new ID | ||
$this->assertInstanceOf(UserInterface::class, $user); | ||
$this->assertEquals('FooBar', $user->user_name); | ||
$this->assertInternalType('int', $user->id); | ||
|
||
// We try to register the same user again. Should throw an error | ||
$registration = new Registration($this->ci, $fakeUserData); | ||
$this->expectException(HttpException::class); | ||
$validation = $registration->validate(); | ||
|
||
// Should throw email error if we change the username | ||
$fakeUserData['user_name'] = 'BarFoo'; | ||
$registration = new Registration($this->ci, $fakeUserData); | ||
$this->expectException(HttpException::class); | ||
$validation = $registration->validate(); | ||
// Make sure the user is added to the db by querying it | ||
$users = User::where('email', '[email protected]')->get(); | ||
$this->assertCount(1, $users); | ||
$this->assertSame('FooBar', $users->first()['user_name']); | ||
} | ||
|
||
/** | ||
* Test validation works | ||
* @depends testNormalRegistration | ||
* @expectedException UserFrosting\Support\Exception\HttpException | ||
* @expectedExceptionMessage Username is already in use. | ||
*/ | ||
public function testValidation() | ||
public function testValidationWithDuplicateUsername() | ||
{ | ||
// Reset database | ||
$this->refreshDatabase(); | ||
|
||
$registration = new Registration($this->ci, [ | ||
'user_name' => 'FooBar', | ||
'first_name' => 'Foo', | ||
'last_name' => 'Bar', | ||
'email' => '[email protected]', | ||
'password' => 'FooBarFooBar123' | ||
]); | ||
// Create the first user to test against | ||
$this->testNormalRegistration(); | ||
|
||
// Validate user. Shouldn't tell us the username is already in use since we reset the database | ||
// We try to register the same user again. Should throw an error | ||
$registration = new Registration($this->ci, $this->fakeUserData); | ||
$validation = $registration->validate(); | ||
$this->assertTrue($validation); | ||
} | ||
|
||
/** | ||
* Test the $requiredProperties property | ||
* @depends testNormalRegistration | ||
* @expectedException UserFrosting\Support\Exception\HttpException | ||
* @expectedExceptionMessage Email is already in use. | ||
*/ | ||
public function testMissingFields() | ||
public function testValidationWithDuplicateEmail() | ||
{ | ||
// Reset database | ||
$this->refreshDatabase(); | ||
// Create the first user to test against | ||
$this->testNormalRegistration(); | ||
|
||
$registration = new Registration($this->ci, [ | ||
'user_name' => 'FooBar', | ||
//'first_name' => 'Foo', | ||
'last_name' => 'Bar', | ||
'email' => '[email protected]', | ||
'password' => 'FooBarFooBar123' | ||
]); | ||
|
||
// Validate user. Shouldn't tell us the username is already in use since we reset the database | ||
$this->expectException(HttpException::class); | ||
// Should throw email error if we change the username | ||
$fakeUserData = $this->fakeUserData; | ||
$fakeUserData['user_name'] = 'BarFoo'; | ||
$registration = new Registration($this->ci, $fakeUserData); | ||
$validation = $registration->validate(); | ||
} | ||
} |
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