View source
<?php
namespace Drupal\printable\Tests;
use Drupal\Tests\node\Functional\NodeTestBase;
class PrintablePageTest extends NodeTestBase {
public static $modules = [
'printable',
'node_test_exception',
'dblog',
'system',
];
public function setUp() {
parent::setUp();
$web_user = $this
->drupalCreateUser([
'create page content',
'edit own page content',
'view printer friendly versions',
'administer printable',
]);
$this
->drupalLogin($web_user);
}
public function testCustomPageExists() {
global $base_url;
$node_type_storage = \Drupal::entityTypeManager()
->getStorage('node_type');
$node_type_storage
->load('article')
->delete();
$this
->drupalGet('node/add');
$this
->assertResponse(200);
$this
->assertUrl('node/add/page');
$edit = [];
$edit['title[0][value]'] = $this
->randomMachineName(8);
$bodytext = $this
->randomMachineName(16) . 'This is functional test which I am writing for printable module.';
$edit['body[0][value]'] = $bodytext;
$this
->drupalPostForm('node/add/page', $edit, t('Save'));
$this
->assertRaw(t('!post %title has been created.', [
'!post' => 'Basic page',
'%title' => $edit['title[0][value]'],
]), 'Basic page created.');
$node = $this
->drupalGetNodeByTitle($edit['title[0][value]']);
$this
->assertTrue($node, 'Node found in database.');
$this
->drupalGet('node/' . $node
->id());
$this
->assertResponse(200);
$this
->drupalGet('node/' . $node
->id() . '/printable/print');
$this
->assertResponse(200);
$this
->assertRaw($edit['title[0][value]'], 'Title discovered successfully in the printable page');
$this
->assertRaw(theme_get_setting('logo.url'), 'Image discovered successfully in the printable page');
$this
->assertRaw($edit['body[0][value]'], 'Body discovered successfully in the printable page');
$this
->assertRaw($base_url . '/node/' . $node
->id(), 'Source Url discovered in the printable page');
$this
->verbose($base_url);
$this
->drupalGet('admin/config/user-interface/printable/print');
$this
->drupalPostForm(NULL, [
'print_html_display_sys_urllist' => 1,
], t('Submit'));
$this
->drupalGet('node/' . $node
->id() . '/printable/print');
$this
->assertResponse(200);
$this
->drupalGet('node/' . $node
->id() . '/printable/UNDEFINED');
$this
->assertResponse(404);
$this
->assertRaw('List of links present in page', 'Main heading for displaying URLs discovered in the printable page');
$this
->assertRaw($base_url . '/node/' . $node
->id(), 'First link discovered successfully');
$this
->assertRaw('/user/1', 'Second link discovered successfully');
$this
->assertRaw('/node/' . $node
->id() . '/printable/print', 'Third link discovered successfully');
}
}