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