Skip to content

Commit

Permalink
Fixed a bug for previous merchants without custom name field in the s…
Browse files Browse the repository at this point in the history
…ecure form settings. (#419)

Co-authored-by: Aashish <aashish@omise.co>
  • Loading branch information
aashishgurung and Aashish committed Nov 16, 2023
1 parent 74c1791 commit f7737ea
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
8 changes: 8 additions & 0 deletions includes/admin/class-omise-page-card-form-customization.php
Expand Up @@ -88,6 +88,14 @@ public function get_design_setting()
if (empty($formDesign)) {
$formDesign = $this->get_default_design_setting();
}

// Old saved settings might not have the newer fields. Make sure
// we add the missing field
// TODO: Find a better way to handle this
if (!in_array('custom_name', $formDesign['font'])) {
$formDesign['font']['custom_name'] = '';
}

return $formDesign;
}

Expand Down
Expand Up @@ -9,17 +9,14 @@ class Omise_Page_Card_From_Customization_Test extends TestCase
{
public function setUp(): void
{
// mocking WP built-in functions
if (!function_exists('get_option')) {
function get_option() {}
}

Brain\Monkey\setUp();
Mockery::mock('alias:Omise_Admin_Page');
require_once __DIR__ . '/../../../../includes/admin/class-omise-page-card-form-customization.php';
}

public function tearDown(): void
{
Brain\Monkey\tearDown();
Mockery::close();
}

Expand Down Expand Up @@ -93,6 +90,48 @@ public function testGetDarkTheme()
$this->assertEqualsCanonicalizing($expected, $themeValues);
}

/**
* Test for merchants using secure form prior to v5.6.0
* Make sure it includes custom_name
* @test
*/
public function testGetDesignSettingIncludesCustomName()
{
// settings of merchant's secure form prior to v5.6.0
$savedSettings = [
'font' => [
'name' => 'Poppins',
'size' => 16,
],
'input' => [
'height' => '44px',
'border_radius' => '4px',
'border_color' => '#475266',
'active_border_color' => '#475266',
'background_color' => '#131926',
'label_color' => '#E6EAF2',
'text_color' => '#ffffff',
'placeholder_color' => '#DBDBDB',
],
'checkbox' => [
'text_color' => '#E6EAF2',
'theme_color' => '#1451CC',
]
];

Brain\Monkey\Functions\stubs( [
'get_option' => $savedSettings,
] );

$obj = Omise_Page_Card_From_Customization::get_instance();
$designValues = $obj->get_design_setting();

$expected = $savedSettings;
$expected['font']['custom_name'] = '';
$this->assertEqualsCanonicalizing($expected, $designValues);
$this->assertArrayHasKey('custom_name', $designValues['font']);
}

/**
* Call protected/private method of a class.
*
Expand Down

0 comments on commit f7737ea

Please sign in to comment.