protected function CustomFilterTest::rulesFilteringTest in Custom filter 2.0.x
Test if node content is replaced by our rules.
1 call to CustomFilterTest::rulesFilteringTest()
- CustomFilterTest::testModule in tests/
src/ Functional/ CustomFilterTest.php - Run all the tests.
File
- tests/
src/ Functional/ CustomFilterTest.php, line 214
Class
- CustomFilterTest
- Test the Custom Filter administration and use.
Namespace
Drupal\Tests\customfilter\FunctionalCode
protected function rulesFilteringTest() {
// Test node replacement.
$this
->drupalGet('node/1');
$this
->assertSession()
->responseContains('Drupal <b>Goodbye <font color="red">Drupal</font> 7</b>');
$this
->assertSession()
->responseContains('<time>');
$time = $this
->xpath('//time');
$this
->assertCount(1, $time);
$time = $time[0]
->getText();
$this
->assertNotNull($time);
// Reloading node should not change time since filter is cached.
sleep(1);
$this
->drupalGet('node/1');
$newtime = $this
->xpath('//time')[0]
->getText();
$this
->assertSame($time, $newtime);
// Change filter caching and rule.
CustomFilter::load('test_filter')
->set('cache', FALSE)
->updateRule([
'rid' => 'test_subrule',
'replacement' => '<font color="orange">Drupal</font>',
])
->save();
// Rule has changed so node should have too.
sleep(1);
$this
->drupalGet('node/1');
$this
->assertSession()
->responseContains('Drupal <b>Goodbye <font color="orange">Drupal</font> 7</b>');
$this
->assertSession()
->responseContains('<time>');
$time = $this
->xpath('//time')[0]
->getText();
$this
->assertNotNull($time);
// Reloading node should not change time since filter is no more cached.
sleep(1);
$this
->drupalGet('node/1');
$newtime = $this
->xpath('//time')[0]
->getText();
$this
->assertNotSame($time, $newtime);
}