| 542 | |
| 543 | /** |
| 544 | * Make sure invalid shortcode names are not allowed. |
| 545 | * |
| 546 | * @dataProvider data_registration_bad |
| 547 | * @expectedIncorrectUsage add_shortcode |
| 548 | */ |
| 549 | function test_registration_bad( $input, $expected ) { |
| 550 | return $this->sub_registration( $input, $expected ); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * Make sure valid shortcode names are allowed. |
| 555 | * |
| 556 | * @dataProvider data_registration_good |
| 557 | */ |
| 558 | function test_registration_good( $input, $expected ) { |
| 559 | return $this->sub_registration( $input, $expected ); |
| 560 | } |
| 561 | |
| 562 | function sub_registration( $input, $expected ) { |
| 563 | add_shortcode( $input, '' ); |
| 564 | $actual = shortcode_exists( $input ); |
| 565 | $test = $this->assertEquals( $expected, $actual ); |
| 566 | if ( $actual ) remove_shortcode( $input ); |
| 567 | return $test; |
| 568 | } |
| 569 | |
| 570 | function data_registration_bad() { |
| 571 | return array( |
| 572 | array( |
| 573 | '<html>', |
| 574 | false, |
| 575 | ), |
| 576 | array( |
| 577 | '[shortcode]', |
| 578 | false, |
| 579 | ), |
| 580 | array( |
| 581 | 'bad/', |
| 582 | false, |
| 583 | ), |
| 584 | array( |
| 585 | '/bad', |
| 586 | false, |
| 587 | ), |
| 588 | array( |
| 589 | 'bad space', |
| 590 | false, |
| 591 | ), |
| 592 | array( |
| 593 | '&', |
| 594 | false, |
| 595 | ), |
| 596 | array( |
| 597 | '', |
| 598 | false, |
| 599 | ), |
| 600 | ); |
| 601 | } |
| 602 | |
| 603 | function data_registration_good() { |
| 604 | return array( |
| 605 | array( |
| 606 | 'good!', |
| 607 | true, |
| 608 | ), |
| 609 | array( |
| 610 | 'plain', |
| 611 | true, |
| 612 | ), |
| 613 | array( |
| 614 | 'unreserved!#$%()*+,-.;?@^_{|}~chars', |
| 615 | true, |
| 616 | ), |
| 617 | ); |
| 618 | } |