Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
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
3 changes: 2 additions & 1 deletion library/Zend/Validator/Db/AbstractDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ public function setSelect(Select $select)
*/
public function getSelect()
{
if ($this->select instanceof Select) {
if ($this->select instanceof Select
&& ($this->getSchema() === null || $this->getTable() === '' || $this->getField() === '' || $this->getExclude() === null)) {
return $this->select;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/ZendTest/Validator/Db/RecordExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,39 @@ public function testGetSelect()
$this->assertNull($parameters['where1']);
$this->assertEquals($parameters['where2'], 'bar');
}

/**
* @cover Zend\Validator\Db\RecordExists::getSelect
* @group ZF2-4521
*/
public function testGetSelectWithSameValidatorTwice()
{
$validator = new RecordExists(
array(
'table' => 'users',
'schema' => 'my'
),
'field1',
array(
'field' => 'foo',
'value' => 'bar'
),
$this->getMockHasResult()
);
$select = $validator->getSelect();
$this->assertInstanceOf('Zend\Db\Sql\Select', $select);
$this->assertEquals('SELECT "my"."users"."field1" AS "field1" FROM "my"."users" WHERE "field1" = \'\' AND "foo" != \'bar\'', $select->getSqlString(new TrustingSql92Platform()));

// same validator instance with changing properties
$validator->setTable('othertable');
$validator->setSchema('otherschema');
$validator->setField('fieldother');
$validator->setExclude(array(
'field' => 'fieldexclude',
'value' => 'fieldvalueexclude',
));
$select = $validator->getSelect();
$this->assertInstanceOf('Zend\Db\Sql\Select', $select);
$this->assertEquals('SELECT "otherschema"."othertable"."fieldother" AS "fieldother" FROM "otherschema"."othertable" WHERE "fieldother" = \'\' AND "fieldexclude" != \'fieldvalueexclude\'', $select->getSqlString(new TrustingSql92Platform()));
}
}