Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?php
/**
Comment on lines +1 to +2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add the required ABSPATH guard at file start.

The file currently lacks the mandatory guard line.

Suggested fix
 <?php
+defined('ABSPATH') || exit;
 /**
  * Tests for Signup_Field_Billing_Address class.
As per coding guidelines `Every PHP file must start with defined('ABSPATH') || exit;`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Billing_Address_Test.php`
around lines 1 - 2, Add the required ABSPATH guard at the top of the file: after
the opening <?php tag in Signup_Field_Billing_Address_Test (class
Signup_Field_Billing_Address_Test), insert the line defined('ABSPATH') || exit;
so the file exits immediately when run outside WordPress context; ensure the
guard is the first executable statement before any comments, declarations, or
class/test definitions.

* Tests for Signup_Field_Billing_Address class.
*
* @package WP_Ultimo\Tests
*/

namespace WP_Ultimo\Checkout\Signup_Fields;

use WP_UnitTestCase;

/**
* Test class for Signup_Field_Billing_Address.
*/
class Signup_Field_Billing_Address_Test extends WP_UnitTestCase {

/**
* @var Signup_Field_Billing_Address
*/
private $field;

/**
* Set up test fixtures.
*/
protected function setUp(): void {
parent::setUp();
$this->field = new Signup_Field_Billing_Address();
}

/**
* Test get_type returns billing_address.
*/
public function test_get_type(): void {
$this->assertEquals( 'billing_address', $this->field->get_type() );
}

/**
* Test is_required returns false.
*/
public function test_is_required(): void {
$this->assertFalse( $this->field->is_required() );
}

/**
* Test is_user_field returns true.
*/
public function test_is_user_field(): void {
$this->assertTrue( $this->field->is_user_field() );
}

/**
* Test is_site_field returns false.
*/
public function test_is_site_field(): void {
$this->assertFalse( $this->field->is_site_field() );
}

/**
* Test get_title returns non-empty string.
*/
public function test_get_title(): void {
$title = $this->field->get_title();
$this->assertIsString( $title );
$this->assertNotEmpty( $title );
}

/**
* Test get_description returns non-empty string.
*/
public function test_get_description(): void {
$description = $this->field->get_description();
$this->assertIsString( $description );
$this->assertNotEmpty( $description );
}

/**
* Test get_tooltip returns non-empty string.
*/
public function test_get_tooltip(): void {
$tooltip = $this->field->get_tooltip();
$this->assertIsString( $tooltip );
$this->assertNotEmpty( $tooltip );
}

/**
* Test get_icon returns dashicon class.
*/
public function test_get_icon(): void {
$icon = $this->field->get_icon();
$this->assertIsString( $icon );
$this->assertStringContainsString( 'dashicons', $icon );
}

/**
* Test defaults returns array with zip_and_country key.
*/
public function test_defaults(): void {
$defaults = $this->field->defaults();
$this->assertIsArray( $defaults );
$this->assertArrayHasKey( 'zip_and_country', $defaults );
$this->assertTrue( $defaults['zip_and_country'] );
}

/**
* Test default_fields returns array containing name.
*/
public function test_default_fields(): void {
$fields = $this->field->default_fields();
$this->assertIsArray( $fields );
$this->assertContains( 'name', $fields );
}

/**
* Test force_attributes returns id and required.
*/
public function test_force_attributes(): void {
$attrs = $this->field->force_attributes();
$this->assertIsArray( $attrs );
$this->assertArrayHasKey( 'id', $attrs );
$this->assertEquals( 'billing_address', $attrs['id'] );
$this->assertArrayHasKey( 'required', $attrs );
$this->assertTrue( $attrs['required'] );
}

/**
* Test get_fields returns array with zip_and_country key.
*/
public function test_get_fields(): void {
$fields = $this->field->get_fields();
$this->assertIsArray( $fields );
$this->assertArrayHasKey( 'zip_and_country', $fields );
}

/**
* Test get_fields zip_and_country is a toggle type.
*/
public function test_get_fields_zip_and_country_is_toggle(): void {
$fields = $this->field->get_fields();
$this->assertEquals( 'toggle', $fields['zip_and_country']['type'] );
}

/**
* Test build_select_alternative returns array with expected keys.
*/
public function test_build_select_alternative(): void {
$base_field = array(
'type' => 'text',
'title' => 'State',
'wrapper_html_attr' => array(),
'html_attr' => array(),
);

$result = $this->field->build_select_alternative( $base_field, 'state_list', 'state_field' );

$this->assertIsArray( $result );
$this->assertEquals( 'select', $result['type'] );
$this->assertArrayHasKey( 'options_template', $result );
$this->assertArrayHasKey( 'options', $result );
$this->assertTrue( $result['required'] );
}

/**
* Test build_select_alternative sets v-if on base_field.
*/
public function test_build_select_alternative_sets_v_if_on_base_field(): void {
$base_field = array(
'type' => 'text',
'title' => 'State',
'wrapper_html_attr' => array(),
'html_attr' => array(),
);

$this->field->build_select_alternative( $base_field, 'state_list', 'state_field' );

$this->assertArrayHasKey( 'v-if', $base_field['wrapper_html_attr'] );
$this->assertStringContainsString( 'state_list', $base_field['wrapper_html_attr']['v-if'] );
}

/**
* Test field is instance of Base_Signup_Field.
*/
public function test_field_is_instance_of_base(): void {
$this->assertInstanceOf( Base_Signup_Field::class, $this->field );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php
/**
Comment on lines +1 to +2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add the required ABSPATH guard at file start.

Please add the mandatory guard for direct file access.

Suggested fix
 <?php
+defined('ABSPATH') || exit;
 /**
  * Tests for Signup_Field_Order_Bump class.
As per coding guidelines `Every PHP file must start with defined('ABSPATH') || exit;`.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<?php
/**
<?php
defined('ABSPATH') || exit;
/**
* Tests for Signup_Field_Order_Bump class.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/WP_Ultimo/Checkout/Signup_Fields/Signup_Field_Order_Bump_Test.php`
around lines 1 - 2, This test file is missing the mandatory WordPress
direct-access guard; open the Signup_Field_Order_Bump_Test.php test file and add
the ABSPATH guard as the very first executable statement so the file aborts when
accessed directly (i.e., check for ABSPATH being defined and exit if not).
Ensure the guard is placed before any PHPDoc, class declarations or code,
leaving the existing class/test names unchanged (e.g.,
Signup_Field_Order_Bump_Test).

* Tests for Signup_Field_Order_Bump class.
*
* @package WP_Ultimo\Tests
*/

namespace WP_Ultimo\Checkout\Signup_Fields;

use WP_UnitTestCase;

/**
* Test class for Signup_Field_Order_Bump.
*/
class Signup_Field_Order_Bump_Test extends WP_UnitTestCase {

/**
* @var Signup_Field_Order_Bump
*/
private $field;

/**
* Set up test fixtures.
*/
protected function setUp(): void {
parent::setUp();
$this->field = new Signup_Field_Order_Bump();
}

/**
* Test get_type returns order_bump.
*/
public function test_get_type(): void {
$this->assertEquals( 'order_bump', $this->field->get_type() );
}

/**
* Test is_required returns false.
*/
public function test_is_required(): void {
$this->assertFalse( $this->field->is_required() );
}

/**
* Test get_title returns non-empty string.
*/
public function test_get_title(): void {
$title = $this->field->get_title();
$this->assertIsString( $title );
$this->assertNotEmpty( $title );
}

/**
* Test get_description returns non-empty string.
*/
public function test_get_description(): void {
$description = $this->field->get_description();
$this->assertIsString( $description );
$this->assertNotEmpty( $description );
}

/**
* Test get_tooltip returns non-empty string.
*/
public function test_get_tooltip(): void {
$tooltip = $this->field->get_tooltip();
$this->assertIsString( $tooltip );
$this->assertNotEmpty( $tooltip );
}

/**
* Test get_icon returns dashicon class.
*/
public function test_get_icon(): void {
$icon = $this->field->get_icon();
$this->assertIsString( $icon );
$this->assertStringContainsString( 'dashicons', $icon );
}

/**
* Test is_user_field returns false by default.
*/
public function test_is_user_field(): void {
$this->assertFalse( $this->field->is_user_field() );
}

/**
* Test is_site_field returns false by default.
*/
public function test_is_site_field(): void {
$this->assertFalse( $this->field->is_site_field() );
}

/**
* Test defaults returns expected keys.
*/
public function test_defaults(): void {
$defaults = $this->field->defaults();
$this->assertIsArray( $defaults );
$this->assertArrayHasKey( 'order_bump_template', $defaults );
$this->assertEquals( 'simple', $defaults['order_bump_template'] );
$this->assertArrayHasKey( 'display_product_description', $defaults );
$this->assertEquals( 0, $defaults['display_product_description'] );
}

/**
* Test default_fields returns array containing name.
*/
public function test_default_fields(): void {
$fields = $this->field->default_fields();
$this->assertIsArray( $fields );
$this->assertContains( 'name', $fields );
}

/**
* Test force_attributes returns order_bump_template.
*/
public function test_force_attributes(): void {
$attrs = $this->field->force_attributes();
$this->assertIsArray( $attrs );
$this->assertArrayHasKey( 'order_bump_template', $attrs );
$this->assertEquals( 'simple', $attrs['order_bump_template'] );
}

/**
* Test get_fields returns array with expected keys.
*/
public function test_get_fields(): void {
$fields = $this->field->get_fields();
$this->assertIsArray( $fields );
$this->assertArrayHasKey( 'product', $fields );
$this->assertArrayHasKey( 'display_product_description', $fields );
$this->assertArrayHasKey( 'display_product_image', $fields );
}

/**
* Test get_fields product field is model type.
*/
public function test_get_fields_product_is_model_type(): void {
$fields = $this->field->get_fields();
$this->assertEquals( 'model', $fields['product']['type'] );
}

/**
* Test get_fields display_product_description is toggle type.
*/
public function test_get_fields_display_product_description_is_toggle(): void {
$fields = $this->field->get_fields();
$this->assertEquals( 'toggle', $fields['display_product_description']['type'] );
}

/**
* Test get_fields display_product_image is toggle type.
*/
public function test_get_fields_display_product_image_is_toggle(): void {
$fields = $this->field->get_fields();
$this->assertEquals( 'toggle', $fields['display_product_image']['type'] );
}

/**
* Test to_fields_array returns empty array when product not found.
*/
public function test_to_fields_array_returns_empty_when_no_product(): void {
$attributes = array(
'product' => 999999,
'order_bump_template' => 'simple',
'id' => 'order_bump',
'element_classes' => '',
);

$result = $this->field->to_fields_array( $attributes );
$this->assertIsArray( $result );
$this->assertEmpty( $result );
}

/**
* Test field is instance of Base_Signup_Field.
*/
public function test_field_is_instance_of_base(): void {
$this->assertInstanceOf( Base_Signup_Field::class, $this->field );
}
}
Loading
Loading