X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fcaxy%2Fphp-htmldiff%2Ftests%2FCaxy%2FTests%2FHtmlDiff%2FHtmlFileIterator.php;fp=vendor%2Fcaxy%2Fphp-htmldiff%2Ftests%2FCaxy%2FTests%2FHtmlDiff%2FHtmlFileIterator.php;h=5fc7de0d6c907611e43a5b9315a9e6925d018747;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/caxy/php-htmldiff/tests/Caxy/Tests/HtmlDiff/HtmlFileIterator.php b/vendor/caxy/php-htmldiff/tests/Caxy/Tests/HtmlDiff/HtmlFileIterator.php new file mode 100644 index 000000000..5fc7de0d6 --- /dev/null +++ b/vendor/caxy/php-htmldiff/tests/Caxy/Tests/HtmlDiff/HtmlFileIterator.php @@ -0,0 +1,103 @@ +files = glob($directory.DIRECTORY_SEPARATOR."*.html"); + } + + /** + * Return the current element + * @link http://php.net/manual/en/iterator.current.php + * @return mixed Can return any type. + * @since 5.0.0 + */ + public function current() + { + return $this->loadHtmlFile($this->key); + } + + /** + * Move forward to next element + * @link http://php.net/manual/en/iterator.next.php + * @return void Any returned value is ignored. + * @since 5.0.0 + */ + public function next() + { + $this->key++; + } + + /** + * Return the key of the current element + * @link http://php.net/manual/en/iterator.key.php + * @return mixed scalar on success, or null on failure. + * @since 5.0.0 + */ + public function key() + { + return basename($this->files[$this->key]); + } + + /** + * Checks if current position is valid + * @link http://php.net/manual/en/iterator.valid.php + * @return boolean The return value will be casted to boolean and then evaluated. + * Returns true on success or false on failure. + * @since 5.0.0 + */ + public function valid() + { + return isset($this->files[$this->key]); + } + + /** + * Rewind the Iterator to the first element + * @link http://php.net/manual/en/iterator.rewind.php + * @return void Any returned value is ignored. + * @since 5.0.0 + */ + public function rewind() + { + $this->key = 0; + } + + protected function loadHtmlFile($key) + { + $filename = $this->files[$key]; + + if (!isset($this->loadedDiffs[$filename])) { + + $html = file_get_contents($filename); + + $oldText = $this->parseTagContent('oldText', $html); + $newText = $this->parseTagContent('newText', $html); + $expected = $this->parseTagContent('expected', $html); + + if (null === $expected) { + throw new \Exception('HTML fixture content should have an tag.'); + } + + $this->loadedDiffs[$filename] = array($oldText, $newText, $expected); + } + + return $this->loadedDiffs[$filename]; + } + + protected function parseTagContent($tagName, $html) + { + $matches = array(); + if (preg_match(sprintf('/<%s\s*[^>]*>(.*)<\/%s\s*>/is', $tagName, $tagName), $html, $matches)) { + return $matches[1]; + } + + return null; + } +}