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


PHP RuleDictionnaryDropdown::update方法代码示例

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


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

示例1: testManufacturer

 /**
  * Import of Manufacturer (with Rule)
  */
 public function testManufacturer()
 {
     // Old counters
     $nbr = countElementsInTable('glpi_rules');
     $nba = countElementsInTable('glpi_ruleactions');
     $nbc = countElementsInTable('glpi_rulecriterias');
     // Create some rules
     $rule = new RuleDictionnaryDropdown('RuleDictionnaryManufacturer');
     $crit = new RuleCriteria();
     $acte = new RuleAction();
     $idr[0] = $rule->add(array('name' => 'test1', 'sub_type' => 'RuleDictionnaryManufacturer', 'match' => 'AND', 'is_active' => 1));
     $this->assertGreaterThan(0, $idr[0], "Fail: can't create rule 1");
     $this->assertTrue($rule->getFromDB($idr[0]));
     $this->assertEquals(1, $rule->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 rule 1 criteria");
     $ida[0] = $acte->add(array('rules_id' => $idr[0], 'action_type' => 'assign', 'field' => 'name', 'value' => $out1 = 'Indepnet'));
     $this->assertGreaterThan(0, $ida[0], "Fail: can't create rule 1 action");
     // Add another rule
     $idr[1] = $rule->add(array('name' => 'test2', 'sub_type' => 'RuleDictionnaryManufacturer', 'match' => 'AND', 'is_active' => 1));
     $this->assertGreaterThan(0, $idr[1], "Fail: can't create rule 2");
     $this->assertTrue($rule->getFromDB($idr[1]));
     $this->assertEquals(2, $rule->fields['ranking'], "Fail: ranking not set");
     $idc[1] = $crit->add(array('rules_id' => $idr[1], 'criteria' => 'name', 'condition' => Rule::PATTERN_BEGIN, 'pattern' => 'http:'));
     $this->assertGreaterThan(0, $idc[1], "Fail: can't create rule 2 criteria");
     $ida[1] = $acte->add(array('rules_id' => $idr[1], 'action_type' => 'assign', 'field' => 'name', 'value' => $out2 = 'Web Site'));
     $this->assertGreaterThan(0, $ida[1], "Fail: can't create rule 2 action");
     $manu = new Manufacturer();
     // Import first and fill cache
     $id[0] = $manu->importExternal($in = 'the indepnet team');
     $this->assertGreaterThan(0, $id[0]);
     $this->assertTrue($manu->getFromDB($id[0]));
     $this->assertEquals($out1, $manu->fields['name'], "Fail: Rule::PATTERN_CONTAIN not match");
     $this->assertEquals(1, countElementsInTable($cache), "Fail: cache empty");
     // Import second and use cache
     $id[1] = $manu->importExternal($in = 'The INDEPNET Team');
     $this->assertGreaterThan(0, $id[1]);
     $this->assertEquals($id[0], $id[1]);
     $this->assertTrue($manu->getFromDB($id[1]));
     $this->assertEquals($out1, $manu->fields['name'], "Fail: Rule::PATTERN_CONTAIN not match");
     $this->assertEquals(1, countElementsInTable($cache), "Fail: cache not filled");
     // Import third not in cache
     $id[2] = $manu->importExternal($in = 'http://www.indepnet.net/');
     $this->assertGreaterThan(0, $id[2]);
     $this->assertEquals($id[0], $id[2]);
     $this->assertTrue($manu->getFromDB($id[2]));
     $this->assertEquals($out1, $manu->fields['name'], "Fail: Rule::PATTERN_CONTAIN not match");
     $this->assertEquals(2, countElementsInTable($cache), "Fail: cache not filled");
     // Set is_active=0, and clean cache
     $this->assertTrue($rule->update(array('id' => $idr[0], 'is_active' => 0)), "Fail: update rule");
     $this->assertEquals(0, countElementsInTable($cache), "Fail: cache not empty");
     $this->assertTrue($rule->update(array('id' => $idr[0], 'is_active' => 1)), "Fail: update rule");
     // Import again and fill cache
     $id[3] = $manu->importExternal($in = 'http://www.glpi-project.org/');
     $this->assertGreaterThan(0, $id[3]);
     $this->assertGreaterThan($id[0], $id[3]);
     $this->assertTrue($manu->getFromDB($id[3]));
     $this->assertEquals($out2, $manu->fields['name'], "Fail: Rule::PATTERN_BEGIN not match");
     $this->assertEquals(1, countElementsInTable($cache), "Fail: cache empty");
     $id[4] = $manu->importExternal($in = 'http://www.indepnet.net/');
     $this->assertGreaterThan(0, $id[4]);
     $this->assertEquals($id[0], $id[4]);
     $this->assertTrue($manu->getFromDB($id[4]));
     $this->assertEquals($out1, $manu->fields['name'], "Fail: Rule::PATTERN_CONTAIN not match");
     $this->assertEquals(2, countElementsInTable($cache), "Fail: cache not filled");
     // Hack : to disable preload done by Singleton
     $tmp = SingletonRuleList::getInstance('RuleDictionnaryManufacturer');
     $tmp->load = 0;
     // Change rules order
     $collection = new RuleDictionnaryDropdownCollection('RuleDictionnaryManufacturer');
     // Move rule 1 after rule 2
     $this->assertTrue($collection->moveRule($idr[0], $idr[1]), "Fail: can't move rules");
     $this->assertEquals(0, countElementsInTable($cache), "Fail: cache not empty");
     $this->assertTrue($rule->getFromDB($idr[1]));
     $this->assertEquals(1, $rule->fields['ranking'], "Fail: ranking not change");
     $this->assertTrue($rule->getFromDB($idr[0]));
     $this->assertEquals(2, $rule->fields['ranking'], "Fail: ranking not change");
     // Import again and fill cache
     $id[5] = $manu->importExternal($in = 'http://www.glpi-project.org/');
     $this->assertGreaterThan(0, $id[5]);
     $this->assertTrue($manu->getFromDB($id[5]));
     $this->assertEquals($out2, $manu->fields['name'], "Fail: Rule::PATTERN_BEGIN not match");
     $id[6] = $manu->importExternal($in = 'http://www.indepnet.net/');
     $this->assertGreaterThan(0, $id[6]);
     $this->assertTrue($manu->getFromDB($id[6]));
     $this->assertEquals($out2, $manu->fields['name'], "Fail: Rule::PATTERN_BEGIN not match");
     $this->assertEquals($id[5], $id[6]);
     // Change rules orders again
     $tmp = SingletonRuleList::getInstance('RuleDictionnaryManufacturer');
     $tmp->load = 0;
     // Move rule 1 up (before rule 2)
     $this->assertTrue($collection->changeRuleOrder($idr[0], 'up'), "Fail: can't move rules");
     $this->assertEquals(0, countElementsInTable($cache), "Fail: cache not empty");
     $this->assertTrue($rule->getFromDB($idr[0]));
     $this->assertEquals(1, $rule->fields['ranking'], "Fail: ranking not change");
     $this->assertTrue($rule->getFromDB($idr[1]));
     $this->assertEquals(2, $rule->fields['ranking'], "Fail: ranking not change");
//.........这里部分代码省略.........
开发者ID:btry,项目名称:glpi,代码行数:101,代码来源:Import.php


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