Skip to content

Commit 4965551

Browse files
committed
Adding test cases for dump()
1 parent 12b9475 commit 4965551

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

cake/tests/cases/console/libs/schema.test.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,49 @@ function testView() {
126126
}
127127

128128
/**
129-
* undocumented function
129+
* test dumping a schema file.
130130
*
131131
* @return void
132132
**/
133-
function () {
134-
133+
function testDump() {
134+
$this->Task->params = array('name' => 'i18n');
135+
$this->Task->startup();
136+
$this->Task->Schema->path = APP . 'config' . DS . 'schema';
137+
$this->Task->expectAt(0, 'out', array(new PatternExpectation('/create table `i18n`/i')));
138+
$this->Task->dump();
139+
}
140+
141+
/**
142+
* test dump() with sql file generation
143+
*
144+
* @return void
145+
**/
146+
function testDumpWithFileWriting() {
147+
//copy file.
148+
$file =& new File(APP . 'config' . DS . 'schema' . DS . 'i18n.php');
149+
$contents = $file->read();
150+
$file =& new File(TMP . 'tests' . DS . 'i18n.php');
151+
$file->write($contents);
152+
153+
$this->Task->params = array('name' => 'i18n');
154+
$this->Task->args = array('write');
155+
$this->Task->startup();
156+
$this->Task->Schema->path = TMP . 'tests';
157+
$this->Task->dump();
158+
159+
$sql =& new File(TMP . 'tests' . DS . 'i18n.sql');
160+
$contents = $sql->read();
161+
$this->assertPattern('/DROP TABLE/', $contents);
162+
$this->assertPattern('/CREATE TABLE `i18n`/', $contents);
163+
$this->assertPattern('/id/', $contents);
164+
$this->assertPattern('/model/', $contents);
165+
$this->assertPattern('/field/', $contents);
166+
$this->assertPattern('/locale/', $contents);
167+
$this->assertPattern('/foreign_key/', $contents);
168+
$this->assertPattern('/content/', $contents);
169+
170+
$sql->delete();
171+
$file->delete();
135172
}
136173
}
137174
?>

0 commit comments

Comments
 (0)