示例#1
0
 public function test_filter_load_rule()
 {
     $rulec = new block_xp_rule_property(block_xp_rule_base::EQ, 'c', 'crud');
     $e = \block_xp\event\something_happened::mock(array('crud' => 'c'));
     $filter = block_xp_filter::load_from_data(array('rule' => $rulec));
     $this->assertTrue($filter->match($e));
     $filter = block_xp_filter::load_from_data(array('ruledata' => json_encode($rulec->export())));
     $this->assertTrue($filter->match($e));
     $filter = block_xp_filter::load_from_data(array());
     $filter->set_rule($rulec);
     $this->assertTrue($filter->match($e));
 }
 public function test_export_create()
 {
     $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str');
     $newrule = block_xp_rule::create($rule->export());
     $this->assertEquals($rule, $newrule);
     $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str');
     $rs = new block_xp_ruleset(array($rule), block_xp_ruleset::ALL);
     $newrs = block_xp_rule::create($rs->export());
     $this->assertEquals($rs, $newrs);
     // Test with bad data.
     $data = $rs->export();
     $data['_class'] = 'Does not exist';
     $this->assertFalse(block_xp_rule::create($data));
 }
示例#3
0
 public function test_export_create()
 {
     $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str');
     $newrule = block_xp_rule::create($rule->export());
     $this->assertEquals($rule, $newrule);
     $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str');
     $rs = new block_xp_ruleset(array($rule), block_xp_ruleset::ALL);
     $newrs = block_xp_rule::create($rs->export());
     $this->assertEquals($rs, $newrs);
 }