[wp-trac] [WordPress Trac] #37046: Unit test initial setup fails if plugins added tables with foreign key constraints
WordPress Trac
noreply at wordpress.org
Tue Jun 7 18:21:27 UTC 2016
#37046: Unit test initial setup fails if plugins added tables with foreign key
constraints
------------------------------+------------------------------
Reporter: javorszky | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Build/Test Tools | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
------------------------------+------------------------------
Comment (by javorszky):
Use case: testing a plugin that makes use of the WP testing library.
When the plugin's install script runs (either on init or hooked into
activation), it creates a new table, for example:
{{{
$wpdb->query( "CREATE TABLE {$wpdb->prefix}tablename (
id BIGINT(20) UNSIGNED AUTO_INCREMENT,
post_id BIGINT(20) UNSIGNED,
some_custom_value VARCHAR(191),
PRIMARY KEY (`id`),
KEY (`post_id`),
KEY (`some_custom_value`),
FOREIGN KEY (post_id)
REFERENCES {$wpdb->posts}(ID)
ON DELETE CASCADE
) ENGINE=INNODB {$collate}");
}}}
where `$collate` is
{{{
$collate = '';
if ( $wpdb->has_cap( 'collation' ) ) {
if ( ! empty( $wpdb->charset ) ) {
$collate .= "DEFAULT CHARACTER SET $wpdb->charset";
}
if ( ! empty( $wpdb->collate ) ) {
$collate .= " COLLATE $wpdb->collate";
}
}
}}}
Next time I want to run the tests, the `posts` table will not have been
deleted. This only works is `tablename` comes later in alphabetical order
than `posts` in this context.
Patch incoming.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37046#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list