Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Apr 10, 2024
1 parent ce59595 commit 1f7c32d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/translate-link-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Translation helper tests.
*
* @package ThemeIsleSDK
*/

/**
* Test translation link functionality.
*/
class Translate_Link extends WP_UnitTestCase {

public function test_default_path() {
add_filter( 'locale', function () {
return 'de_DE';
} );
$url = 'https://example.com';
$this->assertEquals( $url . '/de', tsdk_translate_link( $url ) );
$url = 'https://example.com/some/path';
$this->assertEquals( $url . '/de', tsdk_translate_link( $url ) );
$url = 'https://example.com/some/path/';
$this->assertEquals( $url . 'de/', tsdk_translate_link( $url ) );
}

public function test_query() {
add_filter( 'locale', function () {
return 'de_DE';
} );
$url = 'https://example.com';
$this->assertEquals( 'https://example.com/?lang=de', tsdk_translate_link( $url, 'query' ) );
}

public function test_domain() {
add_filter( 'locale', function () {
return 'de_DE';
} );
$url = 'https://example.com';
$this->assertEquals( 'https://optimole.de', tsdk_translate_link( $url, 'domain', [ 'de_DE' => 'optimole.de' ] ) );
}

public function test_non_existent() {
add_filter( 'locale', function () {
return 'da_DK';
} );
$url = 'https://example.com';
$this->assertEquals( 'https://example.com', tsdk_translate_link( $url ) );
}

}

0 comments on commit 1f7c32d

Please sign in to comment.