コード例 #1
0
 /**
  * Tests the Form::addFormPath method.
  *
  * This method is used to add additional lookup paths for form XML files.
  *
  * @return void
  */
 public function testAddFormPath()
 {
     // Check the default behaviour.
     $paths = FormHelper::addFormPath();
     // The default path is the class file folder/forms
     // use of realpath to ensure test works for on all platforms
     $valid = dirname(__DIR__) . '/form';
     $this->assertThat(in_array($valid, $paths), $this->isTrue(), 'Line:' . __LINE__ . ' The libraries forms path should be included by default.');
     // Test adding a custom folder.
     FormHelper::addFormPath(__DIR__);
     $paths = FormHelper::addFormPath();
     $this->assertThat(in_array(__DIR__, $paths), $this->isTrue(), 'Line:' . __LINE__ . ' An added path should be in the returned array.');
 }
コード例 #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
ファイル: Form.php プロジェクト: ZerGabriel/joomla-framework
 /**
  * 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;
 }