Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fillpdf
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
fillpdf
Commits
a401598b
Commit
a401598b
authored
7 years ago
by
Kevin Kaland
Browse files
Options
Downloads
Patches
Plain Diff
Revert "Issue #2877483: Undo renaming of test file."
This reverts commit
1468130e
.
parent
1468130e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/FillPdfWebTestCase.test
+173
-0
173 additions, 0 deletions
tests/FillPdfWebTestCase.test
with
173 additions
and
0 deletions
tests/FillPdfWebTestCase.test
0 → 100644
+
173
−
0
View file @
a401598b
<?php
/**
* @file
* Contains tests for the module.
*/
/**
* Tests the PDF handling functions of the API (a.k.a. the whole API).
*
* @todo Add a test based on an Acrobat-created PDF.
*/
class
FillPdfWebTestCase
extends
FileFieldTestCase
{
protected
$privileged_user
;
protected
$nonPrivilegedUser
;
/**
*
*/
public
static
function
getInfo
()
{
// Note: getInfo() strings are not translated with t().
return
array
(
'name'
=>
'FillPDF'
,
'description'
=>
'Ensure that FillPDF administration functions are present and work.'
,
'group'
=>
'FillPDF'
,
);
}
/**
*
*/
public
function
setUp
()
{
// Enable any modules required for the test. This should be an array of
// module names.
parent
::
setUp
(
array
(
'fillpdf_test'
));
// Create and log in our privileged user.
$this
->
privileged_user
=
$this
->
drupalCreateUser
(
array
(
'access administration pages'
,
'administer pdfs'
,
'publish all pdfs'
,
));
$this
->
nonPrivilegedUser
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
));
$this
->
drupalLogin
(
$this
->
privileged_user
);
}
/**
*
*/
public
function
testPdfUpload
()
{
$this
->
drupalGet
(
'admin/structure/fillpdf'
);
}
/**
* Ensure that fillpdf_link_from_context() functions properly.
*/
public
function
testLinkFromContext
()
{
// @todo: flesh out with more combinations. This one was most broken,
// though.
$fid
=
1
;
$fake_webform
=
new
stdClass
();
$fake_webform
->
nid
=
123
;
$fake_submission
=
new
stdClass
();
$fake_submission
->
sid
=
456
;
$fake_context
=
array
(
'nodes'
=>
array
(),
'webforms'
=>
array
(
array
(
'webform'
=>
$fake_webform
,
'submission'
=>
$fake_submission
,
),
),
'uc_orders'
=>
array
(),
'uc_order_products'
=>
array
(),
);
// We also add the base domain to our expected link so that they come out
// the same.
$expected_link
=
url
(
''
,
array
(
'absolute'
=>
TRUE
))
.
'fillpdf?fid=1&webforms[0][nid]=123&webforms[0][sid]=456'
;
$actual_link
=
fillpdf_context_to_link
(
$fid
,
$fake_context
);
$this
->
assertEqual
(
$expected_link
,
$actual_link
,
'fillpdf_context_to_link() generates a link with a single Webform correctly.'
);
$fake_multiple_context
=
array
(
'nodes'
=>
array
(),
'webforms'
=>
array
(
array
(
'webform'
=>
$fake_webform
,
'submission'
=>
$fake_submission
,
),
array
(
'webform'
=>
(
object
)
array
(
'nid'
=>
234
),
'submission'
=>
(
object
)
array
(
'sid'
=>
567
),
),
array
(
'webform'
=>
(
object
)
array
(
'nid'
=>
345
),
'submission'
=>
(
object
)
array
(
'sid'
=>
678
),
),
),
'uc_orders'
=>
array
(),
'uc_order_products'
=>
array
(),
);
// We also add the base domain to our expected link so that they come out
// the same.
$expected_link2
=
url
(
''
,
array
(
'absolute'
=>
TRUE
))
.
'fillpdf?fid=1&webforms[0][nid]=123&webforms[0][sid]=456&webforms[1][nid]=234&webforms[1][sid]=567&webforms[2][nid]=345&webforms[2][sid]=678'
;
$actual_link2
=
fillpdf_context_to_link
(
$fid
,
$fake_multiple_context
);
$this
->
assertEqual
(
$expected_link2
,
$actual_link2
,
'fillpdf_context_to_link() generates a link with multiple Webforms correctly.'
);
}
/**
* Make sure that file access works properly.
*/
public
function
testFileAccess
()
{
$this
->
createFileField
(
'field_pdf'
,
'page'
);
// Make a basic page.
$new_node
=
new
stdClass
();
$new_node
->
type
=
'page'
;
$new_node
->
title
=
t
(
'Test node'
);
$new_node
->
field_body
=
array
(
LANGUAGE_NONE
=>
array
(
0
=>
array
(
'value'
=>
'This is test text.'
,
),
),
);
$new_node
->
uid
=
1
;
node_save
(
$new_node
);
variable_set
(
'fillpdf_service'
,
'test'
);
variable_set
(
'fillpdf_scheme'
,
'private'
);
// Upload a template.
$this
->
drupalPost
(
'admin/structure/fillpdf'
,
array
(
'files[upload_pdf]'
=>
drupal_realpath
(
drupal_get_path
(
'module'
,
'fillpdf'
)
.
'/tests/fillpdf_test_v4.pdf'
),
),
t
(
'Upload'
));
$this
->
drupalGet
(
'node/1'
);
$this
->
assertResponse
(
403
,
'Access properly denied for non-admin.'
);
db_update
(
'fillpdf_forms'
)
->
fields
(
array
(
'destination_path'
=>
'output'
))
->
condition
(
'fid'
,
1
)
->
execute
();
$fillpdf_object
=
fillpdf_merge_pdf
(
1
,
array
(
1
),
NULL
,
NULL
,
FALSE
,
FALSE
,
TRUE
,
FALSE
);
$saved_file
=
fillpdf_action_save_to_file
(
$fillpdf_object
,
'fillpdf_test_v4.pdf'
,
FALSE
,
FALSE
);
$saved_file
->
display
=
1
;
$new_node
->
field_pdf
=
array
(
LANGUAGE_NONE
=>
array
(
0
=>
(
array
)
$saved_file
,
),
);
node_save
(
$new_node
);
$this
->
drupalGet
(
'system/files/fillpdf/output/fillpdf_test_v4.pdf'
);
$this
->
assertResponse
(
200
,
'User can generate and access PDF from any data when they have the Publish All PDFs permission.'
);
$this
->
drupalLogin
(
$this
->
nonPrivilegedUser
);
$this
->
drupalGet
(
'system/files/fillpdf/output/fillpdf_test_v4.pdf'
);
$this
->
assertResponse
(
403
,
'User without Administer PDFs and without Publish All PDFs cannot access PDF they cannot view the node for.'
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment