Skip to content

Commit

Permalink
tests for withdeleted on group by
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 30, 2020
1 parent 5a06e0e commit aa9b85e
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions tests/system/Database/Live/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,47 @@ public function testFirstWithGroupBy()

//--------------------------------------------------------------------

public function testFirstRespectsSoftDeletes()
public function provideGroupBy()
{
return [
[true],
[false],
];
}

/**
* @dataProvider provideGroupBy
*/
public function testFirstRespectsSoftDeletes($groupBy)
{
$this->db->table('user')
->where('id', 1)
->update(['deleted_at' => date('Y-m-d H:i:s')]);

$model = new UserModel();

$user = $model->first();
if ($groupBy)
{
$user = $model->groupBy('id')->first();
}
else
{
$user = $model->first();
}

// fix for PHP7.2
$count = is_array($user) ? count($user) : 1;
$this->assertEquals(1, $count);
$this->assertEquals(2, $user->id);

$user = $model->withDeleted()
->first();
$user = $model->withDeleted();
if ($groupBy)
{
$user = $model->groupBy('id')->first();
}
else
{
$user = $model->first();
}

$this->assertEquals(1, $user->id);
}
Expand Down Expand Up @@ -1900,13 +1924,31 @@ public function testUndefinedMethodInBuilder()
->getBindings();
}

public function testFirstRecoverTempUseSoftDeletes()
/**
* @dataProvider provideGroupBy
*/
public function testFirstRecoverTempUseSoftDeletes($groupBy)
{
$model = new UserModel($this->db);
$model->delete(1);
$user = $model->withDeleted()->first();
if ($groupBy)
{
$user = $model->withDeleted()->first();
}
else
{
$user = $model->groupBy('id')->withDeleted()->first();
}
$this->assertEquals(1, $user->id);
$user2 = $model->first();
if ($groupBy)
{
$user2 = $model->first();
}
else
{
$user2 = $model->groupBy('id')->first();
}
$this->assertEquals(2, $user2->id);
}

Expand Down

0 comments on commit aa9b85e

Please sign in to comment.