/** * Tests Base->getSQlString() */ public function testGetSQlString() { // Verifica o padrão de não usar o campo deleted e não mostrar os removidos $this->assertEquals('SELECT `album`.* FROM `album`', $this->Base->getSQlString(), 'showDeleted=false, useDeleted=false'); // Marca para usar o campo deleted $this->Base->setUseDeleted(true); $this->assertEquals('SELECT `album`.* FROM `album` WHERE (album.deleted = 0)', $this->Base->getSQlString(), 'showDeleted=false, useDeleted=true'); // Marca para não usar o campo deleted $this->Base->setUseDeleted(false); $this->assertEquals('SELECT `album`.* FROM `album` WHERE (album.id = 1234)', $this->Base->getSQlString(array('id' => 1234))); $this->assertEquals("SELECT `album`.* FROM `album` WHERE (album.texto = 'textotextotexto')", $this->Base->getSQlString(array('texto' => 'textotextotexto'))); $this->assertEquals("SELECT `album`.*, `album`.`id` AS `novoid` FROM `album` WHERE (album.id = 1234)", $this->Base->getSQlString(array('id' => 1234, 'test' => true))); $this->assertEquals("SELECT `album`.*, `album`.`id` AS `novoid` FROM `album` WHERE (album.texto = 'textotextotexto')", $this->Base->getSQlString(array('texto' => 'textotextotexto', 'test' => true))); }
/** * Tests Base->fetchRow() */ public function testFetchRowWithMultipleKey() { $this->dropTables()->createTables(array('album_array')); $defaultValues = array(array('id_int' => 1, 'id_char' => 'A', 'artist' => 'Rush', 'title' => 'Rush', 'deleted' => 0), array('id_int' => 2, 'id_char' => 'B', 'artist' => 'Rush', 'title' => 'Moving Pictures', 'deleted' => 0), array('id_int' => 3, 'id_char' => 'C', 'artist' => 'Dream Theater', 'title' => 'Images And Words', 'deleted' => 0), array('id_int' => 4, 'id_char' => 'D', 'artist' => 'Claudia Leitte', 'title' => 'Exttravasa', 'deleted' => 1)); foreach ($defaultValues as $row) { $this->getAdapter()->query("INSERT into album (id_int, id_char, artist, title, deleted)\r\n VALUES (\r\n '{$row['id_int']}',\r\n '{$row['id_char']}',\r\n '{$row['artist']}',\r\n '{$row['title']}',\r\n {$row['deleted']}\r\n );"); } $this->Base->setKey(array(RW_App_Model_Base::KEY_STRING => 'id')); // Marca pra usar o campo deleted $this->Base->setUseDeleted(true); // Verifica os itens que existem $this->assertEquals($defaultValues[0], $this->Base->fetchRow(array('id_char' => 'A', 'id_int' => 1))); $this->assertEquals($defaultValues[1], $this->Base->fetchRow(array('id_char' => 'B', 'id_int' => 2))); $this->assertEquals($defaultValues[2], $this->Base->fetchRow(array('id_char' => 'C', 'id_int' => 3))); $this->assertNull($this->Base->fetchRow(array('id_char' => 'C', 'id_int' => 2))); // Verifica o item removido $this->Base->setShowDeleted(true); $this->assertEquals($defaultValues[3], $this->Base->fetchRow(array('id_char' => 'D', 'id_int' => 4))); $this->Base->setShowDeleted(false); }