Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,7 @@ protected function _update(string $table, array $values): string
/**
* This method is used by both update() and getCompiledUpdate() to
* validate that data is actually being set and that a table has been
* chosen to be update.
* chosen to be updated.
*
* @throws DatabaseException
*/
Expand Down
22 changes: 13 additions & 9 deletions tests/system/Models/DeleteModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ public function testOnlyDeleted(): void
}

/**
* If where condition is set, beyond the value was empty (0,'', NULL, etc.),
* Exception should not be thrown because condition was explicity set
* Given an explicit empty value in the WHERE condition
* When executing a soft delete
* Then an exception should not be thrown
*
* @dataProvider emptyPkValues
*
* @param mixed $emptyValue
* @param int|string|null $emptyValue
*/
public function testDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue($emptyValue): void
{
Expand All @@ -167,30 +168,33 @@ public function testDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue
/**
* @dataProvider emptyPkValues
*
* @param mixed $emptyValue
* @param int|string|null $emptyValue
*/
public function testThrowExceptionWhenSoftDeleteParamIsEmptyValue($emptyValue): void
{
$this->expectException(DatabaseException::class);
$this->expectExceptionMessage('Deletes are not allowed unless they contain a "where" or "like" clause.');

$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]);

$this->createModel(UserModel::class)->delete($emptyValue);
}

/**
* @dataProvider emptyPkValues
*
* @param mixed $emptyValue
* @param int|string|null $emptyValue
*/
public function testDontDeleteRowsWhenSoftDeleteParamIsEmpty($emptyValue): void
{
$this->expectException(DatabaseException::class);
$this->expectExceptionMessage('Deletes are not allowed unless they contain a "where" or "like" clause.');

$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]);

$this->createModel(UserModel::class)->delete($emptyValue);
try {
$this->createModel(UserModel::class)->delete($emptyValue);
} catch (DatabaseException $e) {
// Do nothing.
}

$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]);
}

Expand Down