/**
  * Get any value
  * @uses \DOMDocument::loadXML()
  * @uses \DOMDocument::hasChildNodes()
  * @uses \DOMDocument::saveXML()
  * @uses \DOMNode::item()
  * @uses \Ews\StructType\EwsConfigurationRequestDetailsType::setAny()
  * @param bool $asString true: returns XML string, false: returns \DOMDocument
  * @return \DOMDocument|null
  */
 public function getAny($asString = true)
 {
     if (!empty($this->any) && !$this->any instanceof \DOMDocument) {
         $dom = new \DOMDocument('1.0', 'UTF-8');
         $dom->formatOutput = true;
         if ($dom->loadXML($this->any)) {
             $this->setAny($dom);
         }
         unset($dom);
     }
     return $asString && $this->any instanceof \DOMDocument && $this->any->hasChildNodes() ? $this->any->saveXML($this->any->childNodes->item(0)) : $this->any;
 }
 /**
  * Find valid root node (not a comment, at least a DOMElement node)
  * @throws \InvalidArgumentException
  */
 protected function initRootElement()
 {
     if ($this->domDocument->hasChildNodes()) {
         foreach ($this->domDocument->childNodes as $node) {
             if ($node instanceof \DOMElement) {
                 $this->rootElement = $this->getElementHandler($node, $this);
                 break;
             }
         }
     } else {
         throw new \InvalidArgumentException('Document seems to be invalid', __LINE__);
     }
 }
Example #3
0
 /**
  * @param \DOMDocument|\DOMElement $dom
  * @return array
  */
 private function convertXmlToArray($dom)
 {
     $result = array();
     if ($dom->hasChildNodes()) {
         $children = $dom->childNodes;
         if (1 === $children->length) {
             $child = $children->item(0);
             if ($child->nodeType == XML_TEXT_NODE) {
                 $result['_value'] = $child->nodeValue;
                 return urldecode(count($result) == 1 ? $result['_value'] : $result);
             }
         }
         $groups = array();
         foreach ($children as $child) {
             if (!isset($result[$child->nodeName])) {
                 $result[$child->nodeName] = $this->convertXmlToArray($child);
             } else {
                 if (!isset($groups[$child->nodeName])) {
                     $result[$child->nodeName] = array($result[$child->nodeName]);
                     $groups[$child->nodeName] = 1;
                 }
                 $result[$child->nodeName][] = $this->convertXmlToArray($child);
             }
         }
     }
     return $result;
 }
Example #4
0
 /**
  * Convert xml node to array or string
  *
  * @param \DOMDocument $node
  * @return array|string
  */
 public function convert($node)
 {
     $result = [];
     if ($node->nodeType == XML_TEXT_NODE) {
         $result = $node->nodeValue;
     } else {
         if ($node->hasChildNodes()) {
             $children = $node->childNodes;
             for ($i = 0; $i < $children->length; $i++) {
                 $child = $children->item($i);
                 if ($child->nodeName != '#text') {
                     $result[$child->nodeName][] = $this->convert($child);
                 } else {
                     if ($child->nodeName == '#text') {
                         $text = $this->convert($child);
                         if (trim($text) != '') {
                             $result[$child->nodeName] = $this->convert($child);
                         }
                     }
                 }
             }
         }
         if ($node->hasAttributes()) {
             $attributes = $node->attributes;
             if (!is_null($attributes)) {
                 foreach ($attributes as $attribute) {
                     $result[$attribute->name] = $attribute->value;
                 }
             }
         }
     }
     return $result;
 }
Example #5
0
 /**
  * Parse dom document
  *
  * @param \DOMDocument $dom
  * @return array
  */
 public function parse(\DOMDocument $dom)
 {
     $result = [];
     if ($dom->hasChildNodes()) {
         foreach ($dom->childNodes as $child) {
             if (XML_COMMENT_NODE == $child->nodeType) {
                 $result['comment'] = $child->nodeValue;
             } elseif (XML_ELEMENT_NODE == $child->nodeType && 'config' == $child->nodeName) {
                 $result = array_merge($result, $this->_parseNode($child));
             }
         }
     }
     return $result;
 }
 /**
  * Get the html node for this element
  * @param AppBuilderAPIDOMDocument $xml
  * @param array $data
  * @return DOMElement
  */
 public function getHTMLNode($xml, &$data)
 {
     $node = parent::getHTMLNode($xml, $data);
     $node->appendChild($htmlNode = $xml->createElement('div', 'html'));
     $html = $this->html;
     if ($html != '') {
         $fragDoc = new DOMDocument();
         @$fragDoc->loadHTML('<?xml version="1.0" encoding="utf-8" standalone="yes"?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/ loose.dtd"><html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body>' . $html . '</body></html>');
         if ($fragDoc->hasChildNodes()) {
             $body = $fragDoc->getElementsByTagName('body')->item(0);
             if ($body->hasChildNodes()) {
                 for ($i = 0; $i < $body->childNodes->length; $i++) {
                     $iNode = $body->childNodes->item($i);
                     $importedNode = $xml->importNode($iNode, true);
                     $htmlNode->appendChild($importedNode);
                 }
                 $this->checkNode($xml, $htmlNode);
             }
         }
     }
     return $node;
 }
Example #7
0
 /**
  * Get the html node for this element
  *
  * @param \DOMElement $node
  * @param \AppShed\Remote\XML\DOMDocument $xml
  * @param \AppShed\Remote\HTML\Settings $settings
  */
 protected function getHTMLNodeInner($node, $xml, $settings)
 {
     $node->appendChild($htmlNode = $xml->createElement('div', 'html'));
     $html = $this->html;
     if ($html != '') {
         $fragDoc = new \DOMDocument();
         $libxml_previous_state = libxml_use_internal_errors(true);
         $fragDoc->loadHTML('<?xml version="1.0" encoding="utf-8" standalone="yes"?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/ loose.dtd"><html><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body>' . $html . '</body></html>');
         libxml_clear_errors();
         libxml_use_internal_errors($libxml_previous_state);
         if ($fragDoc->hasChildNodes()) {
             $body = $fragDoc->getElementsByTagName('body')->item(0);
             if ($body->hasChildNodes()) {
                 for ($i = 0; $i < $body->childNodes->length; $i++) {
                     $iNode = $body->childNodes->item($i);
                     $importedNode = $xml->importNode($iNode, true);
                     $htmlNode->appendChild($importedNode);
                 }
                 $this->checkNode($xml, $htmlNode);
             }
         }
     }
 }
Example #8
0
 /**
  * Convert opml xml node into array for import
  * http://www.php.net/manual/en/class.domdocument.php#101014
  *
  * @param DOMDocument $node Node to convert into array
  *
  * @return array            Array corresponding to the given node
  */
 public static function getArrayFromXml($node)
 {
     $array = false;
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             $array[$attr->nodeName] = $attr->nodeValue;
         }
     }
     if ($node->hasChildNodes()) {
         if ($node->childNodes->length == 1) {
             $array[$node->firstChild->nodeName] = $node->firstChild->nodeValue;
         } else {
             foreach ($node->childNodes as $childNode) {
                 if ($childNode->nodeType != XML_TEXT_NODE) {
                     $array[$childNode->nodeName][] = Opml::getArrayFromXml($childNode);
                 }
             }
         }
     }
     return $array;
 }
 /**
  * Test if the breadcrumb is functionnal.
  *
  * @cover BreadcrumbExtension::getTemplateName()
  * @cover BreadcrumbExtension::breadcrumbRender()
  * @cover BreadcrumbExtension::breadcrumbDisplay()
  */
 public function testFunctionnal()
 {
     $service = new BreadcrumbService();
     $extension = new BreadcrumbExtension($this->environment, $service);
     // Test default
     $template = $extension->getTemplateName();
     $this->assertEquals('bs_breadcrumb/breadcrumb.html.twig', $template);
     $this->assertTrue($this->filesystemLoader->exists($template));
     ob_start();
     $extension->breadcrumbDisplay();
     $display = ob_get_contents();
     ob_end_clean();
     $html = $extension->breadcrumbRender();
     $this->assertTrue(is_string($html));
     $this->assertGreaterThan(20, strlen($html));
     $this->assertEquals($display, $html);
     $dom = new \DOMDocument();
     $dom->loadXML($html);
     $this->assertTrue($dom->hasChildNodes());
     $container = $dom->firstChild;
     $this->assertEquals('div', $container->nodeName);
     $this->assertEquals('container-fluid', $container->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(1, $container->childNodes->length);
     $row = $container->firstChild;
     $this->assertEquals('div', $row->nodeName);
     $this->assertEquals('row', $row->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(1, $row->childNodes->length);
     $breadcrumb = $row->firstChild;
     $this->assertEquals('ol', $breadcrumb->nodeName);
     $this->assertEquals('breadcrumb', $breadcrumb->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(0, $breadcrumb->childNodes->length);
     // Test content
     $data_test = array(array('Page 1 ' . uniqid(), '/', 'glyphicon-home'), array('Page 2 ' . uniqid(), 'bootstrap-bundle-test-route', null), array('Page 3 ' . uniqid(), null, null));
     foreach ($data_test as $attrs) {
         $link = new BreadcrumbLink($attrs[0], $attrs[1], $attrs[2]);
         $service->pushLink($link);
     }
     $html = $extension->breadcrumbRender();
     $dom->loadXML($html);
     $breadcrumb = $dom->firstChild->firstChild->firstChild;
     $this->assertEquals('ol', $breadcrumb->nodeName);
     $this->assertEquals('breadcrumb', $breadcrumb->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(3, $breadcrumb->childNodes->length);
     foreach ($breadcrumb->childNodes as $k => $node) {
         $this->assertEquals($data_test[$k][0], $node->nodeValue);
     }
     $this->assertEquals('a', $breadcrumb->childNodes->item(0)->firstChild->nodeName);
     $this->assertEquals('a', $breadcrumb->childNodes->item(1)->firstChild->nodeName);
     $this->assertEquals('#text', $breadcrumb->childNodes->item(2)->firstChild->nodeName);
     $this->assertEquals($data_test[0][1], $breadcrumb->childNodes->item(0)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals($data_test[1][1], $breadcrumb->childNodes->item(1)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals('i', $breadcrumb->childNodes->item(0)->firstChild->firstChild->nodeName);
     $this->assertEquals('#text', $breadcrumb->childNodes->item(1)->firstChild->firstChild->nodeName);
     $this->assertEquals('glyphicon ' . $data_test[0][2], $breadcrumb->childNodes->item(0)->firstChild->firstChild->attributes->getNamedItem('class')->nodeValue);
     // Test with the url generator
     $service = new BreadcrumbService($this->urlGenerator);
     $extension = new BreadcrumbExtension($this->environment, $service);
     foreach ($data_test as $attrs) {
         $link = new BreadcrumbLink($attrs[0], $attrs[1], $attrs[2]);
         $service->pushLink($link);
     }
     $html = $extension->breadcrumbRender();
     $dom->loadXML($html);
     $breadcrumb = $dom->firstChild->firstChild->firstChild;
     $this->assertEquals($data_test[0][1], $breadcrumb->childNodes->item(0)->firstChild->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals($this->urlGenerator->generate($data_test[1][1]), $breadcrumb->childNodes->item(1)->firstChild->attributes->getNamedItem('href')->nodeValue);
 }
 /**
  * Rollback *all* web.config settings
  * This removes the specific xpaths we added.
  * Unmerging XML docs is ugly and complex.  We don't have the ability to ermove "chunks"
  * like in the .htaccess files.  It's all or nothing.
  * @return void
  */
 protected function _rollback_web_config()
 {
     if (!file_exists($this->_web_config_path)) {
         return true;
     }
     if (file_exists($this->_web_config_path) && !win_is_writable($this->_web_config_path)) {
         return false;
     }
     // Get the parent doc
     libxml_use_internal_errors(true);
     $DOMParent = new DOMDocument();
     $DOMParent->formatOutput = true;
     try {
         $DOMParent->load($this->_web_config_path);
     } catch (Exception $e) {
         return false;
     }
     // Remove any matching nodes in the parent
     $xpath = new DOMXPath($DOMParent);
     $paths = array("//*/caching/profiles/add[@duration='00:01:00']", "//*/urlCompression[@doDynamicCompression='true']", "//*/clientCache[@cacheControlMaxAge='14.00:00:00']");
     foreach ($paths as $path) {
         $query = $xpath->query($path);
         if ($query->length > 0) {
             for ($i = 0; $i < $query->length; $i++) {
                 $query->item($i)->parentNode->removeChild($query->item($i));
             }
         }
     }
     // Remove empty nodes
     $paths = array("//configuration/system.webServer/caching/profiles", "//configuration/system.webServer/caching", "//configuration/system.webServer/staticContent", "//configuration/system.webServer", "//configuration");
     foreach ($paths as $path) {
         $query = $xpath->query($path);
         if ($query->length > 0) {
             for ($i = 0; $i < $query->length; $i++) {
                 $node = $query->item($i);
                 $nodeHasEmptyText = true;
                 for ($i = 0; $i < $node->childNodes->length; $i++) {
                     if (!$node->childNodes->item($i) instanceof DOMText || '' !== trim($node->childNodes->item($i)->nodeValue)) {
                         $nodeHasEmptyText = false;
                         break;
                     }
                 }
                 if (!$node->hasAttributes() && (!$node->hasChildNodes() || $nodeHasEmptyText)) {
                     $node->parentNode->removeChild($node);
                 }
             }
         }
     }
     // If there is no root element, then save a dummy web.config
     if (!$DOMParent->hasChildNodes()) {
         if (0 === @file_put_contents($this->_web_config_path, '<' . '?xml version="1.0"?' . ">\n<configuration><system.webServer/></configuration>")) {
             return false;
         }
     } else {
         // Save the XML to the parent doc's file
         try {
             $DOMParent->save($this->_web_config_path);
         } catch (Exception $e) {
             return false;
         }
     }
     return true;
 }
Example #11
0
 /**
  * Function will reformat the xml document to have correct indention.
  *
  * @param $strXml
  * @return DOMDocument
  */
 private function formatXmlString($strXml)
 {
     try {
         $doc = new DOMDocument();
         $doc->loadXML($strXml, LIBXML_NOBLANKS);
         $doc->preserveWhiteSpace = false;
         $doc->formatOutput = true;
     } catch (Exception $e) {
         LogHelper::log_error('Error formatting xml: ' . $e);
     }
     return $doc != NULL && $doc->hasChildNodes() ? $doc->saveXML() : NULL;
 }
Example #12
0
 /**
  * @param WebDavClient $client
  * @param string $xml The multi-status response as an XML string
  *
  * @throws \RuntimeException
  * @return self Returns the parsed multi-status response as an object
  *
  * @todo
  * - validate the XML document using a WebDAV DTD
  * - register namespaces automatically with the Xpath object
  * - testing DOMDocument::loadXML throwing DOMException with the libxml settings and an erroneous XML document
  */
 public static function parse(WebDavClient $client, $xml)
 {
     $xml = preg_replace('/\\s*[\\r\\n]\\s*/', null, $xml);
     $dom = new \DOMDocument();
     $dom->formatOutput = false;
     $dom->preserveWhiteSpace = false;
     $dom->loadXML($xml, LIBXML_NOWARNING | LIBXML_NOERROR);
     // XSD validation ? Namespaces ?
     $xpath = new \DOMXPath($dom);
     $xpath->registerNamespace('D', 'DAV:');
     if (!$dom->hasChildNodes()) {
         throw new \RuntimeException();
     }
     if ($dom->documentElement->localName != self::TAGNAME) {
         throw new \RuntimeException();
     }
     $result = array();
     $description = $xpath->evaluate('string(D:responsedescription)', $dom->documentElement);
     foreach ($xpath->query('./D:response', $dom->documentElement) as $xResponse) {
         $href = $xpath->evaluate('string(D:href)', $xResponse);
         $statusLine = $xpath->evaluate('string(D:status)', $xResponse);
         $responseDescription = $xpath->evaluate('string(D:responsedescription)', $xResponse);
         // Determines whether this response uses a combination of href+status elements
         // or if it uses a list of propstat elements
         $responseStatus = $statusLine ? self::parseHttpStatus($statusLine) : array();
         foreach ($xpath->query('./D:propstat', $xResponse) as $xPropstat) {
             $statusCode = self::parseHttpStatus($xpath->evaluate('string(D:status)', $xPropstat));
             $responseStatus[$statusCode] = array();
             foreach ($xpath->query('./D:prop/*', $xPropstat) as $xProperty) {
                 if (!isset($client->xmlNamespaces[$xProperty->namespaceURI])) {
                     continue;
                 }
                 if (isset($client->propertyMap[$xProperty->localName])) {
                     $propertyClass = $client->propertyMap[$xProperty->localName];
                 } else {
                     $propertyClass = __NAMESPACE__ . '\\Property';
                 }
                 $responseStatus[$statusCode][] = $propertyClass::fromXml($xProperty, $client->xmlNamespaces);
             }
         }
         $result[] = new Response($href, $responseStatus, $responseDescription ? $responseDescription : null);
     }
     return new self($result, $description);
 }
Example #13
0
 /**
  * @param \DOMDocument|string $xml $xml
  * @return array
  */
 public function convertXMLToArray($xml)
 {
     $result = array();
     if ($xml->hasAttributes()) {
         $attrs = $xml->attributes;
         foreach ($attrs as $attr) {
             $result['@attributes'][$attr->name] = $attr->value;
         }
     }
     if ($xml->hasChildNodes()) {
         $children = $xml->childNodes;
         if ($children->length == 1) {
             $child = $children->item(0);
             if ($child->nodeType == XML_TEXT_NODE || $child->nodeType == XML_CDATA_SECTION_NODE) {
                 $result['_value'] = $child->nodeValue;
                 return count($result) == 1 ? $result['_value'] : $result;
             }
         }
         $groups = array();
         foreach ($children as $child) {
             if (!isset($result[$child->nodeName])) {
                 $result[$child->nodeName] = $this->convertXMLToArray($child);
             } else {
                 if (!isset($groups[$child->nodeName])) {
                     $result[$child->nodeName] = array($result[$child->nodeName]);
                     $groups[$child->nodeName] = 1;
                 }
                 $result[$child->nodeName][] = $this->convertXMLToArray($child);
             }
             if (empty($result[$child->nodeName])) {
                 unset($result[$child->nodeName]);
             } elseif (is_array($result[$child->nodeName])) {
                 $values = array();
                 foreach ($result[$child->nodeName] as $key => $val) {
                     if (!empty($result[$child->nodeName][$key])) {
                         $values[] = $result[$child->nodeName][$key];
                         if (count($values) > 1) {
                             break;
                         }
                     }
                 }
                 if (empty($values)) {
                     unset($result[$child->nodeName]);
                 }
             }
         }
     }
     return $result;
 }
 /**
  * Test is the navbar is functionnal.
  *
  * @cover NavbarExtension::navbarRender()
  * @cover NavbarExtension::navbarDisplay()
  */
 public function testOutput()
 {
     $container = new NavbarService();
     $extension = new NavbarExtension($this->environment, $container, $this->configuration);
     // Test default
     $template = $extension->getTemplateName();
     $this->assertEquals('bs_navbar/navbar.html.twig', $template);
     $this->assertTrue($this->filesystemLoader->exists($template));
     ob_start();
     $extension->navbarDisplay();
     $display = ob_get_contents();
     ob_end_clean();
     $html = $extension->navbarRender();
     $this->assertTrue(is_string($html));
     $this->assertGreaterThan(20, strlen($html));
     $this->assertEquals($display, $html);
     $dom = new \DOMDocument();
     $dom->loadXML($html);
     $this->assertTrue($dom->hasChildNodes());
     $navbar = $dom->firstChild;
     $this->assertEquals('nav', $navbar->nodeName);
     $this->assertEquals('navbar navbar-fixed-top', $navbar->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(1, $navbar->childNodes->length);
     $container = $navbar->firstChild;
     $this->assertEquals('div', $container->nodeName);
     $this->assertEquals('container-fluid', $container->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(2, $container->childNodes->length);
     $header = $container->firstChild;
     $this->assertEquals('div', $header->nodeName);
     $this->assertEquals('navbar-header', $header->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals(2, $header->childNodes->length);
     $collapse = $container->childNodes->item(1);
     $this->assertEquals('div', $collapse->nodeName);
     $this->assertEquals('collapse navbar-collapse', $collapse->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals('neimheadh-bootstrap-navbar-collapse', $collapse->attributes->getNamedItem('id')->nodeValue);
     $this->assertEquals(1, $collapse->childNodes->length);
     $menus = $collapse->firstChild;
     $this->assertEquals('ul', $menus->nodeName);
     $this->assertEquals('nav navbar-nav navbar-right', $menus->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals('neimheadh-bootstrap-nav', $menus->attributes->getNamedItem('id')->nodeValue);
     $this->assertEquals(0, $menus->childNodes->length);
     $button = $header->firstChild;
     $this->assertEquals('button', $button->nodeName);
     $this->assertEquals('button', $button->attributes->getNamedItem('type')->nodeValue);
     $this->assertEquals('navbar-toggle collapsed', $button->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals('collapse', $button->attributes->getNamedItem('data-toggle')->nodeValue);
     $this->assertEquals('#' . $collapse->attributes->getNamedItem('id')->nodeValue, $button->attributes->getNamedItem('data-target')->nodeValue);
     $this->assertEquals('false', $button->attributes->getNamedItem('aria-expanded')->nodeValue);
     $this->assertEquals(4, $button->childNodes->length);
     foreach ($button->childNodes as $i => $node) {
         $this->assertEquals('span', $node->nodeName);
         $this->assertEquals($i == 0 ? 'sr-only' : 'icon-bar', $node->attributes->getNamedItem('class')->nodeValue);
         if ($i == 0) {
             $this->assertEquals('Navigation', $node->nodeValue);
         }
     }
     // Test config
     $configuration = $this->getConfigurationExample('navbar.config1.yml');
     $configuration = $configuration['neimheadh_bootstrap']['navbar'];
     $container = new NavbarService();
     $extension = new NavbarExtension($this->environment, $container, $configuration);
     // The templates will not be good
     $error = false;
     try {
         $extension->navbarRender();
     } catch (\Twig_Error_Loader $e) {
         $error = true;
     }
     $this->assertTrue($error);
     $configuration['template'] = 'bs_navbar/navbar.html.twig';
     $extension->setConfiguration($configuration);
     $error = false;
     try {
         $extension->navbarRender();
     } catch (\Twig_Error_Loader $e) {
         $error = true;
     }
     $this->assertTrue($error);
     $configuration['header']['template'] = 'bs_navbar/navbar-header.html.twig';
     $extension->setConfiguration($configuration);
     $error = false;
     try {
         $extension->navbarRender();
     } catch (\Twig_Error_Loader $e) {
         $error = true;
     }
     $this->assertTrue($error);
     $configuration['menu']['_list']['template'] = 'bs_navbar/navbar-menu.html.twig';
     $extension->setConfiguration($configuration);
     $html = $extension->navbarRender();
     $dom = new \DOMDocument();
     $dom->loadXML($html);
     $this->assertTrue($dom->hasChildNodes());
     $navbar = $dom->firstChild;
     $container = $navbar->firstChild;
     $header = $container->firstChild;
     $collapse = $container->childNodes->item(1);
     $menus = $collapse->firstChild;
     $button = $header->firstChild;
     $this->assertEquals($configuration['class'] . ' ' . $configuration['position_class'] . ' ' . $configuration['custom_class'], $navbar->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals($configuration['container']['class'], $container->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals($configuration['header']['class'], $header->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals($configuration['header']['title'], $header->childNodes->item(1)->nodeValue);
     $this->assertEquals($configuration['header']['link'], $header->childNodes->item(1)->attributes->getNamedItem('href')->nodeValue);
     $this->assertEquals($configuration['menu']['_container']['id'], $collapse->attributes->getNamedItem('id')->nodeValue);
     $this->assertEquals('#' . $configuration['menu']['_container']['id'], $button->attributes->getNamedItem('data-target')->nodeValue);
     $this->assertEquals($configuration['menu']['_container']['class'], $collapse->attributes->getNamedItem('class')->nodeValue);
     $this->assertEquals($configuration['menu']['_list']['id'], $menus->attributes->getNamedItem('id')->nodeValue);
     $this->assertEquals($configuration['menu']['_list']['class'], $menus->attributes->getNamedItem('class')->nodeValue);
     // Test menus
     $menus_cfg = $configuration['menu']['_menus'][0]['content'];
     $this->assertEquals(4, $menus->childNodes->length);
     foreach ($menus->childNodes as $i => $menu) {
         $this->assertEquals('li', $menu->nodeName);
         $this->assertEquals($configuration['menu']['_list']['children']['class'], $menu->attributes->getNamedItem('class')->nodeValue);
         $this->assertEquals($configuration['menu']['_list']['children']['role'], $menu->attributes->getNamedItem('role')->nodeValue);
         switch ($i) {
             case 3:
                 $i++;
             case 0:
                 $this->assertEquals(2, $menu->childNodes->length);
                 $this->assertEquals('a', $menu->firstChild->nodeName);
                 $this->assertEquals('ul', $menu->childNodes->item(1)->nodeName);
                 $this->assertEquals('dropdown-menu', $menu->childNodes->item(1)->attributes->getNamedItem('class')->nodeValue);
                 $this->assertEquals(1, $menu->childNodes->item(1)->childNodes->length);
                 $this->assertEquals('li', $menu->childNodes->item(1)->firstChild->nodeName);
                 $this->assertEquals($configuration['menu']['_list']['children']['class'], $menu->childNodes->item(1)->firstChild->attributes->getNamedItem('class')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['children']['role'], $menu->childNodes->item(1)->firstChild->attributes->getNamedItem('role')->nodeValue);
                 $this->assertEquals(1, $menu->childNodes->item(1)->firstChild->childNodes->length);
                 $this->assertEquals('a', $menu->childNodes->item(1)->firstChild->firstChild->nodeName);
                 $this->assertEquals($menus_cfg[$i == 4 ? 5 : 2]['title'], $menu->childNodes->item(1)->firstChild->firstChild->nodeValue);
                 $this->assertEquals($menus_cfg[$i == 4 ? 5 : 2]['route'], $menu->childNodes->item(1)->firstChild->firstChild->attributes->getNamedItem('href')->nodeValue);
                 $this->assertEquals(2, $menu->firstChild->childNodes->length);
                 $this->assertEquals('#text', $menu->firstChild->firstChild->nodeName);
                 $this->assertEquals('span', $menu->firstChild->childNodes->item(1)->nodeName);
                 $this->assertEquals($menus_cfg[$i]['title'], trim($menu->firstChild->firstChild->nodeValue));
                 $this->assertEquals($i == 4 ? '#' : $menus_cfg[$i]['route'], $menu->firstChild->attributes->getNamedItem('href')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['class'], $menu->firstChild->attributes->getNamedItem('class')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['data_toggle'], $menu->firstChild->attributes->getNamedItem('data-toggle')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['role'], $menu->firstChild->attributes->getNamedItem('role')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['aria']['haspopup'], $menu->firstChild->attributes->getNamedItem('aria-haspopup')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['aria']['expanded'], $menu->firstChild->attributes->getNamedItem('aria-expanded')->nodeValue);
                 $this->assertEquals($configuration['menu']['_list']['dropdown']['caret']['class'], $menu->firstChild->childNodes->item(1)->attributes->getNamedItem('class')->nodeValue);
                 break;
             case 2:
                 $i++;
             case 1:
                 $this->assertEquals(1, $menu->childNodes->length);
                 $this->assertEquals('a', $menu->firstChild->nodeName);
                 $this->assertEquals($menus_cfg[$i]['title'], $menu->firstChild->nodeValue);
                 $this->assertEquals($menus_cfg[$i]['route'], $menu->firstChild->attributes->getNamedItem('href')->nodeValue);
                 break;
         }
     }
 }
Example #15
0
 /**
  * @param $document
  * @return mixed|null
  */
 private function getDocumentString(DOMDocument $document)
 {
     $document->preserveWhiteSpace = false;
     $document->formatOutput = true;
     $document_str = $document != NULL && $document->hasChildNodes() ? $document->saveXML(NULL, LIBXML_NOBLANKS) : NULL;
     // TODO - current 'LIBXML_NOXMLDECL' is not working.
     if (isset($document_str)) {
         $document_str = str_replace('<?xml version="1.0"?>', '', $document_str);
     }
     return $document_str;
 }
 /** Parse a SPARQL result in the XML format into the object.
  *
  * @ignore
  */
 protected function _parseXml($data)
 {
     $doc = new DOMDocument();
     $doc->loadXML($data);
     # Check for valid root node.
     if ($doc->hasChildNodes() == false or $doc->childNodes->length != 1 or $doc->firstChild->nodeName != 'sparql' or $doc->firstChild->namespaceURI != self::SPARQL_XML_RESULTS_NS) {
         throw new EasyRdf_Exception("Incorrect root node in SPARQL XML Query Results format");
     }
     # Is it the result of an ASK query?
     $boolean = $doc->getElementsByTagName('boolean');
     if ($boolean->length) {
         $this->_type = 'boolean';
         $value = $boolean->item(0)->nodeValue;
         $this->_boolean = $value == 'true' ? true : false;
         return;
     }
     # Get a list of variables from the header
     $head = $doc->getElementsByTagName('head');
     if ($head->length) {
         $variables = $head->item(0)->getElementsByTagName('variable');
         foreach ($variables as $variable) {
             $this->_fields[] = $variable->getAttribute('name');
         }
     }
     # Is it the result of a SELECT query?
     $resultstag = $doc->getElementsByTagName('results');
     if ($resultstag->length) {
         $this->_type = 'bindings';
         $results = $resultstag->item(0)->getElementsByTagName('result');
         foreach ($results as $result) {
             $bindings = $result->getElementsByTagName('binding');
             $t = new stdClass();
             foreach ($bindings as $binding) {
                 $key = $binding->getAttribute('name');
                 foreach ($binding->childNodes as $node) {
                     if ($node->nodeType != XML_ELEMENT_NODE) {
                         continue;
                     }
                     $t->{$key} = $this->_newTerm(array('type' => $node->nodeName, 'value' => $node->nodeValue, 'lang' => $node->getAttribute('xml:lang'), 'datatype' => $node->getAttribute('datatype')));
                     break;
                 }
             }
             $this[] = $t;
         }
         return $this;
     }
     throw new EasyRdf_Exception("Failed to parse SPARQL XML Query Results format");
 }
Example #17
0
 /**
  * @param WebDavClient $client
  * @param string $xml
  *
  * @throws \RuntimeException
  * @return self
  *
  * @todo
  * - validate the XML document using a WebDAV DTD
  * - register namespaces automatically with the Xpath object
  * - testing DOMDocument::loadXML throwing DOMException with the libxml settings and an erroneous XML document
  */
 public static function parse(WebDavClient $client, $xml)
 {
     $xml = preg_replace('/\\s*[\\r\\n]\\s*/', null, $xml);
     $dom = new \DOMDocument();
     $dom->formatOutput = false;
     $dom->preserveWhiteSpace = false;
     $dom->loadXML($xml, LIBXML_NOWARNING | LIBXML_NOERROR);
     // XSD validation ? Namespaces ?
     $xpath = new \DOMXPath($dom);
     $xpath->registerNamespace('D', 'DAV:');
     if (!$dom->hasChildNodes()) {
         throw new \RuntimeException();
     }
     $lockInstance = null;
     $xActiveLocks = $xpath->query('./D:lockdiscovery/D:activelock', $dom->documentElement);
     if ($xActiveLocks->length > 0) {
         $lockInstance = self::fromXml($xActiveLocks->item(0));
     }
     return $lockInstance;
 }