2006-12-28 00:30:25 +03:00
< ? php
2007-03-22 16:32:43 +03:00
/*
* $Id $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
* SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT
* LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL . For more information , see
* < http :// www . phpdoctrine . com >.
*/
/**
* Doctrine_Export_Sqlite_TestCase
*
* @ package Doctrine
* @ author Konsta Vesterinen < kvesteri @ cc . hut . fi >
* @ license http :// www . opensource . org / licenses / lgpl - license . php LGPL
* @ category Object Relational Mapping
* @ link www . phpdoctrine . com
* @ since 1.0
* @ version $Revision $
*/
2007-06-18 22:23:42 +04:00
class Doctrine_Export_Sqlite_TestCase extends Doctrine_UnitTestCase
{
public function testCreateDatabaseDoesNotExecuteSql ()
{
2006-12-28 00:30:25 +03:00
try {
$this -> export -> createDatabase ( 'db' );
$this -> fail ();
} catch ( Doctrine_Export_Exception $e ) {
$this -> pass ();
}
}
2007-06-18 22:23:42 +04:00
public function testDropDatabaseDoesNotExecuteSql ()
{
2006-12-28 00:30:25 +03:00
try {
$this -> export -> dropDatabase ( 'db' );
$this -> fail ();
} catch ( Doctrine_Export_Exception $e ) {
$this -> pass ();
}
}
2007-06-18 22:23:42 +04:00
public function testCreateTableSupportsAutoincPks ()
{
2006-12-28 00:30:25 +03:00
$name = 'mytable' ;
$fields = array ( 'id' => array ( 'type' => 'integer' , 'unsigned' => 1 , 'autoincrement' => true ));
$this -> export -> createTable ( $name , $fields );
2007-06-18 22:23:42 +04:00
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE mytable (id INTEGER PRIMARY KEY AUTOINCREMENT)' );
2006-12-28 00:30:25 +03:00
}
2007-06-18 22:23:42 +04:00
public function testCreateTableSupportsDefaultAttribute ()
{
2006-12-28 00:30:25 +03:00
$name = 'mytable' ;
$fields = array ( 'name' => array ( 'type' => 'char' , 'length' => 10 , 'default' => 'def' ),
'type' => array ( 'type' => 'integer' , 'length' => 3 , 'default' => 12 )
);
$options = array ( 'primary' => array ( 'name' , 'type' ));
$this -> export -> createTable ( $name , $fields , $options );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE mytable (name CHAR(10) DEFAULT \'def\', type INTEGER DEFAULT 12, PRIMARY KEY(name, type))' );
}
2007-06-18 22:23:42 +04:00
public function testCreateTableSupportsMultiplePks ()
{
2006-12-28 00:30:25 +03:00
$name = 'mytable' ;
$fields = array ( 'name' => array ( 'type' => 'char' , 'length' => 10 ),
'type' => array ( 'type' => 'integer' , 'length' => 3 ));
$options = array ( 'primary' => array ( 'name' , 'type' ));
$this -> export -> createTable ( $name , $fields , $options );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE mytable (name CHAR(10), type INTEGER, PRIMARY KEY(name, type))' );
}
2007-03-22 15:47:37 +03:00
public function testCreateTableSupportsIndexes ()
2007-02-10 23:48:45 +03:00
{
$fields = array ( 'id' => array ( 'type' => 'integer' , 'unsigned' => 1 , 'autoincrement' => true , 'unique' => true ),
'name' => array ( 'type' => 'string' , 'length' => 4 ),
);
$options = array ( 'primary' => array ( 'id' ),
'indexes' => array ( 'myindex' => array ( 'fields' => array ( 'id' , 'name' )))
);
$this -> export -> createTable ( 'sometable' , $fields , $options );
2007-07-29 00:39:42 +04:00
//this was the old line, but it looks like the table is created first
//and then the index so i replaced it with the ones below
//$this->assertEqual($var, 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id, name))');
$this -> assertEqual ( $this -> adapter -> pop (), " CREATE INDEX myindex_idx ON sometable (id, name) " );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4))' );
2007-02-10 23:48:45 +03:00
}
2007-09-30 05:17:49 +04:00
public function testIdentifierQuoting ()
{
$this -> conn -> setAttribute ( Doctrine :: ATTR_QUOTE_IDENTIFIER , true );
$fields = array ( 'id' => array ( 'type' => 'integer' , 'unsigned' => 1 , 'autoincrement' => true , 'unique' => true ),
'name' => array ( 'type' => 'string' , 'length' => 4 ),
);
$options = array ( 'primary' => array ( 'id' ),
'indexes' => array ( 'myindex' => array ( 'fields' => array ( 'id' , 'name' )))
);
$this -> export -> createTable ( 'sometable' , $fields , $options );
//this was the old line, but it looks like the table is created first
//and then the index so i replaced it with the ones below
//$this->assertEqual($var, 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id, name))');
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE INDEX "myindex_idx" ON "sometable" ("id", "name")' );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE "sometable" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(4))' );
$this -> conn -> setAttribute ( Doctrine :: ATTR_QUOTE_IDENTIFIER , false );
}
public function testQuoteMultiplePks ()
{
$this -> conn -> setAttribute ( Doctrine :: ATTR_QUOTE_IDENTIFIER , true );
$name = 'mytable' ;
$fields = array ( 'name' => array ( 'type' => 'char' , 'length' => 10 ),
'type' => array ( 'type' => 'integer' , 'length' => 3 ));
$options = array ( 'primary' => array ( 'name' , 'type' ));
$this -> export -> createTable ( $name , $fields , $options );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE "mytable" ("name" CHAR(10), "type" INTEGER, PRIMARY KEY("name", "type"))' );
$this -> conn -> setAttribute ( Doctrine :: ATTR_QUOTE_IDENTIFIER , false );
}
2007-02-10 23:48:45 +03:00
public function testUnknownIndexSortingAttributeThrowsException ()
{
$fields = array ( 'id' => array ( 'sorting' => 'ASC' ),
'name' => array ( 'sorting' => 'unknown' ));
try {
$this -> export -> getIndexFieldDeclarationList ( $fields );
$this -> fail ();
} catch ( Doctrine_Export_Exception $e ) {
$this -> pass ();
}
}
public function testCreateTableSupportsIndexesWithCustomSorting ()
{
$fields = array ( 'id' => array ( 'type' => 'integer' , 'unsigned' => 1 , 'autoincrement' => true , 'unique' => true ),
'name' => array ( 'type' => 'string' , 'length' => 4 ),
);
$options = array ( 'primary' => array ( 'id' ),
'indexes' => array ( 'myindex' => array (
'fields' => array (
'id' => array ( 'sorting' => 'ASC' ),
'name' => array ( 'sorting' => 'DESC' )
)
))
);
$this -> export -> createTable ( 'sometable' , $fields , $options );
2007-07-29 00:39:42 +04:00
//removed this assertion and inserted the two below
// $this->assertEqual($this->adapter->pop(), 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4), INDEX myindex (id ASC, name DESC))');
$this -> assertEqual ( $this -> adapter -> pop (), " CREATE INDEX myindex_idx ON sometable (id ASC, name DESC) " );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE sometable (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(4))' );
2007-02-10 23:48:45 +03:00
}
2007-10-21 10:23:59 +04:00
2007-06-18 23:58:11 +04:00
/**
2007-03-22 16:32:43 +03:00
public function testExportSupportsEmulationOfCascadingDeletes ()
2007-03-22 15:47:37 +03:00
{
$r = new ForeignKeyTest ;
2007-06-18 23:58:11 +04:00
2007-03-22 16:32:43 +03:00
$this -> assertEqual ( $this -> adapter -> pop (), 'COMMIT' );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TRIGGER doctrine_foreign_key_test_cscd_delete AFTER DELETE ON foreign_key_test BEGIN DELETE FROM foreign_key_test WHERE parent_id = old.id;END;' );
$this -> assertEqual ( $this -> adapter -> pop (), 'CREATE TABLE foreign_key_test (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(2147483647), code INTEGER, content VARCHAR(4000), parent_id INTEGER)' );
$this -> assertEqual ( $this -> adapter -> pop (), 'BEGIN TRANSACTION' );
2007-03-22 15:47:37 +03:00
}
2007-06-18 23:58:11 +04:00
*/
2006-12-28 00:30:25 +03:00
}