MDL-76221 core: method to filter by defined properties of persistent.

This commit is contained in:
Paul Holden
2022-12-29 14:02:58 +00:00
parent 12e9d9e1bf
commit 121f5b6300
3 changed files with 30 additions and 21 deletions
+17 -10
View File
@@ -14,14 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Persistent class tests.
*
* @package core
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core;
use advanced_testcase;
@@ -30,8 +22,6 @@ use dml_missing_record_exception;
use lang_string;
use xmldb_table;
defined('MOODLE_INTERNAL') || die();
/**
* Persistent testcase.
*
@@ -173,6 +163,23 @@ class persistent_test extends advanced_testcase {
$this->assertEquals($expected, core_testable_persistent::properties_definition());
}
/**
* Test filtering record properties returns only those defined by the persistent
*/
public function test_properties_filter(): void {
$result = core_testable_persistent::properties_filter((object) [
'idnumber' => '123',
'sortorder' => 1,
'invalidparam' => 'abc',
]);
// We should get back all data except invalid param.
$this->assertEquals([
'idnumber' => '123',
'sortorder' => 1,
], $result);
}
/**
* Test creating persistent instance by specifying record ID in constructor
*/