Skip to content

Commit

Permalink
Adding test cases for dump()
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 9, 2009
1 parent 12b9475 commit 4965551
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions cake/tests/cases/console/libs/schema.test.php
Expand Up @@ -126,12 +126,49 @@ function testView() {
}

/**
* undocumented function
* test dumping a schema file.
*
* @return void
**/
function () {

function testDump() {
$this->Task->params = array('name' => 'i18n');
$this->Task->startup();
$this->Task->Schema->path = APP . 'config' . DS . 'schema';
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/create table `i18n`/i')));
$this->Task->dump();
}

/**
* test dump() with sql file generation
*
* @return void
**/
function testDumpWithFileWriting() {
//copy file.
$file =& new File(APP . 'config' . DS . 'schema' . DS . 'i18n.php');
$contents = $file->read();
$file =& new File(TMP . 'tests' . DS . 'i18n.php');
$file->write($contents);

$this->Task->params = array('name' => 'i18n');
$this->Task->args = array('write');
$this->Task->startup();
$this->Task->Schema->path = TMP . 'tests';
$this->Task->dump();

$sql =& new File(TMP . 'tests' . DS . 'i18n.sql');
$contents = $sql->read();
$this->assertPattern('/DROP TABLE/', $contents);
$this->assertPattern('/CREATE TABLE `i18n`/', $contents);
$this->assertPattern('/id/', $contents);
$this->assertPattern('/model/', $contents);
$this->assertPattern('/field/', $contents);
$this->assertPattern('/locale/', $contents);
$this->assertPattern('/foreign_key/', $contents);
$this->assertPattern('/content/', $contents);

$sql->delete();
$file->delete();
}
}
?>

0 comments on commit 4965551

Please sign in to comment.