| 33 | | } |
| 34 | | No newline at end of file |
| | 33 | /** |
| | 34 | * @ticket 13651 |
| | 35 | */ |
| | 36 | function test_get_comments_number_text_declension_with_default_args() { |
| | 37 | $post_id = $this->factory->post->create(); |
| | 38 | $permalink = get_permalink( $post_id ); |
| | 39 | $this->go_to( $permalink ); |
| | 40 | |
| | 41 | $this->assertEquals( __( 'No Comments' ), get_comments_number_text() ); |
| | 42 | |
| | 43 | $this->factory->comment->create_post_comments( $post_id, 1 ); |
| | 44 | $this->go_to( $permalink ); |
| | 45 | |
| | 46 | $this->assertEquals( __( '1 Comment' ), get_comments_number_text() ); |
| | 47 | |
| | 48 | $this->factory->comment->create_post_comments( $post_id, 1 ); |
| | 49 | $this->go_to( $permalink ); |
| | 50 | |
| | 51 | $this->assertEquals( sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), get_comments_number_text() ); |
| | 52 | |
| | 53 | } |
| | 54 | |
| | 55 | /** |
| | 56 | * @ticket 13651 |
| | 57 | * @dataProvider data_get_comments_number_text_declension |
| | 58 | */ |
| | 59 | function test_get_comments_number_text_declension_with_custom_args( $number, $input, $output ) { |
| | 60 | $post_id = $this->factory->post->create(); |
| | 61 | $permalink = get_permalink( $post_id ); |
| | 62 | |
| | 63 | $this->factory->comment->create_post_comments( $post_id, $number ); |
| | 64 | $this->go_to( $permalink ); |
| | 65 | |
| | 66 | add_filter( 'gettext_with_context', array( $this, '_enable_comment_number_declension' ), 10, 4 ); |
| | 67 | |
| | 68 | $this->assertEquals( $output, get_comments_number_text( false, false, $input ) ); |
| | 69 | |
| | 70 | remove_filter( 'gettext_with_context', array( $this, '_enable_comment_number_declension' ), 10, 4 ); |
| | 71 | } |
| | 72 | |
| | 73 | function _enable_comment_number_declension( $translation, $text, $context, $domain ) { |
| | 74 | if ( 'Comment number declension: on or off' === $context ) { |
| | 75 | $translation = 'on'; |
| | 76 | } |
| | 77 | |
| | 78 | return $translation; |
| | 79 | } |
| | 80 | |
| | 81 | function data_get_comments_number_text_declension() { |
| | 82 | return array( |
| | 83 | array( |
| | 84 | 2, |
| | 85 | 'Comments (%)', |
| | 86 | sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), |
| | 87 | ), |
| | 88 | array( |
| | 89 | 2, |
| | 90 | '2 Comments', |
| | 91 | '2 Comments', |
| | 92 | ), |
| | 93 | array( |
| | 94 | 2, |
| | 95 | '2 Comments<span class="screen-reader-text"> on Hello world!</span>', |
| | 96 | '2 Comments<span class="screen-reader-text"> on Hello world!</span>', |
| | 97 | ), |
| | 98 | array( |
| | 99 | 2, |
| | 100 | __( '% Comments', 'twentyten' ), |
| | 101 | sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), |
| | 102 | ), |
| | 103 | array( |
| | 104 | 2, |
| | 105 | _x( '%', 'comments number', 'twentyeleven' ), |
| | 106 | '2', |
| | 107 | ), |
| | 108 | array( |
| | 109 | 2, |
| | 110 | __( '<b>%</b> Replies', 'twentyeleven' ), |
| | 111 | sprintf( _n( '%s Comment', '%s Comments', 2 ), '<b>2</b>' ), |
| | 112 | ), |
| | 113 | array( |
| | 114 | 2, |
| | 115 | __( '% <span class="reply">comments →</span>', 'twentyeleven' ), |
| | 116 | sprintf( '2 <span class="reply">%s →</span>', trim( sprintf( _n( '%s Comment', '%s Comments', 2 ), '' ) ) ), |
| | 117 | ), |
| | 118 | array( |
| | 119 | 2, |
| | 120 | __( '% Replies', 'twentytwelve' ), |
| | 121 | sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), |
| | 122 | ), |
| | 123 | array( |
| | 124 | 2, |
| | 125 | __( 'View all % comments', 'twentythirteen' ), |
| | 126 | sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), |
| | 127 | ), |
| | 128 | array( |
| | 129 | 2, |
| | 130 | __( '% Comments', 'twentyfourteen' ), |
| | 131 | sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), |
| | 132 | ), |
| | 133 | array( |
| | 134 | 2, |
| | 135 | __( '% Comments', 'twentyfifteen' ), |
| | 136 | sprintf( _n( '%s Comment', '%s Comments', 2 ), '2' ), |
| | 137 | ), |
| | 138 | ); |
| | 139 | } |
| | 140 | |
| | 141 | } |