@@ -877,6 +877,52 @@ public function testTwoColumnsWithPrimaryKey() {
877
877
$ this ->assertContains ('`user_id` int(11) NOT NULL, ' , $ result );
878
878
}
879
879
880
+ /**
881
+ * Test that the primary flag is handled correctly.
882
+ *
883
+ * @return void
884
+ */
885
+ public function testCreateSchemaAutoPrimaryKey () {
886
+ $ schema = new CakeSchema ();
887
+ $ schema ->tables = array (
888
+ 'no_indexes ' => array (
889
+ 'id ' => array ('type ' => 'integer ' , 'null ' => false , 'key ' => 'primary ' ),
890
+ 'data ' => array ('type ' => 'integer ' , 'null ' => false ),
891
+ 'indexes ' => array (),
892
+ )
893
+ );
894
+ $ result = $ this ->Dbo ->createSchema ($ schema , 'no_indexes ' );
895
+ $ this ->assertContains ('PRIMARY KEY (`id`) ' , $ result );
896
+ $ this ->assertNotContains ('UNIQUE KEY ' , $ result );
897
+
898
+ $ schema ->tables = array (
899
+ 'primary_index ' => array (
900
+ 'id ' => array ('type ' => 'integer ' , 'null ' => false ),
901
+ 'data ' => array ('type ' => 'integer ' , 'null ' => false ),
902
+ 'indexes ' => array (
903
+ 'PRIMARY ' => array ('column ' => 'id ' , 'unique ' => 1 ),
904
+ 'some_index ' => array ('column ' => 'data ' , 'unique ' => 1 )
905
+ ),
906
+ )
907
+ );
908
+ $ result = $ this ->Dbo ->createSchema ($ schema , 'primary_index ' );
909
+ $ this ->assertContains ('PRIMARY KEY (`id`) ' , $ result );
910
+ $ this ->assertContains ('UNIQUE KEY `some_index` (`data`) ' , $ result );
911
+
912
+ $ schema ->tables = array (
913
+ 'primary_flag_has_index ' => array (
914
+ 'id ' => array ('type ' => 'integer ' , 'null ' => false , 'key ' => 'primary ' ),
915
+ 'data ' => array ('type ' => 'integer ' , 'null ' => false ),
916
+ 'indexes ' => array (
917
+ 'some_index ' => array ('column ' => 'data ' , 'unique ' => 1 )
918
+ ),
919
+ )
920
+ );
921
+ $ result = $ this ->Dbo ->createSchema ($ schema , 'primary_flag_has_index ' );
922
+ $ this ->assertContains ('PRIMARY KEY (`id`) ' , $ result );
923
+ $ this ->assertContains ('UNIQUE KEY `some_index` (`data`) ' , $ result );
924
+ }
925
+
880
926
/**
881
927
* Tests that listSources method sends the correct query and parses the result accordingly
882
928
* @return void
0 commit comments