I am trying to create a test case against a patch which will be used for automated testing in D8 release.
However, I am trying to do it to check if the page I am on it, has any multiple escaped HTML element. The page where I am trying is following,
<table class="responsive-enabled">
<thead>
<tr>
<th>Uninstall</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="center">
<div class="form-item form-type-checkbox form-item-uninstall-block form-disabled form-no-label">
<label class="visually-hidden" for="edit-uninstall-block">Uninstall Block module</label>
<input disabled="disabled" type="checkbox" id="edit-uninstall-block" name="uninstall[block]" value="1" class="form-checkbox" />
</div>
</td>
<td><label for="edit-uninstall-block" class="module-name table-filter-text-source">Block</label></td>
<td class="description">Controls the visual building blocks a page is constructed with. Blocks are boxes of content rendered into an area, or region, of a web page.<div class="admin-requirements">To uninstall Block, the following module must be uninstalled first: Custom Block</div></td>
</tr>
<tr class="even">
<td align="center">
<div class="form-item form-type-checkbox form-item-uninstall-breakpoint form-disabled form-no-label">
<label class="visually-hidden" for="edit-uninstall-breakpoint">Uninstall Breakpoint module</label>
<input disabled="disabled" type="checkbox" id="edit-uninstall-breakpoint" name="uninstall[breakpoint]" value="1" class="form-checkbox" />
</div>
</td>
<td><label for="edit-uninstall-breakpoint" class="module-name table-filter-text-source">Breakpoint</label></td>
<td class="description">Manage breakpoints and breakpoint groups for responsive designs.<div class="admin-requirements">To uninstall Breakpoint, the following module must be uninstalled first: Toolbar</div></td>
</tr>
<tr class="odd">
<td align="center">
<div class="form-item form-type-checkbox form-item-uninstall-ckeditor form-no-label">
<label class="visually-hidden" for="edit-uninstall-ckeditor">Uninstall CKEditor module</label>
<input type="checkbox" id="edit-uninstall-ckeditor" name="uninstall[ckeditor]" value="1" class="form-checkbox" />
</div>
</td>
<td><label for="edit-uninstall-ckeditor" class="module-name table-filter-text-source">CKEditor</label></td>
<td class="description">WYSIWYG editing for rich text fields using CKEditor.</td>
</tr>
<tr class="even">
<td align="center">
<div class="form-item form-type-checkbox form-item-uninstall-color form-no-label">
<label class="visually-hidden" for="edit-uninstall-color">Uninstall Color module</label>
<input type="checkbox" id="edit-uninstall-color" name="uninstall[color]" value="1" class="form-checkbox" />
</div>
</td>
<td><label for="edit-uninstall-color" class="module-name table-filter-text-source">Color</label></td>
<td class="description">Allows administrators to change the color scheme of compatible themes.</td>
</tr>
</tbody>
</table>
From the code you can understand that it's the module's uninstall page. So in the RAW HTML we can see it has the double escaped HTML elements. Like <
became <
.
The test file I am writing is the following,
<?php
/**
* @file
* Definition of Drupal\system\Tests\Module\UninstallPageLoad.
*/
namespace Drupal\system\Tests\Module;
use Drupal\Component\Utility\String;
use Drupal\simpletest\WebTestBase;
/**
* Tests the module uninstall page load for multiple HTML escaping.
*
* @group Module
*/
class UninstallPageLoad extends WebTestBase {
/**
* Loads module uninstall page and checks HTML escaping
*/
function testUninstallPageHtmlEscape() {
// Create new admin user and test page load.
$account = $this->drupalCreateUser(array('administer modules'));
$this->drupalLogin($account);
$this->drupalGet('admin/modules/uninstall');
$this->assertResponse(200, 'Module Uninstall page loaded.');
// Test the page if it has multiple HTML sanitizations.
$this->assertNoRaw('<label', 'Page should not have htmlentities');
}
}
While executing the file I think I should get a failed result as the page do have many double escaped HTML characters. But I am getting a success.
EDIT: After Core debug
I think now I know the reason why this fails,
When I added a debug code in core/modules/simpletest/src/AssertContentTrait.php
in the method assertNoRaw
it gave me the following RAW HTML.
<table class="responsive-enabled">
<thead>
<tr>
<th>Uninstall</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td colspan="3" class="empty message">No modules are available to uninstall.</td>
</tr>
</tbody>
</table>
So no modules are loading in this page. So now the question is how to replicate the page output same as theme_system_modules_uninstall
from core/modules/system/system.admin.inc, line 290
page.
Can any one help me with this?
assertNoRaw()
uses a basicstrpos()
...I just ranstrpos($your_html_string, '<label');
and got the correct result of 599. I would check what$this->getRawContent()
contains (which is whatassertNoRaw()
checks the test string against), it sounds like that value is not actually the HTML code in your question