diff --git a/assets/src/block-validation/components/higher-order/with-validation-error-notice/edit.css b/assets/src/block-validation/components/higher-order/with-validation-error-notice/edit.css index e913f8b8855..798264e4bd6 100644 --- a/assets/src/block-validation/components/higher-order/with-validation-error-notice/edit.css +++ b/assets/src/block-validation/components/higher-order/with-validation-error-notice/edit.css @@ -1,4 +1,5 @@ -.amp-block-validation-errors { +.amp-block-validation-errors, +.amp-block-validation-errors * { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; font-size: 13px; line-height: 1.5; diff --git a/assets/src/block-validation/components/validation-error-message/index.js b/assets/src/block-validation/components/validation-error-message/index.js index 86800c6989d..25bfe7e6ae8 100644 --- a/assets/src/block-validation/components/validation-error-message/index.js +++ b/assets/src/block-validation/components/validation-error-message/index.js @@ -7,42 +7,25 @@ import { ReactElement } from 'react'; /** * WordPress dependencies */ -import { __, sprintf } from '@wordpress/i18n'; +import { __ } from '@wordpress/i18n'; /** * Get message for validation error. * - * @param {Object} props Component props. + * @param {Object} props Component props. + * @param {?string} props.title Title for error (with HTML) as provided by \AMP_Validation_Error_Taxonomy::get_error_title_from_code(). * @param {?string} props.code Error code. - * @param {?string} props.node_name Node name. - * @param {?string} props.parent_name Parent node name. * @param {?string|ReactElement} props.message Error message. * * @return {ReactElement} Validation error message. */ -const ValidationErrorMessage = ( { message, code, node_name: nodeName, parent_name: parentName } ) => { +const ValidationErrorMessage = ( { title, message, code } ) => { if ( message ) { - return message; + return message; // @todo It doesn't appear this is ever set? } - if ( 'DISALLOWED_TAG' === code && nodeName ) { // @todo Needs to be fleshed out. - return ( - <> - { __( 'Invalid element: ', 'amp' ) } - - { nodeName } - - - ); - } else if ( 'DISALLOWED_ATTR' === code && nodeName ) { // @todo Needs to be fleshed out. - return ( - <> - { __( 'Invalid attribute: ', 'amp' ) } - - { parentName ? sprintf( '%s[%s]', parentName, nodeName ) : nodeName } - - - ); + if ( title ) { + return } return ( @@ -57,9 +40,8 @@ const ValidationErrorMessage = ( { message, code, node_name: nodeName, parent_na ValidationErrorMessage.propTypes = { message: PropTypes.string, + title: PropTypes.string, code: PropTypes.string, - node_name: PropTypes.string, - parent_name: PropTypes.string, }; export default ValidationErrorMessage; diff --git a/assets/src/block-validation/components/validation-error-message/test/__snapshots__/index.js.snap b/assets/src/block-validation/components/validation-error-message/test/__snapshots__/index.js.snap index c017314c04f..b863e11570b 100644 --- a/assets/src/block-validation/components/validation-error-message/test/__snapshots__/index.js.snap +++ b/assets/src/block-validation/components/validation-error-message/test/__snapshots__/index.js.snap @@ -9,31 +9,13 @@ Array [ ] `; -exports[`ValidationErrorMessage renders an error for an invalid attribute 1`] = ` -Array [ - "Invalid attribute: ", - - bar - , -] -`; - -exports[`ValidationErrorMessage renders an error for an invalid attribute with parent node 1`] = ` -Array [ - "Invalid attribute: ", +exports[`ValidationErrorMessage renders an error with a title 1`] = ` + + Invalid attribute - baz[bar] - , -] -`; - -exports[`ValidationErrorMessage renders an error for an invalid element 1`] = ` -Array [ - "Invalid element: ", - - foo - , -] + onclick + + `; exports[`ValidationErrorMessage renders an error for an unknown error code 1`] = ` diff --git a/assets/src/block-validation/components/validation-error-message/test/index.js b/assets/src/block-validation/components/validation-error-message/test/index.js index 0b94167c40c..db90e62fbba 100644 --- a/assets/src/block-validation/components/validation-error-message/test/index.js +++ b/assets/src/block-validation/components/validation-error-message/test/index.js @@ -14,18 +14,8 @@ describe( 'ValidationErrorMessage', () => { expect( errorMessage ).toMatchSnapshot(); } ); - it( 'renders an error for an invalid element', () => { - const errorMessage = render( ); - expect( errorMessage ).toMatchSnapshot(); - } ); - - it( 'renders an error for an invalid attribute', () => { - const errorMessage = render( ); - expect( errorMessage ).toMatchSnapshot(); - } ); - - it( 'renders an error for an invalid attribute with parent node', () => { - const errorMessage = render( ); + it( 'renders an error with a title', () => { + const errorMessage = render( ); expect( errorMessage ).toMatchSnapshot(); } ); diff --git a/assets/src/block-validation/helpers/index.js b/assets/src/block-validation/helpers/index.js index d04725d8ac2..0777a988765 100644 --- a/assets/src/block-validation/helpers/index.js +++ b/assets/src/block-validation/helpers/index.js @@ -71,6 +71,7 @@ export const updateValidationErrors = () => { /** * @param {Object} result Validation error result. * @param {Object} result.error Error object. + * @param {string} result.title Error title. * @param {boolean} result.forced Whether sanitization was forced. * @param {boolean} result.sanitized Whether the error has been sanitized or not. * @param {number} result.status Validation error status. @@ -78,7 +79,7 @@ export const updateValidationErrors = () => { */ const validationErrors = ampValidity.results.filter( ( result ) => { return result.term_status !== VALIDATION_ERROR_ACK_ACCEPTED_STATUS; // If not accepted by the user. - } ).map( ( { error, status } ) => ( { ...error, status } ) ); // Merge status into error since needed in maybeDisplayNotice. + } ).map( ( { error, status, title } ) => ( { ...error, status, title } ) ); // Merge status into error since needed in maybeDisplayNotice. if ( isEqual( validationErrors, previousValidationErrors ) ) { return; diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index 8fbcd1920c5..77cb2ca77b4 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -814,6 +814,7 @@ public static function get_amp_validity_rest_field( $post_data, $field_name, $re foreach ( AMP_Validated_URL_Post_Type::get_invalid_url_validation_errors( $validation_status_post ) as $result ) { $field['results'][] = [ 'sanitized' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $result['status'], + 'title' => AMP_Validation_Error_Taxonomy::get_error_title_from_code( $result['data'] ), 'error' => $result['data'], 'status' => $result['status'], 'term_status' => $result['term_status'], diff --git a/tests/php/test-amp-facebook-embed.php b/tests/php/test-amp-facebook-embed.php index 339be7d6c47..c8a93aa779b 100644 --- a/tests/php/test-amp-facebook-embed.php +++ b/tests/php/test-amp-facebook-embed.php @@ -77,11 +77,7 @@ public function get_raw_embed_dataset() { 'https://www.facebook.com/zuck/posts/10102593740125791' . PHP_EOL, ' -
-

February 4 is Facebook’s 12th birthday!

-

Our anniversary has a lot of meaning to me as an opportunity to reflect on how…

-

Posted by Mark Zuckerberg on Tuesday, January 12, 2016

-
+
' . PHP_EOL, ], @@ -90,9 +86,7 @@ public function get_raw_embed_dataset() { 'https://www.facebook.com/notes/facebook-engineering/under-the-hood-the-javascript-sdk-truly-asynchronous-loading/10151176218703920/' . PHP_EOL, ' -
-

Posted by Facebook Engineering on Saturday, December 8, 2012

-
+
' . PHP_EOL, ], @@ -101,10 +95,7 @@ public function get_raw_embed_dataset() { 'https://www.facebook.com/photo.php?fbid=10102533316889441&set=a.529237706231.2034669.4&type=3&theater' . PHP_EOL, ' -
-

Meanwhile, Beast turned to the dark side.

-

Posted by Mark Zuckerberg on Friday, December 18, 2015

-
+
' . PHP_EOL, ], @@ -113,19 +104,7 @@ public function get_raw_embed_dataset() { 'https://www.facebook.com/zuck/videos/10102509264909801/' . PHP_EOL, ' -
-

-

I want to share a few more thoughts on the Chan Zuckerberg Initiative before I just start posting photos of me and Max for a while 🙂

-

I hope one idea comes through: that we as a society should make investments now to ensure this world is much better for the next generation.

-

I don\'t think we do enough of this right now.

-

Sure, there are many areas where investment now will solve problems for today and also improve the world for the future. We do muster the will to solve some of those.

-

But for the problems that will truly take decades of investment before we see any major return, we are dramatically underinvested.

-

One example is basic science research to cure disease. Another is developing clean energy to protect the world for the future. Another is the slow and steady improvement to modernize schools. Others are systematic issues around poverty and justice. There is a long list of these opportunities.

-

The role of philanthropy is to invest in important areas that companies and governments aren\'t funding — either because they may not be profitable for companies or because they are too long term for people to want to invest now.

-

In the case of disease, basic research often needs to be funded before biotech or pharma companies can create drugs to help people. If we invest more in science, we can make faster progress towards curing disease.

-

Our investment in the Chan Zuckerberg Initiative is small compared to what the world can invest in solving these great challenges. My hope is that our work inspires more people to invest in these longer term issues. If we can do that, then we can all really make a difference together.

-

Posted by Mark Zuckerberg on Friday, December 4, 2015

-
+
' . PHP_EOL, ], @@ -138,16 +117,12 @@ public function get_raw_embed_dataset() { 'post_with_fallbacks' => [ '
-
- Posted by Facebook on Thursday, August 27, 2015 -
+
', ' -
-

Posted by Facebook on Thursday, August 27, 2015

-
+
', ], @@ -161,16 +136,14 @@ public function get_raw_embed_dataset() { '
-
Like Us
+
', '
-
-

Like Us

-
+
', @@ -257,6 +230,9 @@ public function test__raw_embed_sanitizer( $source, $expected ) { $content = AMP_DOM_Utils::get_content_from_dom( $dom ); + // Normalize blockquote contents to account for editing of published posts or variability of localized datetime strings. + $content = preg_replace( '#().+?()#s', '$1$2', $content ); + $this->assertEqualMarkup( $expected, $content ); } diff --git a/tests/php/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php index a1b61610ba7..99e9804390f 100644 --- a/tests/php/validation/test-class-amp-validation-manager.php +++ b/tests/php/validation/test-class-amp-validation-manager.php @@ -604,6 +604,7 @@ public function test_get_amp_validity_rest_field() { static function ( $error ) { return [ 'sanitized' => false, + 'title' => 'Unknown error (test)', 'error' => $error, 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS,