Skip to content

Commit 4a243ec

Browse files
committed
add tests
1 parent 1f7c32d commit 4a243ec

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

load.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function tsdk_translate_link(
209209
$parsed_url = wp_parse_url( $url );
210210
// we replace the domain here based on the localized one.
211211
if ( $type === 'domain' ) {
212-
return $parsed_url['scheme'] . '://' . $code . $parsed_url['path'] . ( isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '' ) . ( isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '' );
212+
return $parsed_url['scheme'] . '://' . $code . ( isset( $parsed_url['path'] ) ? $parsed_url['path'] : '' ) . ( isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '' ) . ( isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '' );
213213
}
214214
// default is the path based approach.
215215
$new_path = isset( $parsed_url['path'] ) ? "/$code" . $parsed_url['path'] : "/$code";

tests/translate-link-test.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,49 @@
1111
class Translate_Link extends WP_UnitTestCase {
1212

1313
public function test_default_path() {
14-
add_filter( 'locale', function () {
15-
return 'de_DE';
16-
} );
14+
add_filter(
15+
'locale',
16+
function () {
17+
return 'de_DE';
18+
}
19+
);
1720
$url = 'https://example.com';
1821
$this->assertEquals( $url . '/de', tsdk_translate_link( $url ) );
1922
$url = 'https://example.com/some/path';
20-
$this->assertEquals( $url . '/de', tsdk_translate_link( $url ) );
23+
$this->assertEquals( 'https://example.com/de/some/path', tsdk_translate_link( $url ) );
2124
$url = 'https://example.com/some/path/';
22-
$this->assertEquals( $url . 'de/', tsdk_translate_link( $url ) );
25+
$this->assertEquals( 'https://example.com/de/some/path/', tsdk_translate_link( $url ) );
2326
}
2427

2528
public function test_query() {
26-
add_filter( 'locale', function () {
27-
return 'de_DE';
28-
} );
29+
add_filter(
30+
'locale',
31+
function () {
32+
return 'de_DE';
33+
}
34+
);
2935
$url = 'https://example.com';
30-
$this->assertEquals( 'https://example.com/?lang=de', tsdk_translate_link( $url, 'query' ) );
36+
$this->assertEquals( 'https://example.com?lang=de', tsdk_translate_link( $url, 'query' ) );
3137
}
3238

3339
public function test_domain() {
34-
add_filter( 'locale', function () {
35-
return 'de_DE';
36-
} );
40+
add_filter(
41+
'locale',
42+
function () {
43+
return 'de_DE';
44+
}
45+
);
3746
$url = 'https://example.com';
3847
$this->assertEquals( 'https://optimole.de', tsdk_translate_link( $url, 'domain', [ 'de_DE' => 'optimole.de' ] ) );
3948
}
4049

4150
public function test_non_existent() {
42-
add_filter( 'locale', function () {
43-
return 'da_DK';
44-
} );
51+
add_filter(
52+
'locale',
53+
function () {
54+
return 'da_DK';
55+
}
56+
);
4557
$url = 'https://example.com';
4658
$this->assertEquals( 'https://example.com', tsdk_translate_link( $url ) );
4759
}

0 commit comments

Comments
 (0)