diff --git a/docroot/modules/custom/nci_ckeditor5_cleanup/nci_ckeditor5_cleanup.module b/docroot/modules/custom/nci_ckeditor5_cleanup/nci_ckeditor5_cleanup.module
index 3ce13be931..3e969ce292 100644
--- a/docroot/modules/custom/nci_ckeditor5_cleanup/nci_ckeditor5_cleanup.module
+++ b/docroot/modules/custom/nci_ckeditor5_cleanup/nci_ckeditor5_cleanup.module
@@ -160,7 +160,7 @@ function _nci_ckeditor5_cleanup_constrain_wysiwyg_styles(array &$format_settings
'styles' => [
'background-color', 'border', 'border-color', 'border-style',
'border-width', 'height', 'padding', 'text-align', 'vertical-align',
- 'width',
+ 'width', 'white-space',
],
];
}
diff --git a/docroot/modules/custom/ncids_html_transformer/ncids_html_transformer.services.yml b/docroot/modules/custom/ncids_html_transformer/ncids_html_transformer.services.yml
index 992d3a4cb7..b86399eac3 100644
--- a/docroot/modules/custom/ncids_html_transformer/ncids_html_transformer.services.yml
+++ b/docroot/modules/custom/ncids_html_transformer/ncids_html_transformer.services.yml
@@ -31,15 +31,15 @@ services:
## These transformers set data-html-transform attributes, so none of the disallow
## transformers will run until after these have run. However, they *can* pass
## child html to the transformer manager to have it transformed as well.
+ ncids_html_transformer.table_transformer:
+ class: Drupal\ncids_html_transformer\Services\NcidsTableTransformer
+ tags:
+ - { name: ncids_html_transformer.ncids_html_transform, priority: 290 }
ncids_html_transformer.callout_box_transformer:
class: Drupal\ncids_html_transformer\Services\NcidsCalloutBoxTransformer
arguments: ['@ncids_html_transformer.html_transformer_manager']
tags:
- { name: ncids_html_transformer.ncids_html_transform, priority: 280 }
- ncids_html_transformer.table_transformer:
- class: Drupal\ncids_html_transformer\Services\NcidsTableTransformer
- tags:
- - { name: ncids_html_transformer.ncids_html_transform, priority: 270 }
ncids_html_transformer.pullquote_transformer:
class: Drupal\ncids_html_transformer\Services\NcidsPullquoteTransformer
arguments: ['@ncids_html_transformer.html_transformer_manager']
diff --git a/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedAttributesTransformer.php b/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedAttributesTransformer.php
index 13bf8f10d0..5c2a59ddb8 100644
--- a/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedAttributesTransformer.php
+++ b/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedAttributesTransformer.php
@@ -52,6 +52,20 @@ class NcidsDisallowedAttributesTransformer extends NcidsHtmlTransformerBase {
'script' => ['src', 'type'],
'time' => ['datetime'],
'img' => ['alt', 'src', 'srcset', 'height', 'width', 'loading', 'name'],
+ 'table' => ['data-sortable'],
+ 'th' => [
+ 'data-fixed',
+ 'data-sortable',
+ 'scope',
+ 'role',
+ 'aria-sort',
+ 'aria-label',
+ 'data-sortable-type',
+ 'colspan',
+ 'rowspan',
+ ],
+ 'tr' => [],
+ 'td' => ['data-sort-active', 'colspan', 'rowspan'],
];
/**
@@ -59,7 +73,7 @@ class NcidsDisallowedAttributesTransformer extends NcidsHtmlTransformerBase {
*
* @var array
*/
- protected array $skipElements = ['td', 'th', 'tr', 'table'];
+ protected array $skipElements = [];
/**
* {@inheritdoc}
@@ -116,7 +130,7 @@ protected function processElementAttributes(\DOMElement $element): void {
}
/* All elements are allowed to contain id and class */
- $allowedForElement = ['id', 'class'];
+ $allowedForElement = ['id', 'class', 'style'];
/* Add element-specific allowed attributes */
if (isset($this->allowedAttributes[$tagName])) {
@@ -128,6 +142,13 @@ protected function processElementAttributes(\DOMElement $element): void {
if (!in_array($attributeName, $allowedForElement)) {
$element->removeAttribute($attributeName);
}
+ elseif (
+ $attributeName === 'style' &&
+ empty(trim($element->getAttribute('style')))
+ ) {
+ // Remove empty style attributes.
+ $element->removeAttribute('style');
+ }
}
}
diff --git a/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedClassesTransformer.php b/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedClassesTransformer.php
index 13e8b217bf..0ef0ba78b1 100644
--- a/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedClassesTransformer.php
+++ b/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedClassesTransformer.php
@@ -66,6 +66,7 @@ class NcidsDisallowedClassesTransformer extends NcidsHtmlTransformerBase {
['usa-button--secondary'],
['usa-summary-box__link'],
],
+ 'table' => [['usa-table']],
];
/**
diff --git a/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedStylesTransformer.php b/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedStylesTransformer.php
index 0f0fa703b8..6c49d0354f 100644
--- a/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedStylesTransformer.php
+++ b/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsDisallowedStylesTransformer.php
@@ -27,6 +27,7 @@ class NcidsDisallowedStylesTransformer extends NcidsHtmlTransformerBase {
'text-align',
'vertical-align',
'width',
+ 'white-space',
];
/**
@@ -84,6 +85,11 @@ protected function processTableStyles(\DOMElement $element): void {
foreach ($styles as $property => $value) {
if (in_array($property, $this->allowedTableStyles)) {
+ // Check for percentage width values and do not include them.
+ if ($property === 'width' && $value === '100%') {
+ // It's a valid percentage width of 100%; skip adding it.
+ continue;
+ }
$cleanedStyles[$property] = $value;
}
}
diff --git a/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsTableTransformer.php b/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsTableTransformer.php
index 1be06c402f..acb6466394 100644
--- a/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsTableTransformer.php
+++ b/docroot/modules/custom/ncids_html_transformer/src/Services/NcidsTableTransformer.php
@@ -2,6 +2,8 @@
namespace Drupal\ncids_html_transformer\Services;
+use Drupal\Component\Utility\Html;
+
/**
* Transformer for tables.
*/
@@ -9,9 +11,185 @@ class NcidsTableTransformer extends NcidsHtmlTransformerBase {
/**
* {@inheritdoc}
+ *
+ * This includes table attributes that are removed.
+ * Includes random attributes we've found on tables during page inventory.
+ * (s, td, bb, etc are not valid attributes on anything...)
+ */
+ protected static $ignoreAttributes = [
+ 'data-sorted',
+ 'data-sort-value',
+ 'cellspacing',
+ 'title',
+ 'bb',
+ 'headers',
+ 's',
+ 'td',
+ ];
+
+ /**
+ * {@inheritdoc}
+ *
+ * Attributes to convert to styles on table elements.
*/
- protected static $preprocessElements = [
- 'table',
+ protected static $attributesToConvertToStyles = [
+ 'width',
+ 'height',
+ 'border',
+ 'border-style',
+ 'border-color',
+ 'border-width',
+ 'text-align',
+ 'vertical-align',
+ 'background-color',
+ 'padding',
];
+ /**
+ * {@inheritdoc}
+ *
+ * Get all table elements for processing.
+ */
+ private function getAllTableElementsForCheck(\DOMElement $table): array {
+ // Build a list of elements to process: the table itself plus
+ // any descendant table, tr, th, and td elements.
+ $elements = [$table];
+ foreach (['table', 'tr', 'th', 'td'] as $tag) {
+ $nodeList = $table->getElementsByTagName($tag);
+ foreach ($nodeList as $node) {
+ if ($node instanceof \DOMElement) {
+ $elements[] = $node;
+ }
+ }
+ }
+ return $elements;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Convert designated attributes to inline styles.
+ */
+ private function convertAttributesToStyles(\DOMElement $el): \DOMElement {
+ foreach (self::$attributesToConvertToStyles as $attribute) {
+ // If the attribute exists on the element, convert it to a style.
+ if ($el->hasAttribute($attribute)) {
+ $style_value = $el->getAttribute($attribute);
+ $existing_style = $el->getAttribute('style');
+ $new_style = $existing_style ? rtrim($existing_style, ';') . '; ' : '';
+ if ($attribute === 'border') {
+ if (is_numeric($style_value)) {
+ if (intval($style_value) > 0) {
+ $new_style .= 'border: ' . $style_value . 'px solid black;';
+ }
+ }
+ else {
+ $new_style .= 'border: ' . $style_value . ';';
+ }
+ }
+ else {
+ $new_style .= $attribute . ': ' . $style_value . ';';
+ }
+ if (!empty($new_style)) {
+ $el->setAttribute('style', $new_style);
+ }
+ $el->removeAttribute($attribute);
+ }
+ }
+ return $el;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Handle sortable attributes and update them appropriately.
+ */
+ private function removeIgnoreAttributes(\DOMElement $el): \DOMElement {
+ foreach ($el->attributes as $attr) {
+ /** @var \DOMAttr $attr */
+ if (in_array($attr->name, self::$ignoreAttributes)) {
+ // If the attribute is a table header, convert to aria-sort.
+ // This handles if the table is pre-sorted. (not sure if any are...)
+ if ($el->tagName === 'th' && $attr->name === 'data-sorted') {
+ $sort_value = $el->getAttribute('data-sorted');
+ $aria_sort_value = 'none';
+ if ($sort_value === 'up') {
+ $aria_sort_value = 'ascending';
+ }
+ elseif ($sort_value === 'down') {
+ $aria_sort_value = 'descending';
+ }
+ $el->setAttribute('aria-sort', $aria_sort_value);
+ }
+ // If the attribute is a table cell, convert to data-sort-active.
+ elseif ($el->tagName === 'td' && $attr->name === 'data-sorted') {
+ $is_sorted = $el->getAttribute('data-sorted');
+ if ($is_sorted === 'true') {
+ // Add data-sort-active attribute to indicate active sorted column.
+ $el->setAttribute('data-sort-active', '');
+ }
+ }
+ // Remove invalid sortable attributes.
+ $el->removeAttribute($attr->name);
+ }
+ }
+ return $el;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Transform the HTML attributes.
+ */
+ private function handleAllAttributes(array $elements): void {
+ // For each element, convert any of the configured attributes
+ // to inline styles and retain any data-sortable attribute.
+ // Remove other attributes.
+ foreach ($elements as $el) {
+ /** @var \DOMElement $el */
+ $el = $this->convertAttributesToStyles($el);
+ $this->removeIgnoreAttributes($el);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * Transform the HTML.
+ */
+ public function transform(string $html): string {
+ if (empty(trim($html))) {
+ return $html;
+ }
+
+ $dom = Html::load($html);
+ $xpath = new \DOMXpath($dom);
+
+ // Find all tables.
+ $all_tables = $xpath->query("//table");
+ $elements_to_check = [];
+
+ foreach ($all_tables as $table) {
+ /** @var \DOMElement $table */
+ // Check if the table is sortable.
+ if ($table->hasAttribute('data-sortable')) {
+ // Add the usa-table class if not already present
+ // for sortable table logic. (Javascript looks for this class.)
+ $table->setAttribute('class', 'usa-table');
+ }
+ // If the table isn't sortable, it should not have any classes.
+ else {
+ $table->removeAttribute('class');
+ }
+
+ // Build a list of elements to process: the table itself plus
+ // any descendant table, tr, th, and td elements.
+ $elements_to_check = array_merge($elements_to_check, $this->getAllTableElementsForCheck($table));
+ }
+
+ $this->handleAllAttributes($elements_to_check);
+
+ return Html::serialize($dom);
+ }
+
}
diff --git a/docroot/modules/custom/ncids_html_transformer/tests/src/Kernel/NcidsTableTransformerKernelTest.php b/docroot/modules/custom/ncids_html_transformer/tests/src/Kernel/NcidsTableTransformerKernelTest.php
index 55efc6227e..be6307dc48 100644
--- a/docroot/modules/custom/ncids_html_transformer/tests/src/Kernel/NcidsTableTransformerKernelTest.php
+++ b/docroot/modules/custom/ncids_html_transformer/tests/src/Kernel/NcidsTableTransformerKernelTest.php
@@ -27,52 +27,58 @@ class NcidsTableTransformerKernelTest extends NcidsTransformerKernelTestBase {
*/
public function testTransformers(): void {
$this->checkTableWithAllowedStyles();
- $this->checkTableCellAlignment();
- $this->checkComplexNestedStructure();
+ $this->checkTableWithDisallowedClasses();
+ $this->checkNestedTablesForTransformation();
$this->checkTableStyleCompleteRemoval();
$this->checkTableMixedStyles();
}
/**
- * Tests complex table with allowed styles - should NOT be transformed.
+ * Tests basic table with allowed/disallowed styles.
+ *
+ * Should retain allowed styles and remove those disallowed.
*/
public function checkTableWithAllowedStyles(): void {
- $input = '
';
+ $input = '';
$output = $this->transformerManager->transformAll($input);
- $expected = '';
- $this->assertEquals($expected, $output, 'Should add data tag and NOT transform complex-table content');
+ $expected = '';
+ $this->assertEquals($expected, $output, 'Should retain allowed styles and remove those disallowed.');
}
/**
- * Tests table cell alignment classes - should be transformed.
+ * Tests basic table with disallowed classes.
*
- * @Covers::transform
+ * Should remove invalid classes from all table elements/children.
*/
- public function checkTableCellAlignment(): void {
+ public function checkTableWithDisallowedClasses(): void {
$input = '';
$output = $this->transformerManager->transformAll($input);
- $expected = '';
- $this->assertEquals($expected, $output, 'Should skip over table cells but add data tag to table element');
+ $expected = '';
+ $this->assertEquals($expected, $output, 'Should remove invalid classes from all table elements/children.');
}
/**
- * Tests complex nested structure with multiple elements - complex-table.
+ * Tests nested table with multiple table elements.
+ *
+ * Should transform outer elements as well as all tables.
*/
- public function checkComplexNestedStructure(): void {
- $input = '';
+ public function checkNestedTablesForTransformation(): void {
+ $input = '';
$output = $this->transformerManager->transformAll($input);
- $expected = '';
- $this->assertEquals($expected, $output, 'Should transform outer elements but preserve complex-table and its children with data tag');
+ $expected = '';
+ $this->assertEquals($expected, $output, 'Should transform outer elements as well as all tables, included nested tables.');
}
/**
- * Tests complete style removal when table elements have no allowed styles.
+ * Tests complete table transformation of a sortable table.
+ *
+ * Should fully transform the table included disallowed attributes and styles.
*/
public function checkTableStyleCompleteRemoval(): void {
- $input = '';
+ $input = '';
$output = $this->transformerManager->transformAll($input);
- $expected = '';
- $this->assertEquals($expected, $output, 'Should remove style attributes entirely from table elements when no allowed styles are present');
+ $expected = '';
+ $this->assertEquals($expected, $output, 'Should fully transform the table included disallowed attributes and styles.');
}
/**
@@ -81,8 +87,32 @@ public function checkTableStyleCompleteRemoval(): void {
public function checkTableMixedStyles(): void {
$input = '';
$output = $this->transformerManager->transformAll($input);
- $expected = '';
+ $expected = '';
$this->assertEquals($expected, $output, 'Should preserve only allowed styles on table elements and remove disallowed ones');
}
+ /**
+ * Tests removal of width attribute when value is 100%.
+ *
+ * @covers ::transform
+ */
+ public function testTableStyleTransformationWithPercentWidthAttribute(): void {
+ $input = '';
+ $output = $this->transformerManager->transformAll($input);
+ $expected = '';
+ $this->assertEquals($expected, $output, 'Should remove all bad styles from non-table elements and keep only allowed styles on table elements');
+ }
+
+ /**
+ * Tests removal of width style when value is 100%.
+ *
+ * @covers ::transform
+ */
+ public function testTableStyleTransformationWithPercentWidthStyle(): void {
+ $input = '';
+ $output = $this->transformerManager->transformAll($input);
+ $expected = '';
+ $this->assertEquals($expected, $output, 'Should remove all bad styles from non-table elements and keep only allowed styles on table elements');
+ }
+
}
diff --git a/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/NcidsDisallowedStylesTransformerTest.php b/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/NcidsDisallowedStylesTransformerTest.php
index 1fc76b66d4..0b5b9119f3 100644
--- a/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/NcidsDisallowedStylesTransformerTest.php
+++ b/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/NcidsDisallowedStylesTransformerTest.php
@@ -55,16 +55,25 @@ public function testNestedInvalidStylesOtherTransformer(): void {
/**
* Tests style removal from non-table elements and filtering of table styles.
*
- * The table in here is a cheat and will depend on the approach for the
- * NcidsTableTransformer.
- *
* @covers ::transform
*/
public function testStyleTransformation(): void {
$input = '';
$output = $this->transformer->transform($input);
- $expected = '';
+ $expected = '';
$this->assertEquals($expected, $output, 'Should remove all bad styles from non-table elements and keep only allowed styles on table elements');
}
+ /**
+ * Tests removal of width style when value is 100%.
+ *
+ * @covers ::transform
+ */
+ public function testTableStyleTransformationWithPercentWidth(): void {
+ $input = '';
+ $output = $this->transformer->transform($input);
+ $expected = '';
+ $this->assertEquals($expected, $output, 'Should remove invalid styles as well as width style when value is 100%');
+ }
+
}
diff --git a/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/NcidsTableTransformerTest.php b/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/NcidsTableTransformerTest.php
index 4cc7fb2046..aff0e96172 100644
--- a/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/NcidsTableTransformerTest.php
+++ b/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/NcidsTableTransformerTest.php
@@ -29,56 +29,159 @@ protected function setUp(): void {
}
/**
- * Test preProcessHtml method.
+ * Test transformation of very simple tables.
*
- * @covers ::preProcessHtml
+ * @covers ::transform
*/
- public function testPreProcessHtml() {
- $original_html =
- '' .
- '' .
- 'This is not a callout box.
';
+ public function simpleTableTest() {
+ $input = <<
+
+
+
+ HEREDOC;
+ $expected_html = <<
+
+
+
+ HEREDOC;
+
+ // Simulate full transformation process.
+ $transformed = $this->transformer->transform($input);
+
+ $this->assertEquals($expected_html, $transformed, 'Table without data-sortable attribute should not be transformed, while tables with the attribute should be.');
+ }
+
+ /**
+ * Test a simple sortable table transformation.
+ *
+ * @covers ::transform
+ */
+ public function simpleSortableTableTest() {
+ $input =
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
$expected_html =
- '' .
- '' .
- 'This is not a callout box.
';
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
- $processed_html = $this->transformer->preProcessHtml($original_html);
- $this->assertEquals($expected_html, $processed_html);
+ // Simulate full transformation process.
+ $transformed = $this->transformer->transform($input);
+
+ $this->assertEquals($expected_html, $transformed, 'Tables should be transformed and have the usa-table class');
}
/**
- * Test postProcessHtml method.
+ * Test table transformation with attributes to be converted to styles.
+ *
+ * @covers ::transform
+ */
+ public function testConvertTableAttributesToStyles() {
+ $input =
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
+ $expected_html =
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
+
+ // Simulate full transformation process.
+ $transformed = $this->transformer->transform($input);
+
+ $this->assertEquals($expected_html, $transformed, 'Table should be transformed and appropriate attributes converted to styles');
+ }
+
+ /**
+ * Test table transformation with bad attributes to be removed.
+ *
+ * Also tests a table with sortable attributes to update to ncids.
*
* @covers ::postProcessHtml
*/
- public function testPostProcessHtml() {
- $original_html =
- '' .
- '' .
- 'This is not a callout box.
' .
- 'This is not a callout box.
';
+ public function testConvertSortableTableWithBadAttributes() {
+ $input =
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
$expected_html =
- '' .
- '' .
- 'This is not a callout box.
' .
- 'This is not a callout box.
';
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
- $processed_html = $this->transformer->postProcessHtml($original_html);
- $this->assertEquals($expected_html, $processed_html);
+ // Simulate full transformation process.
+ $transformed = $this->transformer->transform($input);
+
+ $this->assertEquals($expected_html, $transformed, 'Table should be transformed and disallowed attributes removed or converted appropriately.');
}
- /* Tests removed from BasicMigrationTransformerTest.php to be implemented.
+ /**
+ * Test table transformation with bad border attribute to be converted.
+ *
+ * Should convert border="1" to style="border: 1px solid black;".
*
- * - Tests complex table with allowed styles - should NOT be transformed.
- * https://github.com/NCIOCPL/cgov-digital-platform/blob/f29676a597f2ed735e87959d8653a10da25a2f5c/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/BasicMigrationTransformerTest.php#L95
- * - Tests table cell alignment classes - should be transformed.
- * https://github.com/NCIOCPL/cgov-digital-platform/blob/f29676a597f2ed735e87959d8653a10da25a2f5c/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/BasicMigrationTransformerTest.php#L167
- * - Tests complex nested structure with multiple elements - complex-table.
- * https://github.com/NCIOCPL/cgov-digital-platform/blob/f29676a597f2ed735e87959d8653a10da25a2f5c/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/BasicMigrationTransformerTest.php#L179
- * - Tests complete style removal when table elements have no allowed styles.
- * https://github.com/NCIOCPL/cgov-digital-platform/blob/f29676a597f2ed735e87959d8653a10da25a2f5c/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/BasicMigrationTransformerTest.php#L223
- * - Tests mixed allowed and disallowed styles on table elements.
- *https://github.com/NCIOCPL/cgov-digital-platform/blob/f29676a597f2ed735e87959d8653a10da25a2f5c/docroot/modules/custom/ncids_html_transformer/tests/src/Unit/BasicMigrationTransformerTest.php#L235
+ * @covers ::transform
*/
+ public function testConvertTableWithBadBorderAttributes1() {
+ $input =
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
+ $expected_html =
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
+
+ // Simulate full transformation process.
+ $transformed = $this->transformer->transform($input);
+
+ $this->assertEquals($expected_html, $transformed, 'Table should be transformed and disallowed attributes removed or converted appropriately.');
+ }
+
+ /**
+ * Test table transformation with bad border attribute to be converted.
+ *
+ * Should remove border="0" since 0 would be no border.
+ *
+ * @covers ::transform
+ */
+ public function testConvertTableWithBadBorderAttributes0() {
+ $input =
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
+ $expected_html =
+ '' .
+ '| Heading1 | Heading2 | HeadingFixed |
' .
+ '| Cell 1-1 | Cell 1-2 | Cell 1-3 |
' .
+ '| Cell 2-1 | Cell 2-2 | Cell 2-3 |
' .
+ '
';
+
+ // Simulate full transformation process.
+ $transformed = $this->transformer->transform($input);
+
+ $this->assertEquals($expected_html, $transformed, 'Table should be transformed and disallowed attributes removed or converted appropriately.');
+ }
+
}
diff --git a/docroot/profiles/custom/cgov_site/themes/custom/ncids_trans/front-end/src/entrypoints/ckeditor/ckeditor-ncids.scss b/docroot/profiles/custom/cgov_site/themes/custom/ncids_trans/front-end/src/entrypoints/ckeditor/ckeditor-ncids.scss
index b314124176..38f1a991fa 100644
--- a/docroot/profiles/custom/cgov_site/themes/custom/ncids_trans/front-end/src/entrypoints/ckeditor/ckeditor-ncids.scss
+++ b/docroot/profiles/custom/cgov_site/themes/custom/ncids_trans/front-end/src/entrypoints/ckeditor/ckeditor-ncids.scss
@@ -42,7 +42,7 @@ uswds-core.$theme-global-link-styles: true;
@forward '../../lib/components/wysiwyg/editors/ncids-full-html';
// Need to override ck editor table styles for sortable tables
-.ck-content--ncids table.usa-table[data-sortable] {
+.ck-content--ncids table[data-sortable] {
th {
background-color: uswds-core.color(
uswds-core.$theme-table-header-background-color