| 523 | /** |
| 524 | * @ticket 36392 |
| 525 | */ |
| 526 | public function test_wp_add_inline_script_concat_with_core_dependency() { |
| 527 | global $wp_scripts; |
| 528 | |
| 529 | wp_default_scripts( $wp_scripts ); |
| 530 | |
| 531 | $wp_scripts->base_url = ''; |
| 532 | $wp_scripts->do_concat = true; |
| 533 | |
| 534 | $ver = get_bloginfo( 'version' ); |
| 535 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 536 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 537 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; |
| 538 | |
| 539 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 540 | wp_add_inline_script( 'test-example', 'console.log("after");' ); |
| 541 | |
| 542 | wp_print_scripts(); |
| 543 | $print_scripts = get_echo( '_print_scripts' ); |
| 544 | |
| 545 | $this->assertEquals( $expected, $print_scripts ); |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * @ticket 36392 |
| 550 | */ |
| 551 | public function test_wp_add_inline_script_concat_with_conditional_and_core_dependency() { |
| 552 | global $wp_scripts; |
| 553 | |
| 554 | wp_default_scripts( $wp_scripts ); |
| 555 | |
| 556 | $wp_scripts->base_url = ''; |
| 557 | $wp_scripts->do_concat = true; |
| 558 | |
| 559 | $ver = get_bloginfo( 'version' ); |
| 560 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 561 | $expected .= "<!--[if gte IE 9]>\n"; |
| 562 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 563 | $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; |
| 564 | $expected .= "<![endif]-->\n"; |
| 565 | |
| 566 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 567 | wp_add_inline_script( 'test-example', 'console.log("after");' ); |
| 568 | wp_script_add_data( 'test-example', 'conditional', 'gte IE 9' ); |
| 569 | |
| 570 | wp_print_scripts(); |
| 571 | $print_scripts = get_echo( '_print_scripts' ); |
| 572 | |
| 573 | $this->assertEquals( $expected, $print_scripts ); |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * @ticket 36392 |
| 578 | */ |
| 579 | public function test_wp_add_inline_script_before_concat_with_core_dependency() { |
| 580 | global $wp_scripts; |
| 581 | |
| 582 | wp_default_scripts( $wp_scripts ); |
| 583 | |
| 584 | $wp_scripts->base_url = ''; |
| 585 | $wp_scripts->do_concat = true; |
| 586 | |
| 587 | $ver = get_bloginfo( 'version' ); |
| 588 | $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core,jquery-migrate&ver={$ver}'></script>\n"; |
| 589 | $expected .= "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n"; |
| 590 | $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; |
| 591 | |
| 592 | wp_enqueue_script( 'test-example', 'http://example.com', array( 'jquery' ), null ); |
| 593 | wp_add_inline_script( 'test-example', 'console.log("before");', 'before' ); |
| 594 | |
| 595 | wp_print_scripts(); |
| 596 | $print_scripts = get_echo( '_print_scripts' ); |
| 597 | |
| 598 | $this->assertEquals( $expected, $print_scripts ); |
| 599 | } |