Skip to content
Open
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
6 changes: 4 additions & 2 deletions inc/limitations/class-limit-site-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ public function get_available_site_templates() {
if (self::BEHAVIOR_AVAILABLE === $site_settings->behavior ||
self::BEHAVIOR_PRE_SELECTED === $site_settings->behavior ||
self::MODE_DEFAULT === $this->mode) {
$available[] = $site_id;
// Convert to integer to match type used in validation (absint)
$available[] = absint($site_id);
}
}

Expand All @@ -248,7 +249,8 @@ public function get_pre_selected_site_template() {
$site_settings = (object) $site_settings;

if (self::BEHAVIOR_PRE_SELECTED === $site_settings->behavior) {
$pre_selected_site_template = $site_id;
// Convert to integer to match type used in validation (absint)
$pre_selected_site_template = absint($site_id);
}
}

Expand Down
38 changes: 38 additions & 0 deletions tests/WP_Ultimo/Objects/Limitations_Test.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

Check failure on line 1 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Missing file doc comment

namespace WP_Ultimo\Objects;

use WP_UnitTestCase;
use WP_Ultimo\Objects\Limitations;

class Limitations_Test extends WP_UnitTestCase {

Check failure on line 8 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Missing doc comment for class Limitations_Test

/**
* Clear limitations cache before each test.
Expand Down Expand Up @@ -71,7 +71,7 @@
];
}

/**

Check failure on line 74 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Doc comment for parameter "$expected_modules_count" missing

Check failure on line 74 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Doc comment for parameter "$modules_data" missing
* Test constructor with various module data.
*
* @dataProvider constructorDataProvider
Expand Down Expand Up @@ -121,7 +121,7 @@
];
}

/**

Check failure on line 124 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Doc comment for parameter "$should_exist" missing

Check failure on line 124 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Doc comment for parameter "$module_name" missing
* Test magic getter method.
*
* @dataProvider magicGetterDataProvider
Expand Down Expand Up @@ -196,7 +196,7 @@
];
}

/**

Check failure on line 199 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Doc comment for parameter "$expected_count" missing

Check failure on line 199 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Doc comment for parameter "$modules_data" missing
* Test build_modules method.
*
* @dataProvider buildModulesDataProvider
Expand Down Expand Up @@ -257,7 +257,7 @@
];
}

/**

Check failure on line 260 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Doc comment for parameter "$module_name" missing

Check failure on line 260 in tests/WP_Ultimo/Objects/Limitations_Test.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Doc comment for parameter "$data" missing
* Test static build method.
*
* @dataProvider buildMethodDataProvider
Expand Down Expand Up @@ -910,4 +910,42 @@
// Disk space should be additive
$this->assertEquals(600, $limits->disk_space->get_limit(), 'Disk space should be summed');
}

/**
* Test that get_available_site_templates returns integers, not strings.
*
* Regression test for issue #351: When template IDs are stored as string keys
* in the limit array, they must be converted to integers for proper comparison
* in the Site_Template validation rule.
*/
public function test_available_site_templates_returns_integers(): void {

$limitations = new Limitations([
'site_templates' => [
'enabled' => true,
'mode' => 'choose_available_templates',
'limit' => [
'123' => ['behavior' => 'available'],
'456' => ['behavior' => 'pre_selected'],
'789' => ['behavior' => 'not_available'],
],
],
]);

$available = $limitations->site_templates->get_available_site_templates();

// Should return integers, not strings
$this->assertContains(123, $available, 'Template 123 should be in available array as integer');
$this->assertContains(456, $available, 'Template 456 should be in available array as integer');
$this->assertNotContains(789, $available, 'Template 789 should not be available');

// Verify strict type checking
foreach ($available as $template_id) {
$this->assertIsInt($template_id, 'All template IDs should be integers');
}

// Verify in_array works with strict comparison
$this->assertTrue(in_array(123, $available, true), 'in_array with strict=true should find integer 123');
$this->assertTrue(in_array(456, $available, true), 'in_array with strict=true should find integer 456');
}
}
Loading