| 583 | |
| 584 | /** |
| 585 | * Tests if has_shortcode() detects any shortcode without tag input argument. |
| 586 | * |
| 587 | * @ticket 31093 |
| 588 | */ |
| 589 | public function test_has_shortcode_should_detect_any_shortcode_without_tag_input_argument() { |
| 590 | // Empty. |
| 591 | $content = ''; |
| 592 | $this->assertFalse( has_shortcode( $content ) ); |
| 593 | |
| 594 | // Single shortcode. |
| 595 | $content = 'This is a blob with [gallery] in it'; |
| 596 | $this->assertTrue( has_shortcode( $content ) ); |
| 597 | |
| 598 | // Two shortcodes. |
| 599 | $content = 'This is a blob with [gallery] and [playlist] in it'; |
| 600 | $this->assertTrue( has_shortcode( $content ) ); |
| 601 | |
| 602 | // Un-registered [foo] shortcode. |
| 603 | $content = 'This is a blob with [foo] in it'; |
| 604 | $this->assertFalse( has_shortcode( $content ) ); |
| 605 | |
| 606 | // Nested shortcode. |
| 607 | $content = 'This is a blob with [foo][gallery][/foo] in it'; |
| 608 | $this->assertTrue( has_shortcode( $content ) ); |
| 609 | |
| 610 | // Register [foo] shortcode. |
| 611 | add_shortcode( 'foo', '__return_empty_string' ); |
| 612 | $this->assertTrue( has_shortcode( $content ) ); |
| 613 | remove_shortcode( 'foo' ); |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Tests if has_shortcode() detects any shortcode from a list of shortcodes. |
| 618 | * |
| 619 | * @ticket 31093 |
| 620 | */ |
| 621 | public function test_has_shortcode_should_detect_any_listed_shortcodes() { |
| 622 | // Empty. |
| 623 | $content = ''; |
| 624 | $this->assertFalse( has_shortcode( $content, array( 'gallery', 'playlist' ) ) ); |
| 625 | |
| 626 | // Single shortcode. |
| 627 | $content = 'This is a blob with [gallery] in it'; |
| 628 | $this->assertTrue( has_shortcode( $content, array( 'gallery', 'playlist' ), 'OR' ) ); |
| 629 | $this->assertTrue( has_shortcode( $content, array( 'gallery', 'playlist' ) ) ); |
| 630 | |
| 631 | // Two shortcodes. |
| 632 | $content = 'This is a blob with [foo], [gallery] and [playlist] in it'; |
| 633 | $this->assertTrue( has_shortcode( $content, array( 'gallery', 'playlist' ), 'OR' ) ); |
| 634 | $this->assertTrue( has_shortcode( $content, array( 'gallery', 'video' ), 'OR' ) ); |
| 635 | $this->assertFalse( has_shortcode( $content, array( 'foo' ), 'OR' ) ); |
| 636 | $this->assertFalse( has_shortcode( $content, array( 'foo' ) ) ); |
| 637 | |
| 638 | // Nested shortcode. |
| 639 | $content = 'This is a blob with [foo][gallery][/foo] in it'; |
| 640 | $this->assertTrue( has_shortcode( $content, array( 'gallery', 'foo' ), 'OR' ) ); |
| 641 | $this->assertFalse( has_shortcode( $content, array( 'video' ), 'OR' ) ); |
| 642 | |
| 643 | // Register [foo] shortcode. |
| 644 | add_shortcode( 'foo', '__return_empty_string' ); |
| 645 | $this->assertTrue( has_shortcode( $content, array( 'gallery', 'foo' ), 'OR' ) ); |
| 646 | $this->assertFalse( has_shortcode( $content, array( 'video' ), 'OR' ) ); |
| 647 | remove_shortcode( 'foo' ); |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * Tests if has_shortcode() detects all shortcodes from a list. |
| 652 | * |
| 653 | * @ticket 31093 |
| 654 | */ |
| 655 | public function test_has_shortcode_should_detect_all_listed_shortcodes() { |
| 656 | // Empty. |
| 657 | $content = ''; |
| 658 | $this->assertFalse( has_shortcode( $content, array( 'gallery', 'playlist' ), 'AND' ) ); |
| 659 | |
| 660 | // Single shortcode. |
| 661 | $content = 'This is a blob with [gallery] in it'; |
| 662 | $this->assertFalse( has_shortcode( $content, array( 'gallery', 'playlist' ), 'AND' ) ); |
| 663 | |
| 664 | // Two shortcodes. |
| 665 | $content = 'This is a blob with [gallery] and [playlist] in it'; |
| 666 | $this->assertTrue( has_shortcode( $content, array( 'gallery', 'playlist' ), 'AND' ) ); |
| 667 | $this->assertFalse( has_shortcode( $content, array( 'gallery', 'video' ), 'AND' ) ); |
| 668 | |
| 669 | // Non-existing [foo] shortcode. |
| 670 | $content = 'This is a blob with [foo] in it'; |
| 671 | $this->assertFalse( has_shortcode( $content, array( 'foo' ), 'AND' ) ); |
| 672 | |
| 673 | // Nested shortcode. |
| 674 | $content = 'This is a blob with [foo][gallery][/foo] in it'; |
| 675 | $this->assertFalse( has_shortcode( $content, array( 'gallery', 'foo' ), 'AND' ) ); |
| 676 | $this->assertFalse( has_shortcode( $content, array( 'gallery', 'video' ), 'AND' ) ); |
| 677 | |
| 678 | // Register [foo] shortcode. |
| 679 | add_shortcode( 'foo', '__return_empty_string' ); |
| 680 | $this->assertTrue( has_shortcode( $content, array( 'gallery', 'foo' ), 'AND' ) ); |
| 681 | $this->assertFalse( has_shortcode( $content, array( 'gallery', 'video' ), 'AND' ) ); |
| 682 | remove_shortcode( 'foo' ); |
| 683 | } |