| 245 | |
| 246 | /** |
| 247 | * @ticket 44541 |
| 248 | */ |
| 249 | function test_length_of_excerpt_should_be_counted_by_words() { |
| 250 | global $post; |
| 251 | |
| 252 | switch_to_locale( 'en_US' ); |
| 253 | |
| 254 | $args = array( |
| 255 | 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
| 256 | 'post_excerpt' => '', |
| 257 | ); |
| 258 | |
| 259 | $post = $this->factory()->post->create_and_get( $args ); |
| 260 | setup_postdata( $post ); |
| 261 | |
| 262 | $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat […]</p>\n"; |
| 263 | $this->expectOutputString( $expect ); |
| 264 | the_excerpt(); |
| 265 | |
| 266 | restore_previous_locale(); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * @ticket 44541 |
| 271 | */ |
| 272 | function test_length_of_excerpt_should_be_counted_by_chars() { |
| 273 | global $post; |
| 274 | |
| 275 | switch_to_locale( 'ja_JP' ); |
| 276 | |
| 277 | $args = array( |
| 278 | 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
| 279 | 'post_excerpt' => '', |
| 280 | ); |
| 281 | |
| 282 | $post = $this->factory()->post->create_and_get( $args ); |
| 283 | setup_postdata( $post ); |
| 284 | |
| 285 | $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore […]</p>\n"; |
| 286 | $this->expectOutputString( $expect ); |
| 287 | the_excerpt(); |
| 288 | |
| 289 | restore_previous_locale(); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * @ticket 44541 |
| 294 | */ |
| 295 | function test_length_of_excerpt_should_be_counted_by_chars_in_japanese() { |
| 296 | global $post; |
| 297 | |
| 298 | switch_to_locale( 'ja_JP' ); |
| 299 | |
| 300 | $args = array( |
| 301 | 'post_content' => str_repeat( 'あ', 200 ), |
| 302 | 'post_excerpt' => '', |
| 303 | ); |
| 304 | |
| 305 | $post = $this->factory()->post->create_and_get( $args ); |
| 306 | setup_postdata( $post ); |
| 307 | |
| 308 | $expect = "<p>" . str_repeat( 'あ', 110 ) . " […]</p>\n"; |
| 309 | $this->expectOutputString( $expect ); |
| 310 | the_excerpt(); |
| 311 | |
| 312 | restore_previous_locale(); |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * @ticket 44541 |
| 317 | */ |
| 318 | function test_length_of_excerpt_rss_should_be_counted_by_words() { |
| 319 | global $post; |
| 320 | |
| 321 | switch_to_locale( 'en_US' ); |
| 322 | |
| 323 | $args = array( |
| 324 | 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
| 325 | 'post_excerpt' => '', |
| 326 | ); |
| 327 | |
| 328 | $post = $this->factory()->post->create_and_get( $args ); |
| 329 | setup_postdata( $post ); |
| 330 | |
| 331 | $expect = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat […]"; |
| 332 | $this->expectOutputString( $expect ); |
| 333 | the_excerpt_rss(); |
| 334 | |
| 335 | restore_previous_locale(); |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * @ticket 44541 |
| 340 | */ |
| 341 | function test_length_of_excerpt_rss_should_be_counted_by_chars() { |
| 342 | global $post; |
| 343 | |
| 344 | switch_to_locale( 'ja_JP' ); |
| 345 | |
| 346 | $args = array( |
| 347 | 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
| 348 | 'post_excerpt' => '', |
| 349 | ); |
| 350 | |
| 351 | $post = $this->factory()->post->create_and_get( $args ); |
| 352 | setup_postdata( $post ); |
| 353 | |
| 354 | $expect = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore […]"; |
| 355 | $this->expectOutputString( $expect ); |
| 356 | the_excerpt_rss(); |
| 357 | |
| 358 | restore_previous_locale(); |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * @ticket 44541 |
| 363 | */ |
| 364 | function test_length_of_draft_should_be_counted_by_words() { |
| 365 | require_once dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/src/wp-admin/includes/dashboard.php'; |
| 366 | |
| 367 | switch_to_locale( 'en_US' ); |
| 368 | |
| 369 | $args = array( |
| 370 | 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
| 371 | 'post_excerpt' => '', |
| 372 | 'post_status' => 'draft', |
| 373 | ); |
| 374 | |
| 375 | $post = $this->factory()->post->create( $args ); |
| 376 | |
| 377 | $expect = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…"; |
| 378 | |
| 379 | ob_start(); |
| 380 | wp_dashboard_recent_drafts(); |
| 381 | $result = ob_get_clean(); |
| 382 | |
| 383 | $this->assertTrue( !! strpos( $result, $expect ) ); |
| 384 | |
| 385 | restore_previous_locale(); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * @ticket 44541 |
| 390 | */ |
| 391 | function test_length_of_draft_should_be_counted_by_chars() { |
| 392 | require_once dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/src/wp-admin/includes/dashboard.php'; |
| 393 | |
| 394 | switch_to_locale( 'ja_JP' ); |
| 395 | |
| 396 | $args = array( |
| 397 | 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
| 398 | 'post_excerpt' => '', |
| 399 | 'post_status' => 'draft', |
| 400 | ); |
| 401 | |
| 402 | $post = $this->factory()->post->create( $args ); |
| 403 | |
| 404 | $expect = "Lorem ipsum dolor sit amet, consectetur …"; |
| 405 | |
| 406 | ob_start(); |
| 407 | wp_dashboard_recent_drafts(); |
| 408 | $result = ob_get_clean(); |
| 409 | |
| 410 | $this->assertTrue( !! strpos( $result, $expect ) ); |
| 411 | |
| 412 | restore_previous_locale(); |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * @ticket 44541 |
| 417 | */ |
| 418 | function test_length_of_draft_should_be_counted_by_chars_in_japanese() { |
| 419 | require_once dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . '/src/wp-admin/includes/dashboard.php'; |
| 420 | |
| 421 | switch_to_locale( 'ja_JP' ); |
| 422 | |
| 423 | $args = array( |
| 424 | 'post_content' => str_repeat( 'あ', 200 ), |
| 425 | 'post_excerpt' => '', |
| 426 | 'post_status' => 'draft', |
| 427 | ); |
| 428 | |
| 429 | $post = $this->factory()->post->create( $args ); |
| 430 | |
| 431 | $expect = str_repeat( 'あ', 40 ) . "…"; |
| 432 | |
| 433 | ob_start(); |
| 434 | wp_dashboard_recent_drafts(); |
| 435 | $result = ob_get_clean(); |
| 436 | |
| 437 | $this->assertTrue( !! strpos( $result, $expect ) ); |
| 438 | |
| 439 | restore_previous_locale(); |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * @ticket 44541 |
| 444 | */ |
| 445 | function test_length_of_comment_excerpt_should_be_counted_by_words() { |
| 446 | switch_to_locale( 'en_US' ); |
| 447 | |
| 448 | $args = array( |
| 449 | 'comment_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
| 450 | ); |
| 451 | |
| 452 | $comment_id = $this->factory()->comment->create( $args ); |
| 453 | |
| 454 | $expect = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut…"; |
| 455 | |
| 456 | $comment_excerpt = get_comment_excerpt( $comment_id ); |
| 457 | |
| 458 | $this->assertSame( $expect, $comment_excerpt ); |
| 459 | |
| 460 | restore_previous_locale(); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * @ticket 44541 |
| 465 | */ |
| 466 | function test_length_of_comment_excerpt_should_be_counted_by_chars() { |
| 467 | switch_to_locale( 'ja_JP' ); |
| 468 | |
| 469 | $args = array( |
| 470 | 'comment_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', |
| 471 | ); |
| 472 | |
| 473 | $comment_id = $this->factory()->comment->create( $args ); |
| 474 | |
| 475 | $expect = "Lorem ipsum dolor sit amet, consectetur …"; |
| 476 | |
| 477 | $comment_excerpt = get_comment_excerpt( $comment_id ); |
| 478 | |
| 479 | $this->assertSame( $expect, $comment_excerpt ); |
| 480 | |
| 481 | restore_previous_locale(); |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * @ticket 44541 |
| 486 | */ |
| 487 | function test_length_of_comment_excerpt_should_be_counted_by_chars_in_Japanese() { |
| 488 | switch_to_locale( 'ja_JP' ); |
| 489 | |
| 490 | $args = array( |
| 491 | 'comment_content' => str_repeat( 'あ', 200 ), |
| 492 | ); |
| 493 | |
| 494 | $comment_id = $this->factory()->comment->create( $args ); |
| 495 | |
| 496 | $expect = str_repeat( 'あ', 40 ) . "…"; |
| 497 | |
| 498 | $comment_excerpt = get_comment_excerpt( $comment_id ); |
| 499 | |
| 500 | $this->assertSame( $expect, $comment_excerpt ); |
| 501 | |
| 502 | restore_previous_locale(); |
| 503 | } |