forked from lucee/Lucee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDEV-3739 pass error object to error templates
- Loading branch information
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
component extends="org.lucee.cfml.test.LuceeTestCase" labels="error" { | ||
|
||
function beforeAll(){ | ||
|
||
variables.uri = createURI("LDEV3739"); | ||
// stash default config | ||
admin | ||
action="getError" | ||
type="server" | ||
password="#request.SERVERADMINPASSWORD#" | ||
returnVariable="variables.errorConfig"; | ||
systemOutput(variables.errorConfig, true); | ||
|
||
// setup test config | ||
admin | ||
action="updateError" | ||
type="server" | ||
password="#request.SERVERADMINPASSWORD#" | ||
template500="#uri#/500.cfm" | ||
template404="#uri#/404.cfm" | ||
statuscode="true"; | ||
|
||
admin | ||
action="getError" | ||
type="server" | ||
password="#request.SERVERADMINPASSWORD#" | ||
returnVariable="variables.errorConfig2"; | ||
systemOutput(variables.errorConfig2, true); | ||
|
||
} | ||
|
||
function afterAll(){ | ||
// restore default config | ||
admin | ||
action="updateError" | ||
type="server" | ||
password="#request.SERVERADMINPASSWORD#" | ||
template500=variables.errorConfig.str.500 | ||
template404=variables.errorConfig.str.404 | ||
statuscode= variables.errorConfig.doStatusCode; | ||
} | ||
|
||
function run( testResults , testBox ) { | ||
describe( title='LDEV-3739' , body=function(){ | ||
it( title='test that the test error templates are configured' , body=function() { | ||
expect( fileExists( variables.errorConfig.templates.404 ) ).toBeTrue(); | ||
expect( fileExists( variables.errorConfig.templates.500 ) ).toBeTrue(); | ||
}); | ||
|
||
it( title='test 500 error page has error variable' , body=function() { | ||
var req = _InternalRequest( | ||
template: "#uri#/throw.cfm", // throw an error and trigger 500.cfm | ||
throwonerror: false | ||
); | ||
//fileWrite( uri & "/500_req.json", req.toJson() ); | ||
//fileWrite( uri & "/500.json", req.filecontent ); | ||
// systemOutput( result.filecontent, true ); | ||
// systemOutput( result, true ); | ||
expect( isJson( req.filecontent ) ).toBeTrue(); | ||
var result = deserializeJSON( req.filecontent ); | ||
expect( req.status_code ).toBe( 500 ); | ||
|
||
expect( result ).toHaveKey( "error" ); | ||
expect( result ).toHaveKey( "catch" ); | ||
expect( result ).toHaveKey( "cfcatch" ); | ||
|
||
loop list="browser,datetime,diagnostics,GeneratedContent,HTTPReferer,mailto,QueryString,RemoteAddress,RootCause,Template" item="k" { | ||
expect( result.error ).toHaveKey( k ); | ||
} | ||
}); | ||
|
||
xit( title='test 404 error page has error variable', body=function() { | ||
var req = _InternalRequest( | ||
template : "#uri#/missing.cfm", // trigger 404.cfm | ||
throwonerror: false | ||
); | ||
return; // testing this with internalRequest is difficult | ||
|
||
//fileWrite( uri & "/404_req.json", req.toJson() ); | ||
//fileWrite( uri & "/404.json", req.filecontent ); | ||
expect( req.status_code ).toBe( 404 ); | ||
//systemOutput( result.filecontent, true ); | ||
//systemOutput( result, true ); | ||
expect( isJson( req.filecontent ) ).toBeTrue(); | ||
var result = deserializeJSON( req.filecontent ); | ||
|
||
|
||
expect( result ).toHaveKey( "error" ); | ||
expect( result ).toHaveKey( "catch" ); | ||
expect( result ).toHaveKey( "cfcatch" ); | ||
|
||
}); | ||
|
||
}); | ||
} | ||
|
||
private string function createURI(string calledName){ | ||
var baseURI="/test/#listLast(getDirectoryFromPath(getCurrentTemplatePath()),"\/")#/"; | ||
return baseURI&""&calledName; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<cfscript> | ||
systemOutput("I'm a 404 error template", true); | ||
echo(variables.toJson()); | ||
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<cfscript> | ||
systemOutput("I'm a 500 error template", true); | ||
echo(variables.toJson()); | ||
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
component { | ||
this.name="LDEV3739"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<cfscript> | ||
throw "I'm an error"; | ||
</cfscript> |