@@ -110,7 +110,7 @@ var MockMP = {};
110110 // });
111111 // Don't need, because setStrategy restore all
112112
113- // And get back to the default values
113+ // Get back to the default values
114114 if ( typeof this . defaultValues === 'undefined' || typeof this . defaultValues !== 'object' ) {
115115 this . defaultValues = { } ;
116116 }
@@ -123,13 +123,27 @@ var MockMP = {};
123123 createMocks . call ( this ) ;
124124 } ;
125125
126+ namespace . MockMP . prototype . simulateReceiveEvent = function simulateReceiveEvent ( name , value ) {
127+ _call_callbacks . call ( this , 'wiring' , name , value , true ) ;
128+ } ;
129+
130+ namespace . MockMP . prototype . simulateReceiveContext = function simulateReceiveContext ( name , values ) {
131+ var single_o = false ;
132+ if ( typeof values === 'undefined' ) {
133+ values = name ;
134+ name = '' ;
135+ single_o = true ;
136+ }
137+ _call_callbacks . call ( this , 'widget' , name , values , single_o ) ;
138+ } ;
139+
126140
127141 /*****************************************************************************/
128142 /********************************** Private **********************************/
129143 /*****************************************************************************/
130144
131145 var default_preferences_set = function default_preferences_set ( name , value ) {
132- /* istanbul ignore else */ // ignore else because it should never lead to that
146+ /* istanbul ignore next: This function is private, shouldn't be called outside */
133147 if ( this . methodValues && this . methodValues [ 'prefs.get' ] ) {
134148 var old_f = this . methodValues [ 'prefs.get' ] ;
135149 this . methodValues [ 'prefs.get' ] = function ( name2 ) {
@@ -152,7 +166,7 @@ var MockMP = {};
152166
153167 var default_register_callback = function default_register_callback ( name ) {
154168 var valid_names = [ 'prefs' , 'widget' , 'wiring' ] ;
155- /* istanbul ignore next */ // This function is private, shouldn't be called outside
169+ /* istanbul ignore next: This function is private, shouldn't be called outside */
156170 if ( valid_names . indexOf ( name ) == - 1 ) {
157171 throw new TypeError ( 'You are trying to register in a non existant name: ' + name ) ;
158172 }
@@ -172,7 +186,6 @@ var MockMP = {};
172186 if ( typeof this . callbacks [ name ] [ setted ] === 'undefined' ) {
173187 this . callbacks [ name ] [ setted ] = [ ] ;
174188 }
175-
176189 this . callbacks [ name ] [ setted ] . push ( cb ) ;
177190 return null ;
178191 } ;
@@ -192,14 +205,18 @@ var MockMP = {};
192205 if ( typeof onlyValue === 'undefined' ) {
193206 onlyValue = false ;
194207 }
208+ var toget = vname ;
195209 if ( ! onlyValue ) {
196210 var nv = { } ;
197211 nv [ vname ] = value ; // Send as object
198212 value = nv ;
213+ toget = '' ;
199214 }
200215
201- var calls = _get_callbacks . call ( this , 'prefs' , 'vname' ) ;
216+ var calls = _get_callbacks . call ( this , cname , toget ) ;
217+
202218 for ( var c in calls ) {
219+ /* istanbul ignore else: The callback initializer ensures that this will be a function */
203220 if ( typeof calls [ c ] == 'function' ) {
204221 calls [ c ] ( value ) ;
205222 }
@@ -208,16 +225,16 @@ var MockMP = {};
208225
209226 var _get_callbacks = function _get_callbacks ( name , sname ) {
210227 _initialize_callbacks . call ( this ) ;
228+ /* istanbul ignore next: This function is private, shouldn't be called outside */
211229 if ( ! this . callbacks [ name ] ) {
212230 return [ ] ;
213231 }
214232 var callsn = this . callbacks [ name ] ;
215233
216- var allcalls = callsn [ '' ] || [ ] ;
217-
234+ var allcalls = callsn [ '' ] || /* istanbul ignore next: We've already initialized before */ [ ] ;
218235 if ( typeof sname !== 'undefined' && sname !== '' ) {
219236 var speccalls = callsn [ sname ] || [ ] ;
220- allcalls . concat ( speccalls ) ;
237+ allcalls = allcalls . concat ( speccalls ) ;
221238 }
222239
223240 return allcalls ;
@@ -231,7 +248,6 @@ var MockMP = {};
231248 } ;
232249
233250 var mergeDefault = function mergeDefault ( methodValues ) {
234-
235251 var defaultValues = {
236252 "context.get" : namespace . strategy . constant ( "not set yet" ) ,
237253 "http.buildProxyURL" : namespace . strategy . constant ( null ) ,
@@ -241,17 +257,17 @@ var MockMP = {};
241257 "log.INFO" : 3 ,
242258 "mashup.context.get" : namespace . strategy . constant ( null ) ,
243259 "prefs.get" : namespace . strategy . constant ( "value" ) ,
244- "prefs.set" : default_functionality [ 'prefs.set' ] . bind ( this ) , // namespace.strategy.constant(null),
245- "prefs.registerCallback" : default_functionality [ 'prefs.registerCallback' ] . bind ( this ) , //namespace.strategy.constant(null),
260+ "prefs.set" : default_functionality [ 'prefs.set' ] . bind ( this ) ,
261+ "prefs.registerCallback" : default_functionality [ 'prefs.registerCallback' ] . bind ( this ) ,
246262 "widget.getVariable" : namespace . strategy . constant ( "value" ) ,
247263 "widget.drawAttention" : namespace . strategy . constant ( null ) ,
248264 "widget.id" : "id33" ,
249265 "widget.log" : namespace . strategy . constant ( "something" ) ,
250266 "widget.context.get" : namespace . strategy . constant ( null ) ,
251- "widget.context.registerCallback" : default_functionality [ 'widget.context.registerCallback' ] . bind ( this ) , //namespace.strategy.constant(null),
267+ "widget.context.registerCallback" : default_functionality [ 'widget.context.registerCallback' ] . bind ( this ) ,
252268 "wiring.getReachableEndpoints" : namespace . strategy . constant ( [ ] ) ,
253269 "wiring.pushEvent" : namespace . strategy . constant ( null ) ,
254- "wiring.registerCallback" : default_functionality [ 'wiring.registerCallback' ] . bind ( this ) //namespace.strategy.constant(null)
270+ "wiring.registerCallback" : default_functionality [ 'wiring.registerCallback' ] . bind ( this )
255271 } ;
256272
257273 if ( methodValues ) {
0 commit comments