-
Notifications
You must be signed in to change notification settings - Fork 101
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
7 changed files
with
99 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
composer.lock | ||
/vendor/ | ||
/vendor/ | ||
.idea |
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,12 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
/* | ||
* The version model to use. | ||
* Feel free to change this, if you need specific version | ||
* model logic. | ||
*/ | ||
'version_model' => \Mpociot\Versionable\Version::class | ||
|
||
]; |
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 |
---|---|---|
|
@@ -11,20 +11,6 @@ | |
class VersionableTest extends VersionableTestCase | ||
{ | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
TestVersionableUser::flushEventListeners(); | ||
TestVersionableUser::boot(); | ||
|
||
TestVersionableSoftDeleteUser::flushEventListeners(); | ||
TestVersionableSoftDeleteUser::boot(); | ||
|
||
TestPartialVersionableUser::flushEventListeners(); | ||
TestPartialVersionableUser::boot(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
m::close(); | ||
|
@@ -33,9 +19,6 @@ public function tearDown() | |
|
||
public function testVersionableRelation() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -49,9 +32,6 @@ public function testVersionableRelation() | |
|
||
public function testInitialSaveShouldCreateVersion() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -64,9 +44,6 @@ public function testInitialSaveShouldCreateVersion() | |
|
||
public function testRetrievePreviousVersionFails() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -80,9 +57,6 @@ public function testRetrievePreviousVersionFails() | |
|
||
public function testRetrievePreviousVersionExists() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -103,9 +77,6 @@ public function testRetrievePreviousVersionExists() | |
|
||
public function testVersionAndModelAreEqual() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -142,28 +113,18 @@ public function testVersionsAreRelatedToUsers() | |
|
||
public function testGetResponsibleUserAttribute() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( true ); | ||
|
||
Auth::shouldReceive('id') | ||
->andReturn( 1 ); | ||
|
||
|
||
$responsibleOrigUser = new TestVersionableUser(); | ||
$responsibleOrigUser->name = "Marcel"; | ||
$responsibleOrigUser->email = "[email protected]"; | ||
$responsibleOrigUser->password = "12345"; | ||
$responsibleOrigUser->last_login = $responsibleOrigUser->freshTimestamp(); | ||
$responsibleOrigUser->save(); | ||
|
||
auth()->login($responsibleOrigUser); | ||
|
||
// Needed because otherwise timestamps are exactly the same | ||
sleep(1); | ||
|
||
Config::shouldReceive('get') | ||
->once() | ||
->with("auth.providers.users.model") | ||
->andReturn('TestVersionableUser'); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->name = "John"; | ||
$user->email = "[email protected]"; | ||
|
@@ -182,9 +143,6 @@ public function testGetResponsibleUserAttribute() | |
|
||
public function testDontVersionEveryAttribute() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestPartialVersionableUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -201,9 +159,6 @@ public function testDontVersionEveryAttribute() | |
|
||
public function testVersionEveryAttribute() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -219,9 +174,6 @@ public function testVersionEveryAttribute() | |
|
||
public function testCheckForVersioningEnabled() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->disableVersioning(); | ||
|
||
|
@@ -246,9 +198,6 @@ public function testCheckForVersioningEnabled() | |
|
||
public function testCheckForVersioningEnabledLaterOn() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
|
||
$user->name = "Marcel"; | ||
|
@@ -266,9 +215,6 @@ public function testCheckForVersioningEnabledLaterOn() | |
|
||
public function testCanRevertVersion() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
|
||
$user->name = "Marcel"; | ||
|
@@ -294,9 +240,6 @@ public function testCanRevertVersion() | |
|
||
public function testCanRevertSoftDeleteVersion() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableSoftDeleteUser(); | ||
|
||
$user->name = "Marcel"; | ||
|
@@ -323,9 +266,6 @@ public function testCanRevertSoftDeleteVersion() | |
|
||
public function testGetVersionModel() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
// Create 3 versions | ||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
|
@@ -351,9 +291,6 @@ public function testGetVersionModel() | |
|
||
public function testUseReasonAttribute() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
// Create 3 versions | ||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
|
@@ -368,9 +305,6 @@ public function testUseReasonAttribute() | |
|
||
public function testIgnoreDeleteTimestamp() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableSoftDeleteUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -391,8 +325,6 @@ public function testIgnoreDeleteTimestamp() | |
|
||
public function testDiffTwoVersions() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableUser(); | ||
$user->name = "Marcel"; | ||
|
@@ -414,9 +346,6 @@ public function testDiffTwoVersions() | |
|
||
public function testDiffIgnoresTimestamps() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$user = new TestVersionableSoftDeleteUser(); | ||
$user->name = "Marcel"; | ||
$user->email = "[email protected]"; | ||
|
@@ -440,9 +369,6 @@ public function testDiffIgnoresTimestamps() | |
|
||
public function testDiffSpecificVersions() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
// Create 3 versions | ||
$user = new TestVersionableSoftDeleteUser(); | ||
$user->name = "Marcel"; | ||
|
@@ -477,24 +403,21 @@ public function testDiffSpecificVersions() | |
|
||
public function testDynamicVersionModel() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
|
||
$name_v1 = 'first' ; | ||
$name_v2 = 'second' ; | ||
|
||
$model = new ModelWithDynamicVersion(); | ||
$model->name = $name_v1 ; | ||
$model->save(); | ||
|
||
sleep(1); | ||
|
||
$model->name = $name_v2 ; | ||
$model->save(); | ||
|
||
// Assert that no row in default Version table | ||
$this->assertEquals( 0, Version::all()->count() ); | ||
|
||
// But are in Custom version table | ||
$this->assertEquals( 2, DynamicVersionModel::all()->count() ); | ||
|
||
|
@@ -509,11 +432,34 @@ public function testDynamicVersionModel() | |
$this->assertEquals( $name_v1, $model->name ); | ||
} | ||
|
||
public function testKeepMaxVersionCount() | ||
public function testItUsesConfigurableVersionClass() | ||
{ | ||
Auth::shouldReceive('check') | ||
->andReturn( false ); | ||
$this->app['config']->set('versionable.version_model', DynamicVersionModel::class); | ||
|
||
|
||
$name_v1 = 'first' ; | ||
$name_v2 = 'second' ; | ||
|
||
$model = new TestVersionableUser(); | ||
$model->name = $name_v1 ; | ||
$model->email = $name_v1 ; | ||
$model->password = $name_v1 ; | ||
$model->save(); | ||
|
||
sleep(1); | ||
|
||
$model->name = $name_v2 ; | ||
$model->save(); | ||
|
||
// Assert that no row in default Version table | ||
$this->assertCount(0, Version::all()); | ||
|
||
// But are in Custom version table | ||
$this->assertCount(2, DynamicVersionModel::all()); | ||
} | ||
|
||
public function testKeepMaxVersionCount() | ||
{ | ||
$name_v1 = 'first' ; | ||
$name_v2 = 'second' ; | ||
$name_v3 = 'third' ; | ||
|
@@ -558,7 +504,7 @@ public function testKeepMaxVersionCount() | |
|
||
|
||
|
||
class TestVersionableUser extends Illuminate\Database\Eloquent\Model { | ||
class TestVersionableUser extends \Illuminate\Foundation\Auth\User { | ||
use \Mpociot\Versionable\VersionableTrait; | ||
|
||
protected $table = "users"; | ||
|
Oops, something went wrong.