Skip to content

Commit d8a71e5

Browse files
committed
Move Tests_Custom_Ability_Class to a seperate file
1 parent af85b49 commit d8a71e5

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Test custom ability class that extends WP_Ability.
4+
*
5+
* This class overrides do_execute() and check_permissions() directly,
6+
* allowing registration without execute_callback or permission_callback.
7+
*/
8+
class Tests_Custom_Ability_Class extends WP_Ability {
9+
10+
/**
11+
* Custom execute implementation that multiplies instead of adds.
12+
*
13+
* @param mixed $input The input data.
14+
* @return int The result of multiplying a and b.
15+
*/
16+
protected function do_execute( $input = null ) {
17+
return $input['a'] * $input['b'];
18+
}
19+
20+
/**
21+
* Custom permission check that always returns true.
22+
*
23+
* @param mixed $input The input data.
24+
* @return bool Always true.
25+
*/
26+
public function check_permissions( $input = null ) {
27+
return true;
28+
}
29+
}

tests/phpunit/tests/abilities-api/wpAbilitiesRegistry.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class Tests_Abilities_API_WpAbilitiesRegistry extends WP_UnitTestCase {
2323
* Set up each test method.
2424
*/
2525
public function set_up(): void {
26+
require_once DIR_TESTDATA . '/../includes/class-tests-custom-ability-class.php';
27+
2628
parent::set_up();
2729

2830
$this->registry = new WP_Abilities_Registry();
@@ -680,32 +682,3 @@ static function ( $args, $name ) {
680682
$this->assertNotSame( $filtered_ability->get_label(), $unfiltered_ability->get_label(), 'The filter incorrectly modified the args for an ability it should not have.' );
681683
}
682684
}
683-
684-
/**
685-
* Test custom ability class that extends WP_Ability.
686-
*
687-
* This class overrides do_execute() and check_permissions() directly,
688-
* allowing registration without execute_callback or permission_callback.
689-
*/
690-
class Tests_Custom_Ability_Class extends WP_Ability {
691-
692-
/**
693-
* Custom execute implementation that multiplies instead of adds.
694-
*
695-
* @param mixed $input The input data.
696-
* @return int The result of multiplying a and b.
697-
*/
698-
protected function do_execute( $input = null ) {
699-
return $input['a'] * $input['b'];
700-
}
701-
702-
/**
703-
* Custom permission check that always returns true.
704-
*
705-
* @param mixed $input The input data.
706-
* @return bool Always true.
707-
*/
708-
public function check_permissions( $input = null ) {
709-
return true;
710-
}
711-
}

0 commit comments

Comments
 (0)