Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Fixes #4521 #5857

Merged
merged 2 commits into from Apr 14, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/Zend/Validator/Db/AbstractDb.php
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
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()));
}
}