Skip to content

Commit 22aa019

Browse files
committed
Updated composer dependencies, which are now pegged to releases rather than @dev.
Added tests to show that the CSS and Javascript parser and minifiers work. Updated phpunit.xml to remove src/autoload.php from coverage reports. Improved documentation. Bumped to v1.2.2.
1 parent 849b61e commit 22aa019

File tree

8 files changed

+73
-23
lines changed

8 files changed

+73
-23
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"minimum-stability": "stable",
1414
"require": {
1515
"php": ">=7.3",
16-
"hexydec/tokenise": "@dev",
17-
"hexydec/cssdoc": "@dev",
18-
"hexydec/jslite": "@dev"
16+
"hexydec/tokenise": "0.4.0",
17+
"hexydec/cssdoc": "0.3.0",
18+
"hexydec/jslite": "0.4.0"
1919
},
2020
"autoload": {
2121
"classmap": ["src/"]

composer.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/construct.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ $doc = new \hexydec\html\htmldoc($config);
77
```
88
## Arguments
99

10-
### $config
10+
### `$config`
1111

12-
The options set into the object are setup for general use, but can be configured with the following options:
12+
A optional array of configuration options that will be merged recursively with the default configuration. The available options and their defaults are:
1313

1414
#### `elements`
1515

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
</style>
188188
</head>
189189
<body>
190-
<form action="<?= \htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" accept-charset="<?= \htmlspecialchars(\mb_internal_encoding()); ?>" class="minify__form">
190+
<form action="<?= \htmlspecialchars($_SERVER['REQUEST_URI']); ?>" method="post" accept-charset="<?= \htmlspecialchars(\mb_internal_encoding()); ?>" class="minify__form">
191191
<div class="minify__form-wrap">
192192
<h1 class="minify__form-heading">HTML Minifier</h1>
193193
<?php if ($error) { ?>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "HTMLdoc",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "A token based HTML Document parser and minifier written in PHP",
55
"main": "src/htmldoc.php",
66
"directories": {

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<include>
55
<directory suffix=".php">src</directory>
66
</include>
7+
<exclude>
8+
<file>src/autoload.php</file>
9+
</exclude>
710
<report>
811
<clover outputFile="./coverage/result.xml"/>
912
<html outputDirectory="./coverage/result"/>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if ($doc->open($url) {
6363
The easiest way to get up and running is to use composer:
6464

6565
```
66-
$ composer install
66+
$ composer install hexydec/htmldoc
6767
```
6868

6969
HTMLdoc requires [\hexydec\token\tokenise](https://github.com/hexydec/tokenise) to run, which you can install manually if not using composer. Optionally you can also install [CSSdoc](https://github.com/hexydec/cssdoc) and [JSlite](https://github.com/hexydec/jslite) to perform inline CSS and Javascript minification respectively.

tests/minifyHtmldocTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,51 @@ public function testCanMinifySvg() {
250250
$this->assertEquals(trim($minified), $doc->html(), 'Can minify SVGs');
251251
}
252252
}
253+
254+
public function testCanMinifyCssAndJs() {
255+
256+
// this basic test is to test that the HTMLdoc object can invoke the minifiers, not how good the minifiers themselves are
257+
// There are tests within the minifiers' respective projects for that
258+
$doc = new htmldoc();
259+
$input = '
260+
<style type="text/css">
261+
.test {
262+
display: block;
263+
font-weight: bold;
264+
}
265+
</style>
266+
<script type="text/javascript" async="async">
267+
(function () {
268+
console.log("Test");
269+
}());
270+
</script>
271+
';
272+
$output = '<style>.test{display:block;font-weight:700}</style><script async>(function(){console.log("Test")}())</script>';
273+
$doc->load($input);
274+
$this->assertEquals($input, $doc->html(), 'Can load CSS and Javascript');
275+
276+
// minify the code
277+
$doc->minify();
278+
$this->assertEquals($output, $doc->html(), 'Can minify CSS and Javascript');
279+
280+
// minify and cache
281+
$doc = new htmldoc([
282+
'custom' => [
283+
'style' => [
284+
'cache' => __DIR__.'/cache/%s.css'
285+
],
286+
'script' => [
287+
'cache' => __DIR__.'/cache/%s.js'
288+
]
289+
]
290+
]);
291+
$doc->load($input);
292+
$doc->minify();
293+
$this->assertEquals($output, $doc->html(), 'Can minify and cache CSS and Javascript');
294+
295+
// do it again to pull from cache
296+
$doc->load($input);
297+
$doc->minify();
298+
$this->assertEquals($output, $doc->html(), 'Can load minified CSS and Javascript from cache');
299+
}
253300
}

0 commit comments

Comments
 (0)