-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2916 from samsonasik/fix-postgres-is-unique-call-api
Fix is_unique/is_not_unique validation called on POST/PUT via API in Postgresql
- Loading branch information
Showing
3 changed files
with
189 additions
and
148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
use CodeIgniter\Test\CIDatabaseTestCase; | ||
use Config\Database; | ||
use CodeIgniter\Validation\Rules; | ||
|
||
class RulesTest extends CIDatabaseTestCase | ||
{ | ||
|
@@ -609,6 +610,186 @@ public function testIsUniqueIgnoresParams() | |
|
||
//-------------------------------------------------------------------- | ||
|
||
/** | ||
* @group DatabaseLive | ||
*/ | ||
public function testIsUniqueIgnoresParamsPlaceholders() | ||
{ | ||
$this->hasInDatabase('user', [ | ||
'name' => 'Derek', | ||
'email' => '[email protected]', | ||
'country' => 'GB', | ||
]); | ||
|
||
$db = Database::connect(); | ||
$row = $db->table('user') | ||
->limit(1) | ||
->get() | ||
->getRow(); | ||
|
||
$data = [ | ||
'id' => $row->id, | ||
'email' => '[email protected]', | ||
]; | ||
|
||
$this->validation->setRules([ | ||
'email' => 'is_unique[user.email,id,{id}]', | ||
]); | ||
|
||
$this->assertTrue($this->validation->run($data)); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
/** | ||
* @group DatabaseLive | ||
*/ | ||
public function testIsUniqueByManualRun() | ||
{ | ||
$db = Database::connect(); | ||
$db->table('user') | ||
->insert([ | ||
'name' => 'Developer A', | ||
'email' => '[email protected]', | ||
'country' => 'Elbonia', | ||
]); | ||
|
||
$this->assertFalse((new Rules())->is_unique('[email protected]', 'user.email,id,{id}', [])); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
/** | ||
* @group DatabaseLive | ||
*/ | ||
public function testIsNotUniqueFalse() | ||
{ | ||
$db = Database::connect(); | ||
$db->table('user') | ||
->insert([ | ||
'name' => 'Derek Travis', | ||
'email' => '[email protected]', | ||
'country' => 'Elbonia', | ||
]); | ||
|
||
$data = [ | ||
'email' => '[email protected]', | ||
]; | ||
|
||
$this->validation->setRules([ | ||
'email' => 'is_not_unique[user.email]', | ||
]); | ||
|
||
$this->assertFalse($this->validation->run($data)); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
/** | ||
* @group DatabaseLive | ||
*/ | ||
public function testIsNotUniqueTrue() | ||
{ | ||
$db = Database::connect(); | ||
$db->table('user') | ||
->insert([ | ||
'name' => 'Derek Travis', | ||
'email' => '[email protected]', | ||
'country' => 'Elbonia', | ||
]); | ||
|
||
$data = [ | ||
'email' => '[email protected]', | ||
]; | ||
|
||
$this->validation->setRules([ | ||
'email' => 'is_not_unique[user.email]', | ||
]); | ||
|
||
$this->assertTrue($this->validation->run($data)); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
/** | ||
* @group DatabaseLive | ||
*/ | ||
public function testIsNotUniqueIgnoresParams() | ||
{ | ||
$db = Database::connect(); | ||
$user = $db->table('user') | ||
->insert([ | ||
'name' => 'Developer A', | ||
'email' => '[email protected]', | ||
'country' => 'Elbonia', | ||
]); | ||
$row = $db->table('user') | ||
->limit(1) | ||
->get() | ||
->getRow(); | ||
|
||
$data = [ | ||
'email' => '[email protected]', | ||
]; | ||
|
||
$this->validation->setRules([ | ||
'email' => "is_not_unique[user.email,id,{$row->id}]", | ||
]); | ||
|
||
$this->assertFalse($this->validation->run($data)); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
/** | ||
* @group DatabaseLive | ||
*/ | ||
public function testIsNotUniqueIgnoresParamsPlaceholders() | ||
{ | ||
$this->hasInDatabase('user', [ | ||
'name' => 'Derek', | ||
'email' => '[email protected]', | ||
'country' => 'GB', | ||
]); | ||
|
||
$db = Database::connect(); | ||
$row = $db->table('user') | ||
->limit(1) | ||
->get() | ||
->getRow(); | ||
|
||
$data = [ | ||
'id' => $row->id, | ||
'email' => '[email protected]', | ||
]; | ||
|
||
$this->validation->setRules([ | ||
'email' => 'is_not_unique[user.email,id,{id}]', | ||
]); | ||
|
||
$this->assertTrue($this->validation->run($data)); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
/** | ||
* @group DatabaseLive | ||
*/ | ||
public function testIsNotUniqueByManualRun() | ||
{ | ||
$db = Database::connect(); | ||
$db->table('user') | ||
->insert([ | ||
'name' => 'Developer A', | ||
'email' => '[email protected]', | ||
'country' => 'Elbonia', | ||
]); | ||
|
||
$this->assertTrue((new Rules())->is_not_unique('[email protected]', 'user.email,id,{id}', [])); | ||
} | ||
|
||
//-------------------------------------------------------------------- | ||
|
||
public function testMinLengthNull() | ||
{ | ||
$data = [ | ||
|
This file was deleted.
Oops, something went wrong.