/**
  * Test for Form::loadRuleType method.
  *
  * @return void
  */
 public function testLoadRuleType()
 {
     // Test error handling.
     $this->assertThat(FormHelper::loadRuleType('bogus'), $this->isFalse(), 'Line:' . __LINE__ . ' Loading an unknown rule should return false.');
     // Test loading a custom rule.
     FormHelper::addRulePath(__DIR__ . '/_testrules');
     $this->assertThat(FormHelper::loadRuleType('custom') instanceof Rule, $this->isTrue(), 'Line:' . __LINE__ . ' Loading a known rule should return a rule object.');
     // Test all the stock rules load.
     $this->assertThat(FormHelper::loadRuleType('boolean') instanceof Rule, $this->isTrue(), 'Line:' . __LINE__ . ' Loading the boolean rule should return a rule object.');
     $this->assertThat(FormHelper::loadRuleType('email') instanceof Rule, $this->isTrue(), 'Line:' . __LINE__ . ' Loading the email rule should return a rule object.');
     $this->assertThat(FormHelper::loadRuleType('equals') instanceof Rule, $this->isTrue(), 'Line:' . __LINE__ . ' Loading the equals rule should return a rule object.');
     $this->assertThat(FormHelper::loadRuleType('options') instanceof Rule, $this->isTrue(), 'Line:' . __LINE__ . ' Loading the options rule should return a rule object.');
     $this->assertThat(FormHelper::loadRuleType('color') instanceof Rule, $this->isTrue(), 'Line:' . __LINE__ . ' Loading the color rule should return a rule object.');
     $this->assertThat(FormHelper::loadRuleType('tel') instanceof Rule, $this->isTrue(), 'Line:' . __LINE__ . ' Loading the tel rule should return a rule object.');
 }
Пример #2
0
 /**
  * Test for Form::syncPaths method.
  *
  * @return void
  */
 public function testSyncPaths()
 {
     $form = new JFormInspector('testSyncPaths');
     $this->assertThat($form->load(JFormDataHelper::$syncPathsDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.');
     $fieldPaths = FormHelper::addFieldPath();
     $formPaths = FormHelper::addFormPath();
     $rulePaths = FormHelper::addRulePath();
     $this->assertThat(in_array(JPATH_ROOT . '/field1', $fieldPaths), $this->isTrue(), 'Line:' . __LINE__ . ' The field path from the XML file should be present.');
     $this->assertThat(in_array(JPATH_ROOT . '/field2', $fieldPaths), $this->isTrue(), 'Line:' . __LINE__ . ' The field path from the XML file should be present.');
     $this->assertThat(in_array(JPATH_ROOT . '/field3', $fieldPaths), $this->isTrue(), 'Line:' . __LINE__ . ' The field path from the XML file should be present.');
     $this->assertThat(in_array(JPATH_ROOT . '/form1', $formPaths), $this->isTrue(), 'Line:' . __LINE__ . ' The form path from the XML file should be present.');
     $this->assertThat(in_array(JPATH_ROOT . '/form2', $formPaths), $this->isTrue(), 'Line:' . __LINE__ . ' The form path from the XML file should be present.');
     $this->assertThat(in_array(JPATH_ROOT . '/form3', $formPaths), $this->isTrue(), 'Line:' . __LINE__ . ' The form path from the XML file should be present.');
     $this->assertThat(in_array(JPATH_ROOT . '/rule1', $rulePaths), $this->isTrue(), 'Line:' . __LINE__ . ' The rule path from the XML file should be present.');
     $this->assertThat(in_array(JPATH_ROOT . '/rule2', $rulePaths), $this->isTrue(), 'Line:' . __LINE__ . ' The rule path from the XML file should be present.');
     $this->assertThat(in_array(JPATH_ROOT . '/rule3', $rulePaths), $this->isTrue(), 'Line:' . __LINE__ . ' The rule path from the XML file should be present.');
 }
Пример #3
0
 /**
  * Method to synchronize any field, form or rule paths contained in the XML document.
  *
  * @return  boolean  True on success.
  *
  * @since   1.0
  * @todo    Maybe we should receive all addXXXpaths attributes at once?
  */
 protected function syncPaths()
 {
     // Make sure there is a valid Form XML document.
     if (!$this->xml instanceof \SimpleXMLElement) {
         return false;
     }
     // Get any addfieldpath attributes from the form definition.
     $paths = $this->xml->xpath('//*[@addfieldpath]/@addfieldpath');
     $paths = array_map('strval', $paths ? $paths : array());
     // Add the field paths.
     foreach ($paths as $path) {
         $path = JPATH_ROOT . '/' . ltrim($path, '/\\');
         FormHelper::addFieldPath($path);
     }
     // Get any addformpath attributes from the form definition.
     $paths = $this->xml->xpath('//*[@addformpath]/@addformpath');
     $paths = array_map('strval', $paths ? $paths : array());
     // Add the form paths.
     foreach ($paths as $path) {
         $path = JPATH_ROOT . '/' . ltrim($path, '/\\');
         FormHelper::addFormPath($path);
     }
     // Get any addrulepath attributes from the form definition.
     $paths = $this->xml->xpath('//*[@addrulepath]/@addrulepath');
     $paths = array_map('strval', $paths ? $paths : array());
     // Add the rule paths.
     foreach ($paths as $path) {
         $path = JPATH_ROOT . '/' . ltrim($path, '/\\');
         FormHelper::addRulePath($path);
     }
     return true;
 }