-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
cake_schema.test.php
898 lines (819 loc) · 21.8 KB
/
cake_schema.test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
<?php
/**
* Test for Schema database management
*
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.5550
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
App::import('Model', 'CakeSchema', false);
/**
* Test for Schema database management
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class MyAppSchema extends CakeSchema {
/**
* name property
*
* @var string 'MyApp'
* @access public
*/
var $name = 'MyApp';
/**
* connection property
*
* @var string 'test_suite'
* @access public
*/
var $connection = 'test_suite';
/**
* comments property
*
* @var array
* @access public
*/
var $comments = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'user_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* posts property
*
* @var array
* @access public
*/
var $posts = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'summary' => array('type' => 'text', 'null' => true),
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* setup method
*
* @param mixed $version
* @access public
* @return void
*/
function setup($version) {
}
/**
* teardown method
*
* @param mixed $version
* @access public
* @return void
*/
function teardown($version) {
}
}
/**
* TestAppSchema class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class TestAppSchema extends CakeSchema {
/**
* name property
*
* @var string 'MyApp'
* @access public
*/
var $name = 'MyApp';
/**
* comments property
*
* @var array
* @access public
*/
var $comments = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0,'key' => 'primary'),
'article_id' => array('type' => 'integer', 'null' => false),
'user_id' => array('type' => 'integer', 'null' => false),
'comment' => array('type' => 'text', 'null' => true, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
'tableParameters' => array(),
);
/**
* posts property
*
* @var array
* @access public
*/
var $posts = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
'tableParameters' => array(),
);
/**
* posts_tags property
*
* @var array
* @access public
*/
var $posts_tags = array(
'post_id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'),
'tag_id' => array('type' => 'string', 'null' => false, 'key' => 'primary'),
'indexes' => array('posts_tag' => array('column' => array('tag_id', 'post_id'), 'unique' => 1)),
'tableParameters' => array()
);
/**
* tags property
*
* @var array
* @access public
*/
var $tags = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'tag' => array('type' => 'string', 'null' => false),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
'tableParameters' => array()
);
/**
* datatypes property
*
* @var array
* @access public
*/
var $datatypes = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'float_field' => array('type' => 'float', 'null' => false, 'length' => '5,2', 'default' => ''),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
'tableParameters' => array()
);
/**
* setup method
*
* @param mixed $version
* @access public
* @return void
*/
function setup($version) {
}
/**
* teardown method
*
* @param mixed $version
* @access public
* @return void
*/
function teardown($version) {
}
}
/**
* SchmeaPost class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaPost extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaPost'
* @access public
*/
var $name = 'SchemaPost';
/**
* useTable property
*
* @var string 'posts'
* @access public
*/
var $useTable = 'posts';
/**
* hasMany property
*
* @var array
* @access public
*/
var $hasMany = array('SchemaComment');
/**
* hasAndBelongsToMany property
*
* @var array
* @access public
*/
var $hasAndBelongsToMany = array('SchemaTag');
}
/**
* SchemaComment class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaComment extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaComment'
* @access public
*/
var $name = 'SchemaComment';
/**
* useTable property
*
* @var string 'comments'
* @access public
*/
var $useTable = 'comments';
/**
* belongsTo property
*
* @var array
* @access public
*/
var $belongsTo = array('SchemaPost');
}
/**
* SchemaTag class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaTag extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaTag'
* @access public
*/
var $name = 'SchemaTag';
/**
* useTable property
*
* @var string 'tags'
* @access public
*/
var $useTable = 'tags';
/**
* hasAndBelongsToMany property
*
* @var array
* @access public
*/
var $hasAndBelongsToMany = array('SchemaPost');
}
/**
* SchemaDatatype class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaDatatype extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaDatatype'
* @access public
*/
var $name = 'SchemaDatatype';
/**
* useTable property
*
* @var string 'datatypes'
* @access public
*/
var $useTable = 'datatypes';
}
/**
* Testdescribe class
*
* This class is defined purely to inherit the cacheSources variable otherwise
* testSchemaCreatTable will fail if listSources has already been called and
* its source cache populated - I.e. if the test is run within a group
*
* @uses CakeTestModel
* @package
* @subpackage cake.tests.cases.libs.model
*/
class Testdescribe extends CakeTestModel {
/**
* name property
*
* @var string 'Testdescribe'
* @access public
*/
var $name = 'Testdescribe';
}
/**
* SchemaCrossDatabase class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaCrossDatabase extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaCrossDatabase'
* @access public
*/
var $name = 'SchemaCrossDatabase';
/**
* useTable property
*
* @var string 'posts'
* @access public
*/
var $useTable = 'cross_database';
/**
* useDbConfig property
*
* @var string 'test2'
* @access public
*/
var $useDbConfig = 'test2';
}
/**
* SchemaCrossDatabaseFixture class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaCrossDatabaseFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'CrossDatabase'
* @access public
*/
var $name = 'CrossDatabase';
/**
* table property
*
* @access public
*/
var $table = 'cross_database';
/**
* fields property
*
* @var array
* @access public
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => 'string'
);
/**
* records property
*
* @var array
* @access public
*/
var $records = array(
array('id' => 1, 'name' => 'First'),
array('id' => 2, 'name' => 'Second'),
);
}
/**
* SchemaPrefixAuthUser class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaPrefixAuthUser extends CakeTestModel {
/**
* name property
*
* @var string
*/
var $name = 'SchemaPrefixAuthUser';
/**
* table prefix
*
* @var string
*/
var $tablePrefix = 'auth_';
/**
* useTable
*
* @var string
*/
var $useTable = 'users';
}
/**
* CakeSchemaTest
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class CakeSchemaTest extends CakeTestCase {
/**
* fixtures property
*
* @var array
* @access public
*/
var $fixtures = array(
'core.post', 'core.tag', 'core.posts_tag', 'core.test_plugin_comment',
'core.datatype', 'core.auth_user', 'core.author',
'core.test_plugin_article', 'core.user', 'core.comment'
);
/**
* setUp method
*
* @access public
* @return void
*/
function startTest() {
$this->Schema = new TestAppSchema();
}
/**
* tearDown method
*
* @access public
* @return void
*/
function tearDown() {
@unlink(TMP . 'tests' . DS .'schema.php');
unset($this->Schema);
ClassRegistry::flush();
}
/**
* testSchemaName method
*
* @access public
* @return void
*/
function testSchemaName() {
$Schema = new CakeSchema();
$this->assertEqual(strtolower($Schema->name), strtolower(APP_DIR));
Configure::write('App.dir', 'Some.name.with.dots');
$Schema = new CakeSchema();
$this->assertEqual($Schema->name, 'SomeNameWithDots');
Configure::write('App.dir', 'app');
}
/**
* testSchemaRead method
*
* @access public
* @return void
*/
function testSchemaRead() {
$read = $this->Schema->read(array(
'connection' => 'test_suite',
'name' => 'TestApp',
'models' => array('SchemaPost', 'SchemaComment', 'SchemaTag', 'SchemaDatatype')
));
unset($read['tables']['missing']);
$expected = array('comments', 'datatypes', 'posts', 'posts_tags', 'tags');
$this->assertEqual(array_keys($read['tables']), $expected);
foreach ($read['tables'] as $table => $fields) {
$this->assertEqual(array_keys($fields), array_keys($this->Schema->tables[$table]));
}
$this->assertEqual(
$read['tables']['datatypes']['float_field'],
$this->Schema->tables['datatypes']['float_field']
);
$db =& ConnectionManager::getDataSource('test_suite');
$config = $db->config;
$config['prefix'] = 'schema_test_prefix_';
ConnectionManager::create('schema_prefix', $config);
$read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false));
$this->assertTrue(empty($read['tables']));
$SchemaPost =& ClassRegistry::init('SchemaPost');
$SchemaPost->table = 'sts';
$SchemaPost->tablePrefix = 'po';
$read = $this->Schema->read(array(
'connection' => 'test_suite',
'name' => 'TestApp',
'models' => array('SchemaPost')
));
$this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix %s');
}
/**
* test read() with tablePrefix properties.
*
* @return void
*/
function testSchemaReadWithTablePrefix() {
$model =& new SchemaPrefixAuthUser();
$Schema =& new CakeSchema();
$read = $Schema->read(array(
'connection' => 'test_suite',
'name' => 'TestApp',
'models' => array('SchemaPrefixAuthUser')
));
unset($read['tables']['missing']);
$this->assertTrue(isset($read['tables']['auth_users']), 'auth_users key missing %s');
}
/**
* test reading schema from plugins.
*
* @return void
*/
function testSchemaReadWithPlugins() {
App::objects('model', null, false);
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$Schema =& new CakeSchema();
$Schema->plugin = 'TestPlugin';
$read = $Schema->read(array(
'connection' => 'test_suite',
'name' => 'TestApp',
'models' => true
));
unset($read['tables']['missing']);
$this->assertTrue(isset($read['tables']['auth_users']));
$this->assertTrue(isset($read['tables']['authors']));
$this->assertTrue(isset($read['tables']['test_plugin_comments']));
$this->assertTrue(isset($read['tables']['posts']));
$this->assertEqual(count($read['tables']), 4);
App::build();
}
/**
* test reading schema with tables from another database.
*
* @return void
*/
function testSchemaReadWithCrossDatabase() {
$config = new DATABASE_CONFIG();
$skip = $this->skipIf(
!isset($config->test) || !isset($config->test2),
'%s Primary and secondary test databases not configured, skipping cross-database '
.'join tests.'
.' To run these tests, you must define $test and $test2 in your database configuration.'
);
if ($skip) {
return;
}
$db2 =& ConnectionManager::getDataSource('test2');
$fixture = new SchemaCrossDatabaseFixture();
$fixture->create($db2);
$fixture->insert($db2);
$read = $this->Schema->read(array(
'connection' => 'test_suite',
'name' => 'TestApp',
'models' => array('SchemaCrossDatabase', 'SchemaPost')
));
unset($read['tables']['missing']);
$this->assertTrue(isset($read['tables']['posts']));
$this->assertFalse(isset($read['tables']['cross_database']));
$read = $this->Schema->read(array(
'connection' => 'test2',
'name' => 'TestApp',
'models' => array('SchemaCrossDatabase', 'SchemaPost')
));
unset($read['tables']['missing']);
$this->assertFalse(isset($read['tables']['posts']));
$this->assertTrue(isset($read['tables']['cross_database']));
$fixture->drop($db2);
}
/**
* test that tables are generated correctly
*
* @return void
*/
function testGenerateTable() {
$fields = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
$result = $this->Schema->generateTable('posts', $fields);
$this->assertPattern('/var \$posts/', $result);
eval(substr($result, 4));
$this->assertEqual($posts, $fields);
}
/**
* testSchemaWrite method
*
* @access public
* @return void
*/
function testSchemaWrite() {
$write = $this->Schema->write(array('name' => 'MyOtherApp', 'tables' => $this->Schema->tables, 'path' => TMP . 'tests'));
$file = file_get_contents(TMP . 'tests' . DS .'schema.php');
$this->assertEqual($write, $file);
require_once( TMP . 'tests' . DS .'schema.php');
$OtherSchema = new MyOtherAppSchema();
$this->assertEqual($this->Schema->tables, $OtherSchema->tables);
}
/**
* testSchemaComparison method
*
* @access public
* @return void
*/
function testSchemaComparison() {
$New = new MyAppSchema();
$compare = $New->compare($this->Schema);
$expected = array(
'comments' => array(
'add' => array(
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
),
'drop' => array(
'article_id' => array('type' => 'integer', 'null' => false),
'tableParameters' => array(),
),
'change' => array(
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
)
),
'posts' => array(
'add' => array(
'summary' => array('type' => 'text', 'null' => 1),
),
'drop' => array(
'tableParameters' => array(),
),
'change' => array(
'author_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => '1')
)
),
);
$this->assertEqual($expected, $compare);
}
/**
* Test comparing tableParameters and indexes.
*
* @return void
*/
function testTableParametersAndIndexComparison() {
$old = array(
'posts' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true)
),
'tableParameters' => array(
'charset' => 'latin1',
'collate' => 'latin1_general_ci'
)
),
'comments' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'comment' => array('type' => 'text'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true),
'post_id' => array('column' => 'post_id'),
),
'tableParameters' => array(
'engine' => 'InnoDB',
'charset' => 'latin1',
'collate' => 'latin1_general_ci'
)
)
);
$new = array(
'posts' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'author_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true),
'author_id' => array('column' => 'author_id'),
),
'tableParameters' => array(
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
'engine' => 'MyISAM'
)
),
'comments' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'comment' => array('type' => 'text'),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => true),
),
'tableParameters' => array(
'charset' => 'utf8',
'collate' => 'utf8_general_ci'
)
)
);
$compare = $this->Schema->compare($old, $new);
$expected = array(
'posts' => array(
'add' => array(
'indexes' => array('author_id' => array('column' => 'author_id')),
),
'change' => array(
'tableParameters' => array(
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
'engine' => 'MyISAM'
)
)
),
'comments' => array(
'drop' => array(
'indexes' => array('post_id' => array('column' => 'post_id')),
),
'change' => array(
'tableParameters' => array(
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
)
)
)
);
$this->assertEqual($compare, $expected);
}
/**
* testSchemaLoading method
*
* @access public
* @return void
*/
function testSchemaLoading() {
$Other =& $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests'));
$this->assertEqual($Other->name, 'MyOtherApp');
$this->assertEqual($Other->tables, $this->Schema->tables);
}
/**
* test loading schema files inside of plugins.
*
* @return void
*/
function testSchemaLoadingFromPlugin() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$Other =& $this->Schema->load(array('name' => 'TestPluginApp', 'plugin' => 'TestPlugin'));
$this->assertEqual($Other->name, 'TestPluginApp');
$this->assertEqual(array_keys($Other->tables), array('acos'));
App::build();
}
/**
* testSchemaCreateTable method
*
* @access public
* @return void
*/
function testSchemaCreateTable() {
$db =& ConnectionManager::getDataSource('test_suite');
$db->cacheSources = false;
$Schema =& new CakeSchema(array(
'connection' => 'test_suite',
'testdescribes' => array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'int_null' => array('type' => 'integer', 'null' => true),
'int_not_null' => array('type' => 'integer', 'null' => false),
),
));
$sql = $db->createSchema($Schema);
$col = $Schema->tables['testdescribes']['int_null'];
$col['name'] = 'int_null';
$column = $this->db->buildColumn($col);
$this->assertPattern('/' . preg_quote($column, '/') . '/', $sql);
$col = $Schema->tables['testdescribes']['int_not_null'];
$col['name'] = 'int_not_null';
$column = $this->db->buildColumn($col);
$this->assertPattern('/' . preg_quote($column, '/') . '/', $sql);
}
}
?>