Skip to content

Commit

Permalink
Updated composer dependencies, which are now pegged to releases rathe…
Browse files Browse the repository at this point in the history
…r 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.
  • Loading branch information
hexydec committed May 22, 2021
1 parent 849b61e commit 22aa019
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 23 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"minimum-stability": "stable",
"require": {
"php": ">=7.3",
"hexydec/tokenise": "@dev",
"hexydec/cssdoc": "@dev",
"hexydec/jslite": "@dev"
"hexydec/tokenise": "0.4.0",
"hexydec/cssdoc": "0.3.0",
"hexydec/jslite": "0.4.0"
},
"autoload": {
"classmap": ["src/"]
Expand Down
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/api/construct.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ $doc = new \hexydec\html\htmldoc($config);
```
## Arguments

### $config
### `$config`

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

#### `elements`

Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
</style>
</head>
<body>
<form action="<?= \htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" accept-charset="<?= \htmlspecialchars(\mb_internal_encoding()); ?>" class="minify__form">
<form action="<?= \htmlspecialchars($_SERVER['REQUEST_URI']); ?>" method="post" accept-charset="<?= \htmlspecialchars(\mb_internal_encoding()); ?>" class="minify__form">
<div class="minify__form-wrap">
<h1 class="minify__form-heading">HTML Minifier</h1>
<?php if ($error) { ?>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "HTMLdoc",
"version": "1.2.1",
"version": "1.2.2",
"description": "A token based HTML Document parser and minifier written in PHP",
"main": "src/htmldoc.php",
"directories": {
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<file>src/autoload.php</file>
</exclude>
<report>
<clover outputFile="./coverage/result.xml"/>
<html outputDirectory="./coverage/result"/>
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if ($doc->open($url) {
The easiest way to get up and running is to use composer:

```
$ composer install
$ composer install hexydec/htmldoc
```

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.
Expand Down
47 changes: 47 additions & 0 deletions tests/minifyHtmldocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,51 @@ public function testCanMinifySvg() {
$this->assertEquals(trim($minified), $doc->html(), 'Can minify SVGs');
}
}

public function testCanMinifyCssAndJs() {

// this basic test is to test that the HTMLdoc object can invoke the minifiers, not how good the minifiers themselves are
// There are tests within the minifiers' respective projects for that
$doc = new htmldoc();
$input = '
<style type="text/css">
.test {
display: block;
font-weight: bold;
}
</style>
<script type="text/javascript" async="async">
(function () {
console.log("Test");
}());
</script>
';
$output = '<style>.test{display:block;font-weight:700}</style><script async>(function(){console.log("Test")}())</script>';
$doc->load($input);
$this->assertEquals($input, $doc->html(), 'Can load CSS and Javascript');

// minify the code
$doc->minify();
$this->assertEquals($output, $doc->html(), 'Can minify CSS and Javascript');

// minify and cache
$doc = new htmldoc([
'custom' => [
'style' => [
'cache' => __DIR__.'/cache/%s.css'
],
'script' => [
'cache' => __DIR__.'/cache/%s.js'
]
]
]);
$doc->load($input);
$doc->minify();
$this->assertEquals($output, $doc->html(), 'Can minify and cache CSS and Javascript');

// do it again to pull from cache
$doc->load($input);
$doc->minify();
$this->assertEquals($output, $doc->html(), 'Can load minified CSS and Javascript from cache');
}
}

0 comments on commit 22aa019

Please sign in to comment.