Make WordPress Core

Changeset 36552


Ignore:
Timestamp:
02/17/2016 06:54:27 PM (11 years ago)
Author:
ocean90
Message:

Tests: Add Tests_dbDelta::assertTableHasPrimaryKey().

Also fix a typo in the name for the compound key.

Props charlestonsw.
Fixes #34877.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dbdelta.php

    r35487 r36552  
    3434                                PRIMARY KEY  (id),
    3535                                KEY key_1 (column_1),
    36                                 KEY compoud_key (id,column_1),
     36                                KEY compound_key (id,column_1),
    3737                                FULLTEXT KEY fulltext_key (column_1)
    3838                        ) ENGINE=MyISAM
    … …  
    106106                                PRIMARY KEY  (id),
    107107                                KEY key_1 (column_1),
    108                                 KEY compoud_key (id,column_1)
     108                                KEY compound_key (id,column_1)
    109109                        )
    110110                        "
    … …  
    129129                                PRIMARY KEY  (id),
    130130                                KEY key_1 (column_1),
    131                                 KEY compoud_key (id,column_1)
     131                                KEY compound_key (id,column_1)
    132132                        )
    133133                        "
    … …  
    158158                                PRIMARY KEY  (id),
    159159                                KEY key_1 (column_1),
    160                                 KEY compoud_key (id,column_1)
     160                                KEY compound_key (id,column_1)
    161161                        )
    162162                        "
    … …  
    172172
    173173                $this->assertTableHasColumn( 'column_1', $wpdb->prefix . 'dbdelta_test' );
     174                $this->assertTableHasPrimaryKey( 'id' , $wpdb->prefix . 'dbdelta_test' );
    174175        }
    175176
    … …  
    190191                                PRIMARY KEY  (id),
    191192                                KEY key_1 (column_1),
    192                                 KEY compoud_key (id,column_1)
     193                                KEY compound_key (id,column_1)
    193194                        )
    194195                        "
    … …  
    216217                                PRIMARY KEY  (id),
    217218                                KEY key_1 (column_1),
    218                                 KEY compoud_key (id,column_1)
     219                                KEY compound_key (id,column_1)
    219220                        )
    220221                        "
    … …  
    266267                                PRIMARY KEY  (id),
    267268                                KEY key_1 (column_1),
    268                                 KEY compoud_key (id,column_1),
     269                                KEY compound_key (id,column_1),
    269270                                FULLTEXT KEY fulltext_key (column_1)
    270271                        )
    … …  
    287288         */
    288289        protected function assertTableRowHasValue( $column, $value, $table ) {
    289 
    290290                global $wpdb;
    291291
    … …  
    306306         */
    307307        protected function assertTableHasColumn( $column, $table ) {
    308 
    309308                global $wpdb;
    310309
    … …  
    312311
    313312                $this->assertCount( 1, wp_list_filter( $table_fields, array( 'Field' => $column ) ) );
     313        }
     314
     315        /**
     316         * Assert that a table has a primary key.
     317         *
     318         * Checks for single-column primary keys. May not work for multi-column primary keys.
     319         *
     320         * @param string $column The column for the primary key.
     321         * @param string $table  The database table name.
     322         */
     323        protected function assertTableHasPrimaryKey( $column , $table ) {
     324                global $wpdb;
     325
     326                $table_indices = $wpdb->get_results( "SHOW INDEX FROM {$table}" );
     327
     328                $this->assertCount( 1, wp_list_filter( $table_indices, array( 'Key_name' => 'PRIMARY' , 'Column_name' => $column ) , 'AND' ) );
    314329        }
    315330
Note: See TracChangeset for help on using the changeset viewer.