Changeset 59769
- Timestamp:
- 02/06/2025 05:51:01 PM (3 months ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/bootstrap.php
r59592 r59769 215 215 define( 'DIR_TESTDATA', __DIR__ . '/../data' ); 216 216 define( 'DIR_TESTROOT', realpath( dirname( __DIR__ ) ) ); 217 define( 'IMPORTER_PLUGIN_FOR_TESTS', DIR_TESTDATA . '/plugins/wordpress-importer/wordpress-importer.php' );218 217 219 218 define( 'WP_LANG_DIR', realpath( DIR_TESTDATA . '/languages' ) ); -
trunk/tests/phpunit/tests/import/import.php
r59326 r59769 1 1 <?php 2 3 require_once __DIR__ . '/base.php';4 2 5 3 /** 6 4 * @group import 7 5 */ 8 class Tests_Import_Import extends WP_Import_UnitTestCase { 9 public function set_up() { 10 global $wpdb; 11 12 parent::set_up(); 13 14 if ( ! defined( 'WP_IMPORTING' ) ) { 15 define( 'WP_IMPORTING', true ); 16 } 17 18 if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) { 19 define( 'WP_LOAD_IMPORTERS', true ); 20 } 21 22 add_filter( 'import_allow_create_users', '__return_true' ); 23 24 $this->require_importer(); 25 26 // Crude but effective: make sure there's no residual data in the main tables. 27 foreach ( array( 'posts', 'postmeta', 'comments', 'terms', 'term_taxonomy', 'term_relationships', 'users', 'usermeta' ) as $table ) { 28 $wpdb->query( "DELETE FROM {$wpdb->$table}" ); 29 } 30 } 31 32 /** 33 * @covers WP_Import::import 34 */ 35 public function test_small_import() { 36 global $wpdb; 37 38 $authors = array( 39 'admin' => false, 40 'editor' => false, 41 'author' => false, 42 ); 43 $this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors ); 44 45 // Ensure that authors were imported correctly. 46 $user_count = count_users(); 47 $this->assertSame( 3, $user_count['total_users'] ); 48 $admin = get_user_by( 'login', 'admin' ); 49 $this->assertSame( 'admin', $admin->user_login ); 50 $this->assertSame( 'local@host.null', $admin->user_email ); 51 $editor = get_user_by( 'login', 'editor' ); 52 $this->assertSame( 'editor', $editor->user_login ); 53 $this->assertSame( 'editor@example.org', $editor->user_email ); 54 $this->assertSame( 'FirstName', $editor->user_firstname ); 55 $this->assertSame( 'LastName', $editor->user_lastname ); 56 $author = get_user_by( 'login', 'author' ); 57 $this->assertSame( 'author', $author->user_login ); 58 $this->assertSame( 'author@example.org', $author->user_email ); 59 60 // Check that terms were imported correctly. 61 $this->assertSame( '30', wp_count_terms( array( 'taxonomy' => 'category' ) ) ); 62 $this->assertSame( '3', wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) ); 63 $foo = get_term_by( 'slug', 'foo', 'category' ); 64 $this->assertSame( 0, $foo->parent ); 65 $bar = get_term_by( 'slug', 'bar', 'category' ); 66 $foo_bar = get_term_by( 'slug', 'foo-bar', 'category' ); 67 $this->assertSame( $bar->term_id, $foo_bar->parent ); 68 69 // Check that posts/pages were imported correctly. 70 $post_count = wp_count_posts( 'post' ); 71 $this->assertSame( '5', $post_count->publish ); 72 $this->assertSame( '1', $post_count->private ); 73 $page_count = wp_count_posts( 'page' ); 74 $this->assertSame( '4', $page_count->publish ); 75 $this->assertSame( '1', $page_count->draft ); 76 $comment_count = wp_count_comments(); 77 $this->assertSame( 1, $comment_count->total_comments ); 78 79 $posts = get_posts( 80 array( 81 'numberposts' => 20, 82 'post_type' => 'any', 83 'post_status' => 'any', 84 'orderby' => 'ID', 85 ) 86 ); 87 $this->assertCount( 11, $posts ); 88 89 $post = $posts[0]; 90 $this->assertSame( 'Many Categories', $post->post_title ); 91 $this->assertSame( 'many-categories', $post->post_name ); 92 $this->assertEquals( $admin->ID, $post->post_author ); 93 $this->assertSame( 'post', $post->post_type ); 94 $this->assertSame( 'publish', $post->post_status ); 95 $this->assertSame( 0, $post->post_parent ); 96 $cats = wp_get_post_categories( $post->ID ); 97 $this->assertCount( 27, $cats ); 98 99 $post = $posts[1]; 100 $this->assertSame( 'Non-standard post format', $post->post_title ); 101 $this->assertSame( 'non-standard-post-format', $post->post_name ); 102 $this->assertEquals( $admin->ID, $post->post_author ); 103 $this->assertSame( 'post', $post->post_type ); 104 $this->assertSame( 'publish', $post->post_status ); 105 $this->assertSame( 0, $post->post_parent ); 106 $cats = wp_get_post_categories( $post->ID ); 107 $this->assertCount( 1, $cats ); 108 $this->assertTrue( has_post_format( 'aside', $post->ID ) ); 109 110 $post = $posts[2]; 111 $this->assertSame( 'Top-level Foo', $post->post_title ); 112 $this->assertSame( 'top-level-foo', $post->post_name ); 113 $this->assertEquals( $admin->ID, $post->post_author ); 114 $this->assertSame( 'post', $post->post_type ); 115 $this->assertSame( 'publish', $post->post_status ); 116 $this->assertSame( 0, $post->post_parent ); 117 $cats = wp_get_post_categories( $post->ID, array( 'fields' => 'all' ) ); 118 $this->assertCount( 1, $cats ); 119 $this->assertSame( 'foo', $cats[0]->slug ); 120 121 $post = $posts[3]; 122 $this->assertSame( 'Foo-child', $post->post_title ); 123 $this->assertSame( 'foo-child', $post->post_name ); 124 $this->assertEquals( $editor->ID, $post->post_author ); 125 $this->assertSame( 'post', $post->post_type ); 126 $this->assertSame( 'publish', $post->post_status ); 127 $this->assertSame( 0, $post->post_parent ); 128 $cats = wp_get_post_categories( $post->ID, array( 'fields' => 'all' ) ); 129 $this->assertCount( 1, $cats ); 130 $this->assertSame( 'foo-bar', $cats[0]->slug ); 131 132 $post = $posts[4]; 133 $this->assertSame( 'Private Post', $post->post_title ); 134 $this->assertSame( 'private-post', $post->post_name ); 135 $this->assertEquals( $admin->ID, $post->post_author ); 136 $this->assertSame( 'post', $post->post_type ); 137 $this->assertSame( 'private', $post->post_status ); 138 $this->assertSame( 0, $post->post_parent ); 139 $cats = wp_get_post_categories( $post->ID ); 140 $this->assertCount( 1, $cats ); 141 $tags = wp_get_post_tags( $post->ID ); 142 $this->assertCount( 3, $tags ); 143 $this->assertSame( 'tag1', $tags[0]->slug ); 144 $this->assertSame( 'tag2', $tags[1]->slug ); 145 $this->assertSame( 'tag3', $tags[2]->slug ); 146 147 $post = $posts[5]; 148 $this->assertSame( '1-col page', $post->post_title ); 149 $this->assertSame( '1-col-page', $post->post_name ); 150 $this->assertEquals( $admin->ID, $post->post_author ); 151 $this->assertSame( 'page', $post->post_type ); 152 $this->assertSame( 'publish', $post->post_status ); 153 $this->assertSame( 0, $post->post_parent ); 154 $this->assertSame( 'onecolumn-page.php', get_post_meta( $post->ID, '_wp_page_template', true ) ); 155 156 $post = $posts[6]; 157 $this->assertSame( 'Draft Page', $post->post_title ); 158 $this->assertSame( '', $post->post_name ); 159 $this->assertEquals( $admin->ID, $post->post_author ); 160 $this->assertSame( 'page', $post->post_type ); 161 $this->assertSame( 'draft', $post->post_status ); 162 $this->assertSame( 0, $post->post_parent ); 163 $this->assertSame( 'default', get_post_meta( $post->ID, '_wp_page_template', true ) ); 164 165 $post = $posts[7]; 166 $this->assertSame( 'Parent Page', $post->post_title ); 167 $this->assertSame( 'parent-page', $post->post_name ); 168 $this->assertEquals( $admin->ID, $post->post_author ); 169 $this->assertSame( 'page', $post->post_type ); 170 $this->assertSame( 'publish', $post->post_status ); 171 $this->assertSame( 0, $post->post_parent ); 172 $this->assertSame( 'default', get_post_meta( $post->ID, '_wp_page_template', true ) ); 173 174 $post = $posts[8]; 175 $this->assertSame( 'Child Page', $post->post_title ); 176 $this->assertSame( 'child-page', $post->post_name ); 177 $this->assertEquals( $admin->ID, $post->post_author ); 178 $this->assertSame( 'page', $post->post_type ); 179 $this->assertSame( 'publish', $post->post_status ); 180 $this->assertSame( $posts[7]->ID, $post->post_parent ); 181 $this->assertSame( 'default', get_post_meta( $post->ID, '_wp_page_template', true ) ); 182 183 $post = $posts[9]; 184 $this->assertSame( 'Sample Page', $post->post_title ); 185 $this->assertSame( 'sample-page', $post->post_name ); 186 $this->assertEquals( $admin->ID, $post->post_author ); 187 $this->assertSame( 'page', $post->post_type ); 188 $this->assertSame( 'publish', $post->post_status ); 189 $this->assertSame( 0, $post->post_parent ); 190 $this->assertSame( 'default', get_post_meta( $post->ID, '_wp_page_template', true ) ); 191 192 $post = $posts[10]; 193 $this->assertSame( 'Hello world!', $post->post_title ); 194 $this->assertSame( 'hello-world', $post->post_name ); 195 $this->assertEquals( $author->ID, $post->post_author ); 196 $this->assertSame( 'post', $post->post_type ); 197 $this->assertSame( 'publish', $post->post_status ); 198 $this->assertSame( 0, $post->post_parent ); 199 $cats = wp_get_post_categories( $post->ID ); 200 $this->assertCount( 1, $cats ); 201 } 202 203 /** 204 * @covers WP_Import::import 205 */ 206 public function test_double_import() { 207 $authors = array( 208 'admin' => false, 209 'editor' => false, 210 'author' => false, 211 ); 212 $this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors ); 213 $this->_import_wp( DIR_TESTDATA . '/export/small-export.xml', $authors ); 214 215 $user_count = count_users(); 216 $this->assertSame( 3, $user_count['total_users'] ); 217 $admin = get_user_by( 'login', 'admin' ); 218 $this->assertSame( 'admin', $admin->user_login ); 219 $this->assertSame( 'local@host.null', $admin->user_email ); 220 $editor = get_user_by( 'login', 'editor' ); 221 $this->assertSame( 'editor', $editor->user_login ); 222 $this->assertSame( 'editor@example.org', $editor->user_email ); 223 $this->assertSame( 'FirstName', $editor->user_firstname ); 224 $this->assertSame( 'LastName', $editor->user_lastname ); 225 $author = get_user_by( 'login', 'author' ); 226 $this->assertSame( 'author', $author->user_login ); 227 $this->assertSame( 'author@example.org', $author->user_email ); 228 229 $this->assertSame( '30', wp_count_terms( array( 'taxonomy' => 'category' ) ) ); 230 $this->assertSame( '3', wp_count_terms( array( 'taxonomy' => 'post_tag' ) ) ); 231 $foo = get_term_by( 'slug', 'foo', 'category' ); 232 $this->assertSame( 0, $foo->parent ); 233 $bar = get_term_by( 'slug', 'bar', 'category' ); 234 $foo_bar = get_term_by( 'slug', 'foo-bar', 'category' ); 235 $this->assertSame( $bar->term_id, $foo_bar->parent ); 236 237 $post_count = wp_count_posts( 'post' ); 238 $this->assertSame( '5', $post_count->publish ); 239 $this->assertSame( '1', $post_count->private ); 240 $page_count = wp_count_posts( 'page' ); 241 $this->assertSame( '4', $page_count->publish ); 242 $this->assertSame( '1', $page_count->draft ); 243 $comment_count = wp_count_comments(); 244 $this->assertSame( 1, $comment_count->total_comments ); 245 } 246 6 class Tests_Import_Import extends WP_UnitTestCase { 247 7 /** 248 8 * @covers ::get_importers … … 270 30 $wp_importers = $_wp_importers; // Restore global state. 271 31 } 272 273 /**274 * @ticket 21007275 *276 * @covers WP_Import::import277 */278 public function test_slashes_should_not_be_stripped() {279 global $wpdb;280 281 $authors = array( 'admin' => false );282 $this->_import_wp( DIR_TESTDATA . '/export/slashes.xml', $authors );283 284 $alpha = get_term_by( 'slug', 'alpha', 'category' );285 $this->assertSame( 'a \"great\" category', $alpha->name );286 287 $tag1 = get_term_by( 'slug', 'tag1', 'post_tag' );288 $this->assertSame( "foo\'bar", $tag1->name );289 290 $posts = get_posts(291 array(292 'post_type' => 'any',293 'post_status' => 'any',294 )295 );296 $this->assertSame( 'Slashes aren\\\'t \"cool\"', $posts[0]->post_content );297 }298 32 } -
trunk/tools/local-env/scripts/install.js
r59752 r59769 26 26 // Move wp-config.php to the base directory, so it doesn't get mixed up in the src or build directories. 27 27 renameSync( `${process.env.LOCAL_DIR}/wp-config.php`, 'wp-config.php' ); 28 29 install_wp_importer();30 28 31 29 // Read in wp-tests-config-sample.php, edit it to work with our config, then write it to wp-tests-config.php. … … 58 56 execSync( `docker compose ${composeFiles} run --quiet-pull --rm cli ${cmd} --path=/var/www/${process.env.LOCAL_DIR}`, { stdio: 'inherit' } ); 59 57 } 60 61 /**62 * Downloads the WordPress Importer plugin for use in tests.63 */64 function install_wp_importer() {65 const testPluginDirectory = 'tests/phpunit/data/plugins/wordpress-importer';66 const composeFiles = local_env_utils.get_compose_files();67 68 execSync( `docker compose ${composeFiles} exec -T php rm -rf ${testPluginDirectory}`, { stdio: 'inherit' } );69 execSync( `docker compose ${composeFiles} exec -T php git clone https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } );70 }
Note: See TracChangeset
for help on using the changeset viewer.