View source
<?php
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
class LinkManipulatorTest extends BrowserTestBase {
use TestFillPdfTrait;
public static $modules = [
'fillpdf_test',
];
protected $defaultTheme = 'stark';
protected $linkManipulator;
protected function setUp() {
parent::setUp();
$this
->configureFillPdf();
$this
->initializeUser();
$this->linkManipulator = $this->container
->get('fillpdf.link_manipulator');
}
public function testLinkExceptions() {
$fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], []);
$this
->drupalGet($fillpdf_route);
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->pageTextContains("This link doesn't specify a query string, so failing.");
$fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [
'query' => [
'sample' => 1,
],
]);
$this
->drupalGet($fillpdf_route);
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->pageTextContains("No FillPDF Form was specified in the query string, so failing.");
$fillpdf_route = Url::fromRoute('fillpdf.populate_pdf', [], [
'query' => [
'fid' => 1234,
],
]);
$this
->drupalGet($fillpdf_route);
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->pageTextContains("The requested FillPDF Form doesn't exist, so failing.");
}
public function testSampleLink() {
$this
->uploadTestPdf('fillpdf_test_v3.pdf');
$form_id = $this
->getLatestFillPdfForm();
$query = [
'fid' => $form_id,
'entity_type' => 'user',
'entity_id' => 3,
'entity_ids' => [
'node:1',
'node:2',
],
'sample' => TRUE,
];
$url = Url::fromRoute('fillpdf.populate_pdf', [], [
'query' => $query,
]);
$context = $this->linkManipulator
->parseLink($url);
$this
->assertEquals($form_id, $context['fid']);
$this
->assertEquals(TRUE, $context['sample']);
$this
->assertEmpty($context['entity_ids']);
$this
->assertArrayNotHasKey('entity_type', $context);
$this
->assertArrayNotHasKey('entity_id', $context);
}
}