Welcome to mirror list, hosted at ThFree Co, Russian Federation.

translations.php « l10n « tests « tests - github.com/YOURLS/YOURLS.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 417fb1b3eea04fd2275b399c075b5fd4596f6ecb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php

/**
 * Localization functions : helper functions
 *
 * @group l10n
 * @since 0.1
 */
class Translation_Translation_Tests extends PHPUnit\Framework\TestCase {

    public static function setUpBeforeClass(): void {
        yourls_load_textdomain( 'test', YOURLS_TESTDATA_DIR . '/pomo/test-fr_FR.mo' );
        yourls_load_textdomain( 'default', YOURLS_TESTDATA_DIR . '/pomo/fr_FR.mo' );
    }

    public static function tearDownAfterClass(): void {
        yourls_unload_textdomain( 'test' );
        yourls_unload_textdomain( 'default' );
    }

    /**
     * Check a sample translation - returned
     *
     * @since 0.1
     */
    public function test_translation() {
        $this->assertSame( 'Court (default)' , yourls__( 'Short' ) );
        $this->assertSame( 'Court (test)' ,    yourls__( 'Short', 'test' ) );
    }

    /**
     * Check a sample translation - echoed
     *
     * @since 0.1
     */
    public function test_translation_echo() {
        $this->expectOutputString( 'Court (default)' );
        yourls_e( 'Short' );
    }

    /**
     * Check an unstranslated string
     *
     * @since 0.1
     */
    public function test_untranslated_string() {
        $this->assertSame( 'Untranslated string', yourls__( 'Untranslated string' ) );
        $this->assertSame( 'Untranslated string', yourls__( 'Untranslated string', 'test' ) );
    }

    /**
     * Check a random string
     *
     * @since 0.1
     */
    public function test_random_string() {
        $rand_string = rand_str();
        $this->assertSame( $rand_string, yourls__( $rand_string ) );
        $this->assertSame( $rand_string, yourls__( $rand_string, 'test' ) );
    }

    /**
     * Sprintf'ed translation
     *
     * @since 0.1
     */
    public function test_yourls_s() {
        $this->assertSame( 'Chaine avec omg (default)', yourls_s( 'String with %s', 'omg' ) );
        $this->assertSame( 'Chaine avec omg (test)',    yourls_s( 'String with %s', 'omg', 'test' ) );
    }

    /**
     * Sprintf'ed translation, echoed
     *
     * @since 0.1
     */
    public function test_yourls_se() {
        $this->expectOutputString( 'Chaine avec omg (test)' );
        yourls_se( 'String with %s', 'omg', 'test' );
    }

    /**
     * Sprintf'ed with too few arguments - trigger sprintf "too few arguments" error
     *
     * @since 0.1
     */
    public function test_yourls_s_too_few() {
        if (PHP_VERSION_ID >= 80000) {
            $this->expectException(ArgumentCountError::class);
        } else {
            $this->expectException(PHPUnit\Framework\Error\Error::class);
        }
        $this->expectExceptionMessageMatches('/arguments/');

        yourls_s( 'Hello %s you are %s', 'Ozh' );
    }

    /**
     * Sprintf'ed with arbitrary number of arguments
     *
     * @since 0.1
     */
    public function test_yourls_s_too_many() {
        // Expected number of arguments, + the domain
        $this->assertSame( 'Bonjour Ozh tu es nice (default)', yourls_s( 'Hello %s you are %s', 'Ozh', 'nice' ) );
        $this->assertSame( 'Bonjour Ozh tu es nice (test)',    yourls_s( 'Hello %s you are %s', 'Ozh', 'nice', 'test' ) );

        // Extra arguments with the last one not being a valid domain: string should be translated
        $this->assertSame( 'Hello Ozh you are nice', yourls_s( 'Hello %s you are %s', 'Ozh', 'nice', 'omg' ) );

        // Extra arguments with the last one being a valid domain: string should be translated
        $this->assertSame( 'Bonjour Ozh tu es nice (test)', yourls_s( 'Hello %s you are %s', 'Ozh', 'nice', 'omg', 'test' ) );
    }

    /**
     * Translation with context
     *
     * @since 0.1
     */
    public function test_yourls_x() {
        $this->assertSame( 'Chaine simple (default)', yourls_x( 'Simple string', 'data' ) );
        $this->assertSame( 'Chaine simple (test)', yourls_x( 'Simple string', 'data', 'test' ) );
    }

    /**
     * Translation with context, echoed
     *
     * @since 0.1
     */
    public function test_yourls_xe() {
        $this->expectOutputString( 'Chaine simple (test)' );
        yourls_xe( 'Simple string', 'data', 'test' );
    }

    /**
     * Translation with invalid context - string returned untranslated
     *
     * @since 0.1
     */
    public function test_yourls_x_invalid() {
        $this->assertSame( 'Simple string', yourls_x( 'Simple string', rand_str() ) );
        $this->assertSame( 'Simple string', yourls_x( 'Simple string', rand_str(), 'test' ) );
    }

    /**
     * Translation with numbers
     *
     * @since 0.1
     */
    public function test_yourls_n() {
        $this->assertSame( '1 truc (default)',   yourls_n( '1 item', '%s items', 1 ) );
        $this->assertSame( '%s trucs (default)', yourls_n( '1 item', '%s items', 2 ) );

        $this->assertSame( '1 truc (test)',   yourls_n( '1 item', '%s items', 1, 'test' ) );
        $this->assertSame( '%s trucs (test)', yourls_n( '1 item', '%s items', 2, 'test' ) );
    }

    /**
     * Translation with numbers and context
     *
     * @since 0.1
     */
    public function test_yourls_nx() {
        $this->assertSame( '1 ressort (default)',   yourls_nx( '1 spring', '%s springs', 1, 'boing' ) );
        $this->assertSame( '%s ressorts (default)', yourls_nx( '1 spring', '%s springs', 2, 'boing' ) );
        $this->assertSame( '1 source (default)',   yourls_nx( '1 spring', '%s springs', 1, 'water' ) );
        $this->assertSame( '%s sources (default)', yourls_nx( '1 spring', '%s springs', 2, 'water' ) );

        $this->assertSame( '1 ressort (test)',   yourls_nx( '1 spring', '%s springs', 1, 'boing', 'test' ) );
        $this->assertSame( '%s ressorts (test)', yourls_nx( '1 spring', '%s springs', 2, 'boing', 'test' ) );
        $this->assertSame( '1 source (test)',   yourls_nx( '1 spring', '%s springs', 1, 'water', 'test' ) );
        $this->assertSame( '%s sources (test)', yourls_nx( '1 spring', '%s springs', 2, 'water', 'test' ) );
    }

}