markTestSkipped('No sqlite available'); } $this->_db = new Zend_Db_Adapter_Pdo_Sqlite( array('dbname' => 'test') ); Zend_Db_Table_Abstract::setDefaultAdapter($this->_db); $createTable = 'CREATE TABLE [users] ( ' . '[id] INTEGER NOT NULL PRIMARY KEY, ' . '[field1] VARCHAR(20),' . '[field2] VARCHAR(20) )'; $this->_db->query($createTable); $insert1 = 'INSERT INTO users (id, field1, field2) ' . 'VALUES (1, "value1", "value2")'; $insert2 = 'INSERT INTO users (id, field1, field2) ' . 'VALUES (2, "value3", "value4")'; $this->_db->query($insert1); $this->_db->query($insert2); } /** * Test basic function of RecordExists (no exclusion) * * @return void */ public function testBasicFindsRecord() { $validator = new Zend_Validate_Db_RecordExists('users', 'field1'); $this->assertTrue($validator->isValid('value1')); } /** * Test basic function of RecordExists (no exclusion) * * @return void */ public function testBasicFindsNoRecord() { $validator = new Zend_Validate_Db_RecordExists('users', 'field1'); $this->assertFalse($validator->isValid('nosuchvalue')); } /** * Test the exclusion function * * @return void */ public function testExcludeWithArray() { $validator = new Zend_Validate_Db_RecordExists('users', 'field1', array('field' => 'id', 'value' => 1)); $this->assertTrue($validator->isValid('value3')); } /** * Test the exclusion function * with an array * * @return void */ public function testExcludeWithArrayNoRecord() { $validator = new Zend_Validate_Db_RecordExists('users', 'field1', array('field' => 'id', 'value' => 1)); $this->assertFalse($validator->isValid('nosuchvalue')); } /** * Test the exclusion function * with a string * * @return void */ public function testExcludeWithString() { $validator = new Zend_Validate_Db_RecordExists('users', 'field1', 'id != 1'); $this->assertTrue($validator->isValid('value3')); } /** * Test the exclusion function * with a string * * @return void */ public function testExcludeWithStringNoRecord() { $validator = new Zend_Validate_Db_RecordExists('users', 'field1', 'id != 1'); $this->assertFalse($validator->isValid('nosuchvalue')); } /** * Test that the class throws an exception if no adapter is provided * and no default is set. * * @return void */ public function testThrowsExceptionWithNoAdapter() { Zend_Db_Table_Abstract::setDefaultAdapter(null); try { $validator = new Zend_Validate_Db_RecordExists('users', 'field1', 'id != 1'); $valid = $validator->isValid('nosuchvalue'); $this->markTestFailed('Did not throw exception'); } catch (Exception $e) { } } public function tearDown() { $dropTable = 'DROP TABLE [users]'; $this->_db->query($dropTable); } }