Changeset 37939 for branches/4.2/tests/phpunit/tests/dbdelta.php
- Timestamp:
- 07/01/2016 11:50:08 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.2/tests/phpunit/tests/dbdelta.php
r32108 r37939 9 9 class Tests_dbDelta extends WP_UnitTestCase { 10 10 11 /** 12 * Make sure the upgrade code is loaded before the tests are run. 13 */ 14 public static function setUpBeforeClass() { 15 16 parent::setUpBeforeClass(); 17 18 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 19 } 20 21 /** 22 * Create a custom table to be used in each test. 23 */ 24 public function setUp() { 25 26 global $wpdb; 27 28 $wpdb->query( 29 " 30 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 31 id bigint(20) NOT NULL AUTO_INCREMENT, 32 column_1 varchar(255) NOT NULL, 33 column_2 text, 34 column_3 blob, 35 PRIMARY KEY (id), 36 KEY key_1 (column_1), 37 KEY compound_key (id,column_1) 38 ) 39 " 40 ); 41 42 parent::setUp(); 43 } 44 45 /** 46 * Delete the custom table on teardown. 47 */ 48 public function tearDown() { 49 50 global $wpdb; 51 52 parent::tearDown(); 53 54 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test" ); 55 } 56 11 57 function test_create_new_table() { 12 include_once( ABSPATH . 'wp-admin/includes/upgrade.php');13 58 $table_name = 'test_new_table'; 14 59 … … 41 86 $this->assertSame( array(), $actual ); 42 87 } 88 89 /** 90 * @ticket 36748 91 */ 92 function test_dont_downsize_text_fields() { 93 global $wpdb; 94 95 $result = dbDelta( 96 " 97 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 98 id bigint(20) NOT NULL AUTO_INCREMENT, 99 column_1 varchar(255) NOT NULL, 100 column_2 tinytext, 101 column_3 blob, 102 PRIMARY KEY (id), 103 KEY key_1 (column_1), 104 KEY compound_key (id,column_1) 105 ) ENGINE=MyISAM 106 ", false ); 107 108 $this->assertSame( array(), $result ); 109 } 110 111 /** 112 * @ticket 36748 113 */ 114 function test_dont_downsize_blob_fields() { 115 global $wpdb; 116 117 $result = dbDelta( 118 " 119 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 120 id bigint(20) NOT NULL AUTO_INCREMENT, 121 column_1 varchar(255) NOT NULL, 122 column_2 text, 123 column_3 tinyblob, 124 PRIMARY KEY (id), 125 KEY key_1 (column_1), 126 KEY compound_key (id,column_1) 127 ) ENGINE=MyISAM 128 ", false ); 129 130 $this->assertSame( array(), $result ); 131 } 132 133 /** 134 * @ticket 36748 135 */ 136 function test_upsize_text_fields() { 137 global $wpdb; 138 139 $result = dbDelta( 140 " 141 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 142 id bigint(20) NOT NULL AUTO_INCREMENT, 143 column_1 varchar(255) NOT NULL, 144 column_2 bigtext, 145 column_3 blob, 146 PRIMARY KEY (id), 147 KEY key_1 (column_1), 148 KEY compound_key (id,column_1) 149 ) ENGINE=MyISAM 150 ", false ); 151 152 $this->assertSame( 153 array( 154 "{$wpdb->prefix}dbdelta_test.column_2" 155 => "Changed type of {$wpdb->prefix}dbdelta_test.column_2 from text to bigtext" 156 ), $result ); 157 } 158 159 /** 160 * @ticket 36748 161 */ 162 function test_upsize_blob_fields() { 163 global $wpdb; 164 165 $result = dbDelta( 166 " 167 CREATE TABLE {$wpdb->prefix}dbdelta_test ( 168 id bigint(20) NOT NULL AUTO_INCREMENT, 169 column_1 varchar(255) NOT NULL, 170 column_2 text, 171 column_3 mediumblob, 172 PRIMARY KEY (id), 173 KEY key_1 (column_1), 174 KEY compound_key (id,column_1) 175 ) ENGINE=MyISAM 176 ", false ); 177 178 $this->assertSame( 179 array( 180 "{$wpdb->prefix}dbdelta_test.column_3" 181 => "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob" 182 ), $result ); 183 } 43 184 }
Note: See TracChangeset
for help on using the changeset viewer.