Skip to content

Commit

Permalink
Unit test
Browse files Browse the repository at this point in the history
@Shelob9 was there a precise reason why set_locale_code() and get_validator_url() were protected functions ? I'm not sure if I can test a protected function.
  • Loading branch information
New0 committed Jul 25, 2019
1 parent 975713d commit 1e523e9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions classes/render/assets.php
Expand Up @@ -1049,7 +1049,7 @@ protected static function field_script_dependencies()
*
* @return string
*/
protected static function get_validator_locale_url($locale)
public static function get_validator_locale_url($locale)
{
//Use correct formatted locale for file to be matched
$locale = self::set_locale_code($locale);
Expand All @@ -1068,7 +1068,7 @@ protected static function get_validator_locale_url($locale)
*
* @return string
*/
protected static function set_locale_code($locale)
public static function set_locale_code($locale)
{
if (file_exists(CFCORE_PATH . 'assets/js/i18n/' . $locale . '.js')) {
// no need to check other possibilities- break if/else early
Expand Down
50 changes: 50 additions & 0 deletions tests/test-locale-assets-enqueued.php
@@ -0,0 +1,50 @@
<?php
/**
* Test locale set to enqueue assets
*
* @package Caldera_Forms
* @since 1.8.7
* @license GPL-2.0+
*/
class TestLocaleRenderAssets extends Caldera_Forms_Test_Case
{
/**
* Test a locale which corresponding file exists within assets/js/i18n/
*
* @since 1.8.7
*
* @covers \Caldera_Forms_Render_Assets::set_locale_code($locale)
* @covers \Caldera_Forms_Render_Assets::get_validator_locale_url($locale)
*/
public function testKnownLocale()
{

$locale = "fr";
$code = Caldera_Forms_Render_Assets::set_locale_code($locale);
$validator_url = Caldera_Forms_Render_Assets::get_validator_locale_url($locale);

$this->assertSame( $code, "fr" );
$this->assertSame( $validator_url, "http://example.org/wp-content/plugins/app/assets/js/i18n/en.js" );

}

/**
* Test a locale which corresponding file doesn't exist within assets/js/i18n/
*
* @since 1.8.7
*
* @covers \Caldera_Forms_Render_Assets::set_locale_code($locale)
* @covers \Caldera_Forms_Render_Assets::get_validator_locale_url($locale)
*/
public function testUnkKnownLocale()
{

$locale = "bo";
$code = Caldera_Forms_Render_Assets::set_locale_code($locale);
$validator_url = Caldera_Forms_Render_Assets::get_validator_locale_url($locale);

$this->assertSame( $code, "en" );
$this->assertSame( $validator_url, "http://example.org/wp-content/plugins/app/assets/js/i18n/en.js" );
}

}

1 comment on commit 1e523e9

@Shelob9
Copy link
Collaborator

@Shelob9 Shelob9 commented on 1e523e9 Jul 25, 2019 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.