Skip to content

Commit

Permalink
tweak events tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jun 3, 2023
1 parent 815f1e8 commit 8fadb56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
30 changes: 6 additions & 24 deletions tests/events.cfc
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
<!---
*
* Copyright (c) 2016, Lucee Assosication Switzerland. All rights reserved.
* Copyright (c) 2014, the Railo Company LLC. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
---><cfscript>
component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" {

//public function setUp(){}
Expand Down Expand Up @@ -52,7 +33,8 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" {
systemOutput("ERROR: " & err.error, true, true);
}
}
local.expectedEvents = [ "preInsert", "postInsert", "onFlush", "onClear" ]; // TBC
local.expectedEvents = [ "onFlush", "preInsert", "preInsert", "postInsert", "postInsert", "onClear" ];
// local.expectedEvents = [ "preInsert", "postInsert", "onFlush", "onClear" ]; // TBC
expect( res.events ).toBe( expectedEvents );
expect( res.errors.len() ).toBe( 0, "errors" );
expect( res.events.len() ).toBe( 4, "events" );
Expand All @@ -69,8 +51,9 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" {
loop array=res.errors, item="local.err"{
systemOutput("ERROR: " & err.error, true, true);
}
}
local.expectedEvents = [ "preLoad", "postLoad", "onFlush", "onClear" ]; // TBC
}
local.expectedEvents = [ "onFlush", "onClear" ];
//local.expectedEvents = [ "preLoad", "postLoad", "onFlush", "onClear" ]; // TBC
expect( res.events ).toBe( expectedEvents );
expect( res.errors.len() ).toBe( 0, "errors" );
expect( res.events.len() ).toBe( 4, "events" );
Expand All @@ -82,5 +65,4 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" {
var baseURI = getDirectoryFromPath( contractPath( getCurrentTemplatePath() ) );
return baseURI&""&calledName;
}
}
</cfscript>
}
13 changes: 10 additions & 3 deletions tests/events/eventHandler.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ component hint="logs out any orm events" {
eventLog( arguments );
}

function preUpdate( entity, Struct oldData ){
function preUpdate( entity, oldData ){
systemOutput(oldData, true);
eventLog( arguments );
}
Expand Down Expand Up @@ -80,10 +80,10 @@ component hint="logs out any orm events" {
if ( isSimpleValue( args.2 ) ){
systemOutput("simple arguments.2: " & args.2, true);
} else if ( isStruct( args.2) ) {
systemOutput("struct arguments.2: " & args.2.toJson(), true);
systemOutput("struct arguments.2: " & serializeJson(args.2), true); // hmm??
} else {
try {
systemOutput("arguments.2: " & args.2.toJson(), true);
systemOutput("arguments.2: " & args.2.getClass(), true); //hmm?
} catch (e) {
systemOutput("arguments.2: " & e.message, true);
}
Expand All @@ -98,6 +98,13 @@ component hint="logs out any orm events" {
"args": args
} );

var noEntityExpected = {
"onFlush" : true,
"onClear" : true
};

if (structKeyExists(noEntityExpected, eventName)) return;

try {
if ( isNull(arguments.args.entity ) ) {
throw ("entity was null");
Expand Down

0 comments on commit 8fadb56

Please sign in to comment.