当前位置: 首页>>代码示例>>PHP>>正文


PHP RuleDictionnaryDropdown::add方法代码示例

本文整理汇总了PHP中RuleDictionnaryDropdown::add方法的典型用法代码示例。如果您正苦于以下问题:PHP RuleDictionnaryDropdown::add方法的具体用法?PHP RuleDictionnaryDropdown::add怎么用?PHP RuleDictionnaryDropdown::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RuleDictionnaryDropdown的用法示例。


在下文中一共展示了RuleDictionnaryDropdown::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSoftwareRule

 /**
  * Import of Software (with Rule)
  *
  * From OcsServer class
  */
 public function testSoftwareRule()
 {
     // Clean preload rules
     $tmp = SingletonRuleList::getInstance('RuleDictionnaryManufacturer');
     $tmp->load = 0;
     $tmp = SingletonRuleList::getInstance('RuleDictionnarySoftware');
     $tmp->load = 0;
     // Needed objetcs
     $rulem = new RuleDictionnaryDropdown('RuleDictionnaryManufacturer');
     $rules = new RuleDictionnaryDropdown('RuleDictionnarySoftware');
     $crit = new RuleCriteria();
     $acte = new RuleAction();
     // Rule for Manufacturer
     $idr[0] = $rulem->add(array('name' => 'test1', 'sub_type' => 'RuleDictionnaryManufacturer', 'match' => 'AND', 'is_active' => 1));
     $this->assertGreaterThan(0, $idr[0], "Fail: can't create manufacturer rule");
     $this->assertTrue($rulem->getFromDB($idr[0]));
     $this->assertEquals(1, $rulem->fields['ranking'], "Fail: ranking not set");
     $idc[0] = $crit->add(array('rules_id' => $idr[0], 'criteria' => 'name', 'condition' => Rule::PATTERN_CONTAIN, 'pattern' => 'indepnet'));
     $this->assertGreaterThan(0, $idc[0], "Fail: can't create manufacturer rule criteria");
     $ida[0] = $acte->add(array('rules_id' => $idr[0], 'action_type' => 'assign', 'field' => 'name', 'value' => $outm = 'Indepnet'));
     $this->assertGreaterThan(0, $ida[0], "Fail: can't create manufacturer rule action");
     // Rule for Software
     $idr[1] = $rules->add(array('name' => 'test2', 'sub_type' => 'RuleDictionnarySoftware', 'match' => 'AND', 'is_active' => 1));
     $this->assertGreaterThan(0, $idr[1], "Fail: can't create software rule");
     $this->assertTrue($rules->getFromDB($idr[1]));
     $this->assertEquals(1, $rules->fields['ranking'], "Fail: ranking not set");
     $idc[1] = $crit->add(array('rules_id' => $idr[1], 'criteria' => 'name', 'condition' => Rule::REGEX_MATCH, 'pattern' => '/^glpi (0\\.[0-9]+)/'));
     $this->assertGreaterThan(0, $idc[1], "Fail: can't create software rule criteria");
     $ida[1] = $acte->add(array('rules_id' => $idr[1], 'action_type' => 'assign', 'field' => 'name', 'value' => $outs = 'GLPI'));
     $this->assertGreaterThan(0, $ida[1], "Fail: can't create software rule action");
     $ida[2] = $acte->add(array('rules_id' => $idr[1], 'action_type' => 'regex_result', 'field' => 'version', 'value' => $outv = '#0'));
     $this->assertGreaterThan(0, $ida[2], "Fail: can't create software rule action");
     // Apply Rule to manufacturer
     $manu = Dropdown::import('Manufacturer', 'the indepnet team');
     $this->assertEquals('Indepnet', $manu, "Fail: manufacturer not altered");
     // Apply Rule to software
     $rulecollection = new RuleDictionnarySoftwareCollection();
     $res_rule = $rulecollection->processAllRules(array("name" => 'glpi 0.78', "manufacturer" => $manu, "old_version" => ''), array(), array());
     $this->assertArrayHasKey('name', $res_rule, "Fail: name not altered");
     $this->assertEquals('GLPI', $res_rule['name'], "Fail: name not correct");
     $this->assertArrayHasKey('version', $res_rule, "Fail: name not altered");
     $this->assertEquals('0.78', $res_rule['version'], "Fail: version not correct");
     // Clean
     $this->assertTrue($rulem->delete(array('id' => $idr[0])));
     $this->assertTrue($rules->delete(array('id' => $idr[1])));
 }
开发者ID:btry,项目名称:glpi,代码行数:51,代码来源:Import.php


注:本文中的RuleDictionnaryDropdown::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。