Comments (7)
I agree. We should definitely have tests. Thanks for creating the ticket I was planning to create :-)
cc: @sirkitree
from amp-library.
(BTW we probably won't have CI for now though)
from amp-library.
Need to have a discussion with @sirkitree if we need to do this in Phase 1 or we can park this for a Phase 2.
from amp-library.
This does not need to be done for phase 1, but would be a good candidate for phase 2 of the project.
from amp-library.
Parking this ticket for now. No work will be done on this for Phase 1.
from amp-library.
General Plan
- Use
phpunit
- All tests will be in the GIT_ROOT/tests directory
- Separate fragment and full html tests
- Use html for tests from https://github.com/ampproject/amphtml/tree/master/validator/testdata/feature_tests
The scope of this ticket would be to setup a few basic tests and generally get this working. We'll need to keep adding tests as we go along.
from amp-library.
Basic testing structure is in place with 2 tests. This was probably the most important part. Now all we need to do is keep adding more tests along with expected output.
- The testing code automatically picks up html fragments and whole documents for testing placed in
tests/test-data/full-html
andtests/test-data/fragment-html
folders - Currently there is one full html document test and one fragment test. The expected output is stored with a suffix of
.out
e.g.several_errors.html.out
Here is an example of what happens when a test fails
(Note: None are failing currently. This is an artificial example -- a test has been made to fail by changing the input html slightly)
$ vendor/bin/phpunit tests
PHPUnit 5.3.2 by Sebastian Bergmann and contributors.
F. 2 / 2 (100%)
Time: 1.16 seconds, Memory: 14.00Mb
There was 1 failure:
1) AmpTest::testFiles with data set "tests/test-data/fragment-html/sample-html-fragment.html" ('tests/test-data/fragment-html...t.html', false)
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
---------------
-Line 1: <p><a style="color: red;" href="javascript:run();">Run</a></p>
+Line 1: <p><a great-style="color: red;" href="javascript:run();">Run</a></p>
@@ @@
-<a style="color: red;" href="javascript:run();"> on line 1
-- The attribute 'style' may not appear in tag 'a'.
+<a great-style="color: red;" href="javascript:run();"> on line 1
+- The attribute 'great-style' may not appear in tag 'a'.
[code: DISALLOWED_ATTR category: DISALLOWED_HTML]
- ACTION TAKEN: a.style attribute was removed due to validation issues.
+ ACTION TAKEN: a.great-style attribute was removed due to validation issues.
- Invalid URL protocol 'javascript:' for attribute 'href' in tag 'a'.
[code: INVALID_URL_PROTOCOL category: DISALLOWED_HTML]
ACTION TAKEN: a.href attribute was removed due to validation issues.
<a style="margin: 2px;" href="http://www.cnn.com" target="_parent"> on line 2
- The attribute 'style' may not appear in tag 'a'.
[code: DISALLOWED_ATTR category: DISALLOWED_HTML]
ACTION TAKEN: a.style attribute was removed due to validation issues.
- The attribute 'target' in tag 'a' is set to the invalid value '_parent'.
[code: INVALID_ATTR_VALUE category: DISALLOWED_HTML]
ACTION TAKEN: a.target attribute was removed due to validation issues.
<input type="submit" value="submit"> on line 5
- The tag 'input' is disallowed.
[code: DISALLOWED_TAG category: DISALLOWED_HTML]
ACTION TAKEN: input tag was removed due to validation issues.
<div onmouseover="hello();"> on line 6
- The attribute 'onmouseover' may not appear in tag 'div'.
[code: DISALLOWED_ATTR category: DISALLOWED_HTML]
ACTION TAKEN: div.onmouseover attribute was removed due to validation issues.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"> on line 8
- The tag 'script' is disallowed except in specific forms.
[code: GENERAL_DISALLOWED_TAG category: GENERIC]
ACTION TAKEN: script tag was removed due to validation issues.
<style> on line 9
- The mandatory attribute 'amp-custom' is missing in tag 'style amp-custom'.
[code: MANDATORY_ATTR_MISSING category: DISALLOWED_HTML see: https://www.ampproject.org/docs/reference/spec.html#stylesheets]
- The parent tag of tag 'style' is 'body', but it can only be 'head'.
[code: WRONG_PARENT_TAG category: DISALLOWED_HTML see: https://www.ampproject.org/docs/reference/spec.html#stylesheets]
ACTION TAKEN: style tag was removed due to validation issues.
COMPONENT NAMES WITH JS PATH
------------------------------
'amp-iframe', include path 'https://cdn.ampproject.org/v0/amp-iframe-0.1.js'
'
tests/AmpTest.php:45
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
from amp-library.
Related Issues (20)
- standard amp-selector is being removed HOT 1
- TwitterTransformPass | Invalid HTML cause fatal error HOT 2
- is this repo dead? HOT 2
- inline style removed from div block HOT 3
- Not Work Tag <picture> HOT 1
- Error "The script tag for amp-user-notification is likely included twice in the page". Circular dependency in validator-generated.php
- Support for new masterminds/html5 v2.7.0
- Inline css for table is removed
- support of PHP 7.4
- Convert from Instagram TV post HOT 1
- DISALLOWED_TAG on amp-google-document-embed HOT 2
- Signed exchange issues
- Laravel 8 support
- Set data-locale for FacebookNonIframeTransformPass
- Local image URL detection loses query arguments
- <amp-accordion> should allow expand-single-section attribute.
- After converting to amp html, amp-script component is discarded from the template
- Not working with php8.1.5 HOT 2
- Rename `master` branch to `main`
- Deprecated: Using ${var} in strings is deprecated, use {$var} instead with PHP 8.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amp-library.