Add missing validation to component trees being saved into content entities in tests— and simplify `CanvasTestSetup`
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3572847. -->
Reported by: [wim leers](https://www.drupal.org/user/99777)
Related to !583
>>>
<h3 id="overview">Overview</h3>
<p>With <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3563216" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3563216</a></span> and <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3572401" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3572401</a></span> done, we can be confident all component trees stored in config entities are being validated.</p>
<p>However, at <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3561392" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3561392</a></span>, it became clear that this there are exceptions:<br>
<code>CanvasTestSetup</code> creates content entities with component trees without validating them (<span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3531679" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3531679</a></span> will reduce the usage of that, but until then we should still make it valid)<br>
<code>BlockComponentTest:: testGetExplicitInput()</code></p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<p>Add validation to all of these. For example:</p>
<pre>diff --git a/tests/src/Kernel/Plugin/Canvas/ComponentSource/BlockComponentTest.php b/tests/src/Kernel/Plugin/Canvas/ComponentSource/BlockComponentTest.php<br>index 68e94cfce..1287f10e4 100644<br>--- a/tests/src/Kernel/Plugin/Canvas/ComponentSource/BlockComponentTest.php<br>+++ b/tests/src/Kernel/Plugin/Canvas/ComponentSource/BlockComponentTest.php<br>@@ -334,6 +334,7 @@ HTML,<br> 'type' => 'article',<br> 'field_canvas_test' => $componentItemValue,<br> ]);<br>+ self::assertSame([], self::violationsToArray($node->validate()));<br> $node->save();<br> $canvas_field_item = $node->field_canvas_test[0];<br> $this->assertInstanceOf(ComponentTreeItem::class, $canvas_field_item);</pre><h3 id="ui-changes">User interface changes</h3>
<p>None.</p>
issue