Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Tests_Formatting_WPTexturize often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Tests_Formatting_WPTexturize, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
6 | class Tests_Formatting_WPTexturize extends WP_UnitTestCase { |
||
7 | function test_dashes() { |
||
11 | |||
12 | function test_disable() { |
||
34 | |||
35 | //WP Ticket #1418 |
||
36 | function test_bracketed_quotes_1418() { |
||
41 | |||
42 | //WP Ticket #3810 |
||
43 | function test_bracketed_quotes_3810() { |
||
46 | |||
47 | //WP Ticket #4539 |
||
48 | View Code Duplication | function test_basic_quotes() { |
|
49 | $this->assertEquals('test’s', wptexturize('test\'s')); |
||
50 | |||
51 | $this->assertEquals('‘quoted’', wptexturize('\'quoted\'')); |
||
52 | $this->assertEquals('“quoted”', wptexturize('"quoted"')); |
||
53 | |||
54 | $this->assertEquals('space before ‘quoted’ space after', wptexturize('space before \'quoted\' space after')); |
||
55 | $this->assertEquals('space before “quoted” space after', wptexturize('space before "quoted" space after')); |
||
56 | |||
57 | $this->assertEquals('(‘quoted’)', wptexturize('(\'quoted\')')); |
||
58 | $this->assertEquals('{“quoted”}', wptexturize('{"quoted"}')); |
||
59 | |||
60 | $this->assertEquals('‘qu(ot)ed’', wptexturize('\'qu(ot)ed\'')); |
||
61 | $this->assertEquals('“qu{ot}ed”', wptexturize('"qu{ot}ed"')); |
||
62 | |||
63 | $this->assertEquals(' ‘test’s quoted’ ', wptexturize(' \'test\'s quoted\' ')); |
||
64 | $this->assertEquals(' “test’s quoted” ', wptexturize(' "test\'s quoted" ')); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @ticket 4539 |
||
69 | * @ticket 15241 |
||
70 | */ |
||
71 | function test_full_sentences_with_unmatched_single_quotes() { |
||
77 | |||
78 | /** |
||
79 | * @ticket 4539 |
||
80 | */ |
||
81 | function test_quotes() { |
||
96 | |||
97 | /** |
||
98 | * @ticket 4539 |
||
99 | */ |
||
100 | function test_quotes_before_s() { |
||
107 | |||
108 | /** |
||
109 | * @ticket 4539 |
||
110 | */ |
||
111 | function test_quotes_before_numbers() { |
||
136 | |||
137 | function test_quotes_after_numbers() { |
||
140 | |||
141 | /** |
||
142 | * @ticket 4539 |
||
143 | * @ticket 15241 |
||
144 | */ |
||
145 | function test_other_html() { |
||
150 | |||
151 | function test_x() { |
||
154 | |||
155 | View Code Duplication | function test_minutes_seconds() { |
|
156 | $this->assertEquals('9′', wptexturize('9\'')); |
||
157 | $this->assertEquals('9″', wptexturize("9\"")); |
||
158 | |||
159 | $this->assertEquals('a 9′ b', wptexturize('a 9\' b')); |
||
160 | $this->assertEquals('a 9″ b', wptexturize("a 9\" b")); |
||
161 | |||
162 | $this->assertEquals('“a 9′ b”', wptexturize('"a 9\' b"')); |
||
163 | $this->assertEquals('‘a 9″ b’', wptexturize("'a 9\" b'")); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @ticket 8775 |
||
168 | */ |
||
169 | function test_wptexturize_quotes_around_numbers() { |
||
175 | |||
176 | /** |
||
177 | * @ticket 8912 |
||
178 | */ |
||
179 | function test_wptexturize_html_comments() { |
||
184 | |||
185 | /** |
||
186 | * @ticket 4539 |
||
187 | * @ticket 15241 |
||
188 | */ |
||
189 | function test_entity_quote_cuddling() { |
||
193 | |||
194 | /** |
||
195 | * @ticket 22823 |
||
196 | */ |
||
197 | function test_apostrophes_before_primes() { |
||
200 | |||
201 | /** |
||
202 | * @ticket 23185 |
||
203 | */ |
||
204 | function test_spaces_around_hyphens() { |
||
223 | |||
224 | /** |
||
225 | * @ticket 31030 |
||
226 | */ |
||
227 | View Code Duplication | function test_hyphens_at_start_and_end() { |
|
228 | $this->assertEquals( '– ', wptexturize( '- ' ) ); |
||
229 | $this->assertEquals( '– –', wptexturize( '- -' ) ); |
||
230 | $this->assertEquals( ' –', wptexturize( ' -' ) ); |
||
231 | |||
232 | $this->assertEquals( '— ', wptexturize( '-- ' ) ); |
||
233 | $this->assertEquals( '— —', wptexturize( '-- --' ) ); |
||
234 | $this->assertEquals( ' —', wptexturize( ' --' ) ); |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * Test spaces around quotes. |
||
239 | * |
||
240 | * These should never happen, even if the desired output changes some day. |
||
241 | * |
||
242 | * @ticket 22692 |
||
243 | */ |
||
244 | function test_spaces_around_quotes_never() { |
||
252 | |||
253 | /** |
||
254 | * Test spaces around quotes. |
||
255 | * |
||
256 | * These are desirable outputs for the current design. |
||
257 | * |
||
258 | * @ticket 22692 |
||
259 | * @dataProvider data_spaces_around_quotes |
||
260 | */ |
||
261 | function test_spaces_around_quotes( $input, $output ) { |
||
264 | |||
265 | function data_spaces_around_quotes() { |
||
308 | |||
309 | /** |
||
310 | * Apostrophe before a number always becomes ’ (apos); |
||
311 | * |
||
312 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
313 | * |
||
314 | * @ticket 22692 |
||
315 | * @dataProvider data_apos_before_digits |
||
316 | */ |
||
317 | function test_apos_before_digits( $input, $output ) { |
||
320 | |||
321 | View Code Duplication | function data_apos_before_digits() { |
|
322 | return array( |
||
323 | array( |
||
324 | "word '99 word", |
||
325 | "word ’99 word", |
||
326 | ), |
||
327 | array( |
||
328 | "word'99 word", |
||
329 | "word’99 word", |
||
330 | ), |
||
331 | array( |
||
332 | "word '99word", |
||
333 | "word ’99word", |
||
334 | ), |
||
335 | array( |
||
336 | "word'99word", |
||
337 | "word’99word", |
||
338 | ), |
||
339 | array( |
||
340 | "word '99’s word", // Appears as a separate but logically superfluous pattern in 3.8. |
||
341 | "word ’99’s word", |
||
342 | ), |
||
343 | array( |
||
344 | "according to our source, '33 students scored less than 50' on the test.", // Apostrophes and primes have priority over quotes |
||
345 | "according to our source, ’33 students scored less than 50′ on the test.", |
||
346 | ), |
||
347 | ); |
||
348 | } |
||
349 | |||
350 | /** |
||
351 | * Apostrophe after a space or ([{<" becomes ‘ (opening_single_quote) |
||
352 | * |
||
353 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
354 | * |
||
355 | * @ticket 22692 |
||
356 | * @dataProvider data_opening_single_quote |
||
357 | */ |
||
358 | function test_opening_single_quote( $input, $output ) { |
||
361 | |||
362 | function data_opening_single_quote() { |
||
478 | |||
479 | /** |
||
480 | * Double quote after a number becomes ″ (double_prime) |
||
481 | * |
||
482 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
483 | * |
||
484 | * @ticket 22692 |
||
485 | * @dataProvider data_double_prime |
||
486 | */ |
||
487 | function test_double_prime( $input, $output ) { |
||
490 | |||
491 | View Code Duplication | function data_double_prime() { |
|
492 | return array( |
||
493 | array( |
||
494 | 'word 99" word', |
||
495 | 'word 99″ word', |
||
496 | ), |
||
497 | array( |
||
498 | 'word 99"word', |
||
499 | 'word 99″word', |
||
500 | ), |
||
501 | array( |
||
502 | 'word99" word', |
||
503 | 'word99″ word', |
||
504 | ), |
||
505 | array( |
||
506 | 'word99"word', |
||
507 | 'word99″word', |
||
508 | ), |
||
509 | ); |
||
510 | } |
||
511 | |||
512 | /** |
||
513 | * Apostrophe after a number becomes ′ (prime) |
||
514 | * |
||
515 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
516 | * |
||
517 | * @ticket 22692 |
||
518 | * @dataProvider data_single_prime |
||
519 | */ |
||
520 | function test_single_prime( $input, $output ) { |
||
523 | |||
524 | View Code Duplication | function data_single_prime() { |
|
525 | return array( |
||
526 | array( |
||
527 | "word 99' word", |
||
528 | "word 99′ word", |
||
529 | ), |
||
530 | array( |
||
531 | "word 99'word", // Not a prime anymore. Apostrophes get priority. |
||
532 | "word 99’word", |
||
533 | ), |
||
534 | array( |
||
535 | "word99' word", |
||
536 | "word99′ word", |
||
537 | ), |
||
538 | array( |
||
539 | "word99'word", // Not a prime anymore. |
||
540 | "word99’word", |
||
541 | ), |
||
542 | ); |
||
543 | } |
||
544 | |||
545 | /** |
||
546 | * Apostrophe "in a word" becomes ’ (apos) |
||
547 | * |
||
548 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
549 | * |
||
550 | * @ticket 22692 |
||
551 | * @dataProvider data_contractions |
||
552 | */ |
||
553 | function test_contractions( $input, $output ) { |
||
556 | |||
557 | View Code Duplication | function data_contractions() { |
|
558 | return array( |
||
559 | array( |
||
560 | "word word's word", |
||
561 | "word word’s word", |
||
562 | ), |
||
563 | array( |
||
564 | "word'[ word", // Apostrophes are never followed by opening punctuation. |
||
565 | "word'[ word", |
||
566 | ), |
||
567 | array( |
||
568 | "word'( word", |
||
569 | "word'( word", |
||
570 | ), |
||
571 | array( |
||
572 | "word'{ word", |
||
573 | "word'{ word", |
||
574 | ), |
||
575 | array( |
||
576 | "word'< word", |
||
577 | "word'< word", |
||
578 | ), |
||
579 | array( |
||
580 | "word'< word", // Invalid HTML input does trigger the apos pattern. |
||
581 | "word’< word", |
||
582 | ), |
||
583 | ); |
||
584 | } |
||
585 | |||
586 | /** |
||
587 | * Double quote after a space or ([-{< becomes “ (opening_quote) if not followed by spaces |
||
588 | * |
||
589 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
590 | * |
||
591 | * @ticket 22692 |
||
592 | * @dataProvider data_opening_quote |
||
593 | */ |
||
594 | function test_opening_quote( $input, $output ) { |
||
597 | |||
598 | View Code Duplication | function data_opening_quote() { |
|
599 | return array( |
||
600 | array( |
||
601 | 'word "word word', |
||
602 | 'word “word word', |
||
603 | ), |
||
604 | array( |
||
605 | 'word ("word word', |
||
606 | 'word (“word word', |
||
607 | ), |
||
608 | array( |
||
609 | 'word ["word word', |
||
610 | 'word [“word word', |
||
611 | ), |
||
612 | array( |
||
613 | 'word <"word word', // Invalid HTML |
||
614 | 'word <"word word', |
||
615 | ), |
||
616 | array( |
||
617 | 'word <"word word', |
||
618 | 'word <“word word', |
||
619 | ), |
||
620 | array( |
||
621 | 'word {"word word', |
||
622 | 'word {“word word', |
||
623 | ), |
||
624 | array( |
||
625 | 'word -"word word', |
||
626 | 'word -“word word', |
||
627 | ), |
||
628 | array( |
||
629 | 'word-"word word', |
||
630 | 'word-“word word', |
||
631 | ), |
||
632 | array( |
||
633 | '"word word', |
||
634 | '“word word', |
||
635 | ), |
||
636 | array( |
||
637 | 'word("word word', |
||
638 | 'word(“word word', |
||
639 | ), |
||
640 | array( |
||
641 | 'word["word word', |
||
642 | 'word[“word word', |
||
643 | ), |
||
644 | array( |
||
645 | 'word<"word word', |
||
646 | 'word<"word word', |
||
647 | ), |
||
648 | array( |
||
649 | 'word<"word word', |
||
650 | 'word<“word word', |
||
651 | ), |
||
652 | array( |
||
653 | 'word{"word word', |
||
654 | 'word{“word word', |
||
655 | ), |
||
656 | array( |
||
657 | 'word "99 word', |
||
658 | 'word “99 word', |
||
659 | ), |
||
660 | ); |
||
661 | } |
||
662 | |||
663 | /** |
||
664 | * Double quote becomes ” (closing_quote) unless it is already converted to double_prime or opening_quote. |
||
665 | * |
||
666 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
667 | * |
||
668 | * @ticket 22692 |
||
669 | * @dataProvider data_closing_quote |
||
670 | */ |
||
671 | function test_closing_quote( $input, $output ) { |
||
674 | |||
675 | View Code Duplication | function data_closing_quote() { |
|
676 | return array( |
||
677 | array( |
||
678 | 'word word" word', |
||
679 | 'word word” word', |
||
680 | ), |
||
681 | array( |
||
682 | 'word word") word', |
||
683 | 'word word”) word', |
||
684 | ), |
||
685 | array( |
||
686 | 'word word"] word', |
||
687 | 'word word”] word', |
||
688 | ), |
||
689 | array( |
||
690 | 'word word"} word', |
||
691 | 'word word”} word', |
||
692 | ), |
||
693 | array( |
||
694 | 'word word"> word', // Invalid HTML input? |
||
695 | 'word word”> word', |
||
696 | ), |
||
697 | array( |
||
698 | 'word word"> word', // Valid HTML should work |
||
699 | 'word word”> word', |
||
700 | ), |
||
701 | array( |
||
702 | 'word word"', |
||
703 | 'word word”', |
||
704 | ), |
||
705 | array( |
||
706 | 'word word"word', |
||
707 | 'word word”word', |
||
708 | ), |
||
709 | array( |
||
710 | 'word"word"word', |
||
711 | 'word”word”word', |
||
712 | ), |
||
713 | array( |
||
714 | 'test sentence".', |
||
715 | 'test sentence”.', |
||
716 | ), |
||
717 | array( |
||
718 | 'test sentence",', |
||
719 | 'test sentence”,', |
||
720 | ), |
||
721 | array( |
||
722 | 'test sentence":', |
||
723 | 'test sentence”:', |
||
724 | ), |
||
725 | array( |
||
726 | 'test sentence";', |
||
727 | 'test sentence”;', |
||
728 | ), |
||
729 | array( |
||
730 | 'test sentence"!', |
||
731 | 'test sentence”!', |
||
732 | ), |
||
733 | array( |
||
734 | 'test sentence"?', |
||
735 | 'test sentence”?', |
||
736 | ), |
||
737 | array( |
||
738 | 'test sentence."', |
||
739 | 'test sentence.”', |
||
740 | ), |
||
741 | array( |
||
742 | 'test sentence". word', |
||
743 | 'test sentence”. word', |
||
744 | ), |
||
745 | array( |
||
746 | 'test sentence." word', |
||
747 | 'test sentence.” word', |
||
748 | ), |
||
749 | ); |
||
750 | } |
||
751 | |||
752 | /** |
||
753 | * Test that single quotes followed by a space or .,-)}]> become ’ (closing_single_quote) |
||
754 | * |
||
755 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
756 | * |
||
757 | * @ticket 22692 |
||
758 | * @dataProvider data_closing_single_quote |
||
759 | */ |
||
760 | function test_closing_single_quote( $input, $output ) { |
||
763 | |||
764 | View Code Duplication | function data_closing_single_quote() { |
|
765 | return array( |
||
766 | array( |
||
767 | "word word' word", |
||
768 | "word word’ word", |
||
769 | ), |
||
770 | array( |
||
771 | "word word'. word", |
||
772 | "word word’. word", |
||
773 | ), |
||
774 | array( |
||
775 | "word word'.word", |
||
776 | "word word’.word", |
||
777 | ), |
||
778 | array( |
||
779 | "word word', she said", |
||
780 | "word word’, she said", |
||
781 | ), |
||
782 | array( |
||
783 | "word word': word", |
||
784 | "word word’: word", |
||
785 | ), |
||
786 | array( |
||
787 | "word word'; word", |
||
788 | "word word’; word", |
||
789 | ), |
||
790 | array( |
||
791 | "word word'! word", |
||
792 | "word word’! word", |
||
793 | ), |
||
794 | array( |
||
795 | "word word'? word", |
||
796 | "word word’? word", |
||
797 | ), |
||
798 | array( |
||
799 | "word word'- word", |
||
800 | "word word’- word", |
||
801 | ), |
||
802 | array( |
||
803 | "word word') word", |
||
804 | "word word’) word", |
||
805 | ), |
||
806 | array( |
||
807 | "word word'} word", |
||
808 | "word word’} word", |
||
809 | ), |
||
810 | array( |
||
811 | "word word'] word", |
||
812 | "word word’] word", |
||
813 | ), |
||
814 | array( |
||
815 | "word word'> word", |
||
816 | "word word’> word", |
||
817 | ), |
||
818 | array( |
||
819 | "word word'", |
||
820 | "word word’", |
||
821 | ), |
||
822 | array( |
||
823 | "test sentence'.", |
||
824 | "test sentence’.", |
||
825 | ), |
||
826 | array( |
||
827 | "test sentence.'", |
||
828 | "test sentence.’", |
||
829 | ), |
||
830 | array( |
||
831 | "test sentence'. word", |
||
832 | "test sentence’. word", |
||
833 | ), |
||
834 | array( |
||
835 | "test sentence.' word", |
||
836 | "test sentence.’ word", |
||
837 | ), |
||
838 | ); |
||
839 | } |
||
840 | |||
841 | /** |
||
842 | * Tests multiplication. |
||
843 | * |
||
844 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
845 | * |
||
846 | * @ticket 22692 |
||
847 | * @dataProvider data_multiplication |
||
848 | */ |
||
849 | function test_multiplication( $input, $output ) { |
||
852 | |||
853 | function data_multiplication() { |
||
890 | |||
891 | /** |
||
892 | * Test ampersands. & always becomes & unless it is followed by # or ; |
||
893 | * |
||
894 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
895 | * |
||
896 | * @ticket 22692 |
||
897 | * @dataProvider data_ampersand |
||
898 | */ |
||
899 | function test_ampersand( $input, $output ) { |
||
902 | |||
903 | View Code Duplication | function data_ampersand() { |
|
904 | return array( |
||
905 | array( |
||
906 | "word & word", |
||
907 | "word & word", |
||
908 | ), |
||
909 | array( |
||
910 | "word&word", |
||
911 | "word&word", |
||
912 | ), |
||
913 | array( |
||
914 | "word word", |
||
915 | "word word", |
||
916 | ), |
||
917 | array( |
||
918 | "word & word", |
||
919 | "word & word", |
||
920 | ), |
||
921 | array( |
||
922 | "word ઼ word", |
||
923 | "word ઼ word", |
||
924 | ), |
||
925 | array( |
||
926 | "word Δ word", |
||
927 | "word Δ word", |
||
928 | ), |
||
929 | array( |
||
930 | "word &# word", |
||
931 | "word &# word", |
||
932 | ), |
||
933 | array( |
||
934 | "word &44; word", |
||
935 | "word &44; word", |
||
936 | ), |
||
937 | array( |
||
938 | "word && word", |
||
939 | "word && word", |
||
940 | ), |
||
941 | array( |
||
942 | "word &!amp; word", |
||
943 | "word &!amp; word", |
||
944 | ), |
||
945 | array( |
||
946 | "word &#", |
||
947 | "word &#", |
||
948 | ), |
||
949 | array( |
||
950 | "word &", |
||
951 | "word &", |
||
952 | ), |
||
953 | ); |
||
954 | } |
||
955 | |||
956 | /** |
||
957 | * Test "cockney" phrases, which begin with an apostrophe instead of an opening single quote. |
||
958 | * |
||
959 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
960 | * |
||
961 | * @ticket 22692 |
||
962 | * @dataProvider data_cockney |
||
963 | */ |
||
964 | function test_cockney( $input, $output ) { |
||
967 | |||
968 | View Code Duplication | function data_cockney() { |
|
969 | return array( |
||
970 | array( |
||
971 | "word 'tain't word", |
||
972 | "word ’tain’t word", |
||
973 | ), |
||
974 | array( |
||
975 | "word 'twere word", |
||
976 | "word ’twere word", |
||
977 | ), |
||
978 | array( |
||
979 | "word 'twas word", |
||
980 | "word ’twas word", |
||
981 | ), |
||
982 | array( |
||
983 | "word 'tis word", |
||
984 | "word ’tis word", |
||
985 | ), |
||
986 | array( |
||
987 | "word 'twill word", |
||
988 | "word ’twill word", |
||
989 | ), |
||
990 | array( |
||
991 | "word 'til word", |
||
992 | "word ’til word", |
||
993 | ), |
||
994 | array( |
||
995 | "word 'bout word", |
||
996 | "word ’bout word", |
||
997 | ), |
||
998 | array( |
||
999 | "word 'nuff word", |
||
1000 | "word ’nuff word", |
||
1001 | ), |
||
1002 | array( |
||
1003 | "word 'round word", |
||
1004 | "word ’round word", |
||
1005 | ), |
||
1006 | array( |
||
1007 | "word 'cause word", |
||
1008 | "word ’cause word", |
||
1009 | ), |
||
1010 | array( |
||
1011 | "word 'em word", |
||
1012 | "word ’em word", |
||
1013 | ), |
||
1014 | ); |
||
1015 | } |
||
1016 | |||
1017 | /** |
||
1018 | * Test smart dashes. |
||
1019 | * |
||
1020 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
1021 | * |
||
1022 | * @ticket 22692 |
||
1023 | * @dataProvider data_smart_dashes |
||
1024 | */ |
||
1025 | function test_smart_dashes( $input, $output ) { |
||
1028 | |||
1029 | function data_smart_dashes() { |
||
1069 | |||
1070 | /** |
||
1071 | * Test miscellaneous static replacements. |
||
1072 | * |
||
1073 | * Checks all baseline patterns. If anything ever changes in wptexturize(), these tests may fail. |
||
1074 | * |
||
1075 | * @ticket 22692 |
||
1076 | * @dataProvider data_misc_static_replacements |
||
1077 | */ |
||
1078 | function test_misc_static_replacements( $input, $output ) { |
||
1081 | |||
1082 | function data_misc_static_replacements() { |
||
1126 | |||
1127 | /** |
||
1128 | * Numbers inside of matching quotes get curly quotes instead of apostrophes and primes. |
||
1129 | * |
||
1130 | * @ticket 8775 |
||
1131 | * @dataProvider data_quoted_numbers |
||
1132 | */ |
||
1133 | function test_quoted_numbers( $input, $output ) { |
||
1136 | |||
1137 | View Code Duplication | function data_quoted_numbers() { |
|
1138 | return array( |
||
1139 | array( |
||
1140 | 'word "42.00" word', |
||
1141 | 'word “42.00” word', |
||
1142 | ), |
||
1143 | array( |
||
1144 | 'word "42.00"word', |
||
1145 | 'word “42.00”word', |
||
1146 | ), |
||
1147 | array( |
||
1148 | "word '42.00' word", |
||
1149 | "word ‘42.00’ word", |
||
1150 | ), |
||
1151 | array( |
||
1152 | "word '42.00'word", |
||
1153 | "word ‘42.00’word", |
||
1154 | ), |
||
1155 | array( |
||
1156 | 'word "42" word', |
||
1157 | 'word “42” word', |
||
1158 | ), |
||
1159 | array( |
||
1160 | 'word "42,00" word', |
||
1161 | 'word “42,00” word', |
||
1162 | ), |
||
1163 | array( |
||
1164 | 'word "4,242.00" word', |
||
1165 | 'word “4,242.00” word', |
||
1166 | ), |
||
1167 | array( |
||
1168 | "word '99's word", |
||
1169 | "word ’99’s word", |
||
1170 | ), |
||
1171 | array( |
||
1172 | "word '99'samsonite", |
||
1173 | "word ’99’samsonite", |
||
1174 | ), |
||
1175 | ); |
||
1176 | } |
||
1177 | |||
1178 | /** |
||
1179 | * Quotations should be allowed to have dashes around them. |
||
1180 | * |
||
1181 | * @ticket 20342 |
||
1182 | * @dataProvider data_quotes_and_dashes |
||
1183 | */ |
||
1184 | function test_quotes_and_dashes( $input, $output ) { |
||
1187 | |||
1188 | View Code Duplication | function data_quotes_and_dashes() { |
|
1189 | return array( |
||
1190 | array( |
||
1191 | 'word---"quote"', |
||
1192 | 'word—“quote”', |
||
1193 | ), |
||
1194 | array( |
||
1195 | 'word--"quote"', |
||
1196 | 'word–“quote”', |
||
1197 | ), |
||
1198 | array( |
||
1199 | 'word-"quote"', |
||
1200 | 'word-“quote”', |
||
1201 | ), |
||
1202 | array( |
||
1203 | "word---'quote'", |
||
1204 | "word—‘quote’", |
||
1205 | ), |
||
1206 | array( |
||
1207 | "word--'quote'", |
||
1208 | "word–‘quote’", |
||
1209 | ), |
||
1210 | array( |
||
1211 | "word-'quote'", |
||
1212 | "word-‘quote’", |
||
1213 | ), |
||
1214 | array( |
||
1215 | '"quote"---word', |
||
1216 | '“quote”—word', |
||
1217 | ), |
||
1218 | array( |
||
1219 | '"quote"--word', |
||
1220 | '“quote”–word', |
||
1221 | ), |
||
1222 | array( |
||
1223 | '"quote"-word', |
||
1224 | '“quote”-word', |
||
1225 | ), |
||
1226 | array( |
||
1227 | "'quote'---word", |
||
1228 | "‘quote’—word", |
||
1229 | ), |
||
1230 | array( |
||
1231 | "'quote'--word", |
||
1232 | "‘quote’–word", |
||
1233 | ), |
||
1234 | array( |
||
1235 | "'quote'-word", |
||
1236 | "‘quote’-word", |
||
1237 | ), |
||
1238 | ); |
||
1239 | } |
||
1240 | |||
1241 | /** |
||
1242 | * Test HTML and shortcode avoidance. |
||
1243 | * |
||
1244 | * @ticket 12690 |
||
1245 | * @dataProvider data_tag_avoidance |
||
1246 | */ |
||
1247 | function test_tag_avoidance( $input, $output ) { |
||
1250 | |||
1251 | function data_tag_avoidance() { |
||
1463 | |||
1464 | /** |
||
1465 | * Year abbreviations consist of exactly two digits. |
||
1466 | * |
||
1467 | * @ticket 26850 |
||
1468 | * @dataProvider data_year_abbr |
||
1469 | */ |
||
1470 | function test_year_abbr( $input, $output ) { |
||
1473 | |||
1474 | View Code Duplication | function data_year_abbr() { |
|
1475 | return array( |
||
1476 | array( |
||
1477 | "word '99 word", |
||
1478 | "word ’99 word", |
||
1479 | ), |
||
1480 | array( |
||
1481 | "word '99. word", |
||
1482 | "word ’99. word", |
||
1483 | ), |
||
1484 | array( |
||
1485 | "word '99, word", |
||
1486 | "word ’99, word", |
||
1487 | ), |
||
1488 | array( |
||
1489 | "word '99; word", |
||
1490 | "word ’99; word", |
||
1491 | ), |
||
1492 | array( |
||
1493 | "word '99' word", // For this pattern, prime doesn't make sense. Should get apos and a closing quote. |
||
1494 | "word ’99’ word", |
||
1495 | ), |
||
1496 | array( |
||
1497 | "word '99'. word", |
||
1498 | "word ’99’. word", |
||
1499 | ), |
||
1500 | array( |
||
1501 | "word '99', word", |
||
1502 | "word ’99’, word", |
||
1503 | ), |
||
1504 | array( |
||
1505 | "word '99.' word", |
||
1506 | "word ’99.’ word", |
||
1507 | ), |
||
1508 | array( |
||
1509 | "word '99", |
||
1510 | "word ’99", |
||
1511 | ), |
||
1512 | array( |
||
1513 | "'99 word", |
||
1514 | "’99 word", |
||
1515 | ), |
||
1516 | array( |
||
1517 | "word '999 word", // Does not match the apos pattern, should be opening quote. |
||
1518 | "word ‘999 word", |
||
1519 | ), |
||
1520 | array( |
||
1521 | "word '99% word", |
||
1522 | "word ‘99% word", |
||
1523 | ), |
||
1524 | array( |
||
1525 | "word '9 word", |
||
1526 | "word ‘9 word", |
||
1527 | ), |
||
1528 | array( |
||
1529 | "word '99.9 word", |
||
1530 | "word ‘99.9 word", |
||
1531 | ), |
||
1532 | array( |
||
1533 | "word '999", |
||
1534 | "word ‘999", |
||
1535 | ), |
||
1536 | array( |
||
1537 | "word '9", |
||
1538 | "word ‘9", |
||
1539 | ), |
||
1540 | array( |
||
1541 | "in '4 years, 3 months,' Obama cut the deficit", |
||
1542 | "in ‘4 years, 3 months,’ Obama cut the deficit", |
||
1543 | ), |
||
1544 | array( |
||
1545 | "testing's '4' through 'quotes'", |
||
1546 | "testing’s ‘4’ through ‘quotes’", |
||
1547 | ), |
||
1548 | ); |
||
1549 | } |
||
1550 | |||
1551 | /** |
||
1552 | * Make sure translation actually works. |
||
1553 | * |
||
1554 | * Also make sure apostrophes and closing quotes aren't being confused by default. |
||
1555 | * |
||
1556 | * @ticket 27426 |
||
1557 | * @dataProvider data_translate |
||
1558 | */ |
||
1559 | View Code Duplication | function test_translate( $input, $output ) { |
|
1560 | add_filter( 'gettext_with_context', array( $this, 'filter_translate' ), 10, 4 ); |
||
1561 | |||
1562 | $result = wptexturize( $input, true ); |
||
1563 | |||
1564 | remove_filter( 'gettext_with_context', array( $this, 'filter_translate' ), 10, 4 ); |
||
1565 | wptexturize( 'reset', true ); |
||
1566 | |||
1567 | return $this->assertEquals( $output, $result ); |
||
1568 | } |
||
1569 | |||
1570 | View Code Duplication | function filter_translate( $translations, $text, $context, $domain ) { |
|
1571 | switch ($text) { |
||
1572 | case '–' : return '!endash!'; |
||
1573 | case '—' : return '!emdash!'; |
||
1574 | case '‘' : return '!openq1!'; |
||
1575 | case '’' : |
||
1576 | if ( 'apostrophe' == $context ) { |
||
1577 | return '!apos!'; |
||
1578 | } else { |
||
1579 | return '!closeq1!'; |
||
1580 | } |
||
1581 | case '“' : return '!openq2!'; |
||
1582 | case '”' : return '!closeq2!'; |
||
1583 | case '′' : return '!prime1!'; |
||
1584 | case '″' : return '!prime2!'; |
||
1585 | case '’tain’t,’twere,’twas,’tis,’twill,’til,’bout,’nuff,’round,’cause,’em' : |
||
1586 | return '!apos!tain!apos!t,!apos!twere,!apos!twas,!apos!tis,!apos!twill,!apos!til,!apos!bout,!apos!nuff,!apos!round,!apos!cause,!apos!em'; |
||
1587 | default : return $translations; |
||
1588 | } |
||
1589 | } |
||
1590 | |||
1591 | function data_translate() { |
||
1771 | |||
1772 | /** |
||
1773 | * Extra sanity checks for _wptexturize_pushpop_element() |
||
1774 | * |
||
1775 | * @ticket 28483 |
||
1776 | * @dataProvider data_element_stack |
||
1777 | */ |
||
1778 | function test_element_stack( $input, $output ) { |
||
1781 | |||
1782 | View Code Duplication | function data_element_stack() { |
|
1783 | return array( |
||
1784 | array( |
||
1785 | '<span>hello</code>---</span>', |
||
1786 | '<span>hello</code>—</span>', |
||
1787 | ), |
||
1788 | array( |
||
1789 | '</code>hello<span>---</span>', |
||
1790 | '</code>hello<span>—</span>', |
||
1791 | ), |
||
1792 | array( |
||
1793 | '<code>hello</code>---</span>', |
||
1794 | '<code>hello</code>—</span>', |
||
1795 | ), |
||
1796 | array( |
||
1797 | '<span>hello</span>---<code>', |
||
1798 | '<span>hello</span>—<code>', |
||
1799 | ), |
||
1800 | array( |
||
1801 | '<span>hello<code>---</span>', |
||
1802 | '<span>hello<code>---</span>', |
||
1803 | ), |
||
1804 | array( |
||
1805 | '<code>hello<span>---</span>', |
||
1806 | '<code>hello<span>---</span>', |
||
1807 | ), |
||
1808 | array( |
||
1809 | '<code>hello</span>---</span>', |
||
1810 | '<code>hello</span>---</span>', |
||
1811 | ), |
||
1812 | array( |
||
1813 | '<span><code>hello</code>---</span>', |
||
1814 | '<span><code>hello</code>—</span>', |
||
1815 | ), |
||
1816 | array( |
||
1817 | '<code>hello</code>world<span>---</span>', |
||
1818 | '<code>hello</code>world<span>—</span>', |
||
1819 | ), |
||
1820 | ); |
||
1821 | } |
||
1822 | |||
1823 | /** |
||
1824 | * Test disabling shortcode texturization. |
||
1825 | * |
||
1826 | * @ticket 29557 |
||
1827 | * @dataProvider data_unregistered_shortcodes |
||
1828 | */ |
||
1829 | function test_unregistered_shortcodes( $input, $output ) { |
||
1837 | |||
1838 | function filter_shortcodes( $disabled ) { |
||
1842 | |||
1843 | View Code Duplication | function data_unregistered_shortcodes() { |
|
1844 | return array( |
||
1845 | array( |
||
1846 | '[a]a--b[audio]---[/audio]a--b[/a]', |
||
1847 | '[a]a–b[audio]---[/audio]a–b[/a]', |
||
1848 | ), |
||
1849 | array( |
||
1850 | '[code ...]...[/code]', // code is not a registered shortcode. |
||
1851 | '[code …]…[/code]', |
||
1852 | ), |
||
1853 | array( |
||
1854 | '[hello ...]...[/hello]', // hello is not a registered shortcode. |
||
1855 | '[hello …]…[/hello]', |
||
1856 | ), |
||
1857 | array( |
||
1858 | '[...]...[/...]', // These are potentially usable shortcodes. |
||
1859 | '[…]…[/…]', |
||
1860 | ), |
||
1861 | array( |
||
1862 | '[gal>ery ...]', |
||
1863 | '[gal>ery …]', |
||
1864 | ), |
||
1865 | array( |
||
1866 | '[randomthing param="test"]', |
||
1867 | '[randomthing param=”test”]', |
||
1868 | ), |
||
1869 | array( |
||
1870 | '[[audio]...[/audio]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [[audio] is ambiguous unless we run the entire shortcode regexp. |
||
1871 | '[[audio]…[/audio]…', |
||
1872 | ), |
||
1873 | array( |
||
1874 | '[audio]...[/audio]]...', // These are potentially usable shortcodes. Unfortunately, the meaning of [/audio]] is ambiguous unless we run the entire shortcode regexp. |
||
1875 | '[audio]...[/audio]]...', // This test would not pass in 3.9 because the extra brace was always ignored by texturize. |
||
1876 | ), |
||
1877 | array( |
||
1878 | '<span>hello[/audio]---</span>', |
||
1879 | '<span>hello[/audio]—</span>', |
||
1880 | ), |
||
1881 | array( |
||
1882 | '[/audio]hello<span>---</span>', |
||
1883 | '[/audio]hello<span>—</span>', |
||
1884 | ), |
||
1885 | array( |
||
1886 | '[audio]hello[/audio]---</span>', |
||
1887 | '[audio]hello[/audio]—</span>', |
||
1888 | ), |
||
1889 | array( |
||
1890 | '<span>hello</span>---[audio]', |
||
1891 | '<span>hello</span>—[audio]', |
||
1892 | ), |
||
1893 | array( |
||
1894 | '<span>hello[audio]---</span>', |
||
1895 | '<span>hello[audio]---</span>', |
||
1896 | ), |
||
1897 | array( |
||
1898 | '[audio]hello<span>---</span>', |
||
1899 | '[audio]hello<span>---</span>', |
||
1900 | ), |
||
1901 | array( |
||
1902 | '[audio]hello</span>---</span>', |
||
1903 | '[audio]hello</span>---</span>', |
||
1904 | ), |
||
1905 | ); |
||
1906 | } |
||
1907 | |||
1908 | /** |
||
1909 | * Ensure primes logic is not too greedy at the end of a quotation. |
||
1910 | * |
||
1911 | * @ticket 29256 |
||
1912 | * @dataProvider data_primes_vs_quotes |
||
1913 | */ |
||
1914 | function test_primes_vs_quotes( $input, $output ) { |
||
1917 | |||
1918 | function data_primes_vs_quotes() { |
||
1967 | |||
1968 | /** |
||
1969 | * Make sure translation actually works. |
||
1970 | * |
||
1971 | * Also make sure opening and closing quotes are allowed to be identical. |
||
1972 | * |
||
1973 | * @ticket 29256 |
||
1974 | * @dataProvider data_primes_quotes_translation |
||
1975 | */ |
||
1976 | View Code Duplication | function test_primes_quotes_translation( $input, $output ) { |
|
1977 | add_filter( 'gettext_with_context', array( $this, 'filter_translate2' ), 10, 4 ); |
||
1978 | |||
1979 | $result = wptexturize( $input, true ); |
||
1980 | |||
1981 | remove_filter( 'gettext_with_context', array( $this, 'filter_translate2' ), 10, 4 ); |
||
1982 | wptexturize( 'reset', true ); |
||
1983 | |||
1984 | return $this->assertEquals( $output, $result ); |
||
1985 | } |
||
1986 | |||
1987 | View Code Duplication | function filter_translate2( $translations, $text, $context, $domain ) { |
|
1988 | switch ($text) { |
||
1989 | case '–' : return '!endash!'; |
||
1990 | case '—' : return '!emdash!'; |
||
1991 | case '‘' : return '!q1!'; |
||
1992 | case '’' : |
||
1993 | if ( 'apostrophe' == $context ) { |
||
1994 | return '!apos!'; |
||
1995 | } else { |
||
1996 | return '!q1!'; |
||
1997 | } |
||
1998 | case '“' : return '!q2!'; |
||
1999 | case '”' : return '!q2!'; |
||
2000 | case '′' : return '!prime1!'; |
||
2001 | case '″' : return '!prime2!'; |
||
2002 | default : return $translations; |
||
2003 | } |
||
2004 | } |
||
2005 | |||
2006 | function data_primes_quotes_translation() { |
||
2055 | |||
2056 | /** |
||
2057 | * Automated performance testing of the main regex. |
||
2058 | * |
||
2059 | * @dataProvider data_whole_posts |
||
2060 | */ |
||
2061 | function test_pcre_performance( $input ) { |
||
2075 | |||
2076 | /** |
||
2077 | * Ensure that a trailing less-than symbol doesn't cause a PHP warning. |
||
2078 | * |
||
2079 | * @ticket 35864 |
||
2080 | */ |
||
2081 | function test_trailing_less_than() { |
||
2084 | |||
2085 | function data_whole_posts() { |
||
2089 | } |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.