Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
fusiondirectory
fusiondirectory-orchestrator
Commits
ecb41b14
Commit
ecb41b14
authored
1 month ago
by
Oana-Eliza Alexa
Browse files
Options
Download
Patches
Plain Diff
write 2 more tests
parent
b360fd5a
70-create-unitests-for-orchestrator
1 merge request
!73
Draft: Resolve "Create unitests for orchestrator"
Pipeline
#32490
failed with stages
in 33 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testing/tests/NotificationsTest.php
+92
-0
testing/tests/NotificationsTest.php
with
92 additions
and
0 deletions
+92
-0
testing/tests/NotificationsTest.php
+
92
−
0
View file @
ecb41b14
...
...
@@ -255,4 +255,96 @@ class NotificationsTest extends TestCase
$result
=
$notifications
->
processEndPointPost
();
$this
->
assertEmpty
(
$result
);
}
public
function
testProcessNotificationsOneTaskToProcessOneMatchingAttributes
()
{
$taskData
=
[
'status'
=>
1
,
'fdtasksgranularmaster'
=>
[
'main task'
],
'maintask'
=>
[
[
'fdtasksnotificationslistofrecipientsmails'
=>
[
'abc@yahoo.com'
,
'def@gmail.com'
],
'fdtasksnotificationsemailsender'
=>
[
'sender@fd.com'
,
'sender@email.com'
],
'fdtasksnotificationsmailtemplate'
=>
[
'template1'
],
'mailInfos'
=>
[],
'fdtasksnotificationsattributes'
=>
[
'resource2'
,
'resource3'
],
'fdtasksnotificationsresource'
=>
[
'test resource'
],
'fdtasksnotificationsstate'
=>
[
'test state'
],
'fdtasksnotificationssubstate'
=>
[
'test substate'
],
]
],
'fdtasksgranularref'
=>
[
'resource1'
],
'fdtasksgranulardn'
=>
[
'granulardn'
],
'dn'
=>
'testdn'
,
'cn'
=>
[
'mycn'
],
'monitoredattrs'
=>
[
[
'fdauditattributes'
=>
[
json_encode
([
'resource2'
=>
'value2'
])],
]
]
];
$taskGateway
=
$this
->
createMock
(
TaskGateway
::
class
);
$taskGateway
->
expects
(
$this
->
once
())
->
method
(
'statusAndScheduleCheck'
)
->
willReturnCallback
(
function
(
$task
)
{
return
$task
[
'status'
]
==
1
;
});
$taskGateway
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'getLdapTasks'
)
->
willReturnCallback
(
function
(
$filter
,
$attrs
,
$attachmentsCN
,
$dn
)
use
(
$taskData
)
{
if
(
$dn
==
'resource1'
)
{
return
$taskData
[
'monitoredattrs'
];
}
return
$taskData
[
'maintask'
][
0
][
'mailInfos'
];
});
$notifications
=
$this
->
getMockBuilder
(
Notifications
::
class
)
->
setConstructorArgs
([
$taskGateway
])
->
onlyMethods
([
'getNotificationsMainTask'
,
'sendNotificationsMail'
])
->
getMock
();
$notifications
->
expects
(
$this
->
once
())
->
method
(
'getNotificationsMainTask'
)
->
willReturn
(
$taskData
[
'maintask'
]);
$notifications
->
expects
(
$this
->
once
())
->
method
(
'sendNotificationsMail'
)
->
willReturn
([
TRUE
]);
$task
=
new
NotificationsTask
(
$taskData
);
$result
=
$notifications
->
processNotifications
([
$task
->
toArray
()]);
$expectedOutput
=
[[
TRUE
]];
$this
->
assertEquals
(
$expectedOutput
,
$result
);
}
public
function
testProcessNotificationsOneTaskToProcessSupannMatchingAttributes
()
{
$taskData
=
[
'status'
=>
1
,
'fdtasksgranularmaster'
=>
[
'main task'
],
'maintask'
=>
[
[
'fdtasksnotificationslistofrecipientsmails'
=>
[
'abc@yahoo.com'
,
'def@gmail.com'
],
'fdtasksnotificationsemailsender'
=>
[
'sender@fd.com'
,
'sender@email.com'
],
'fdtasksnotificationsmailtemplate'
=>
[
'template1'
],
'mailInfos'
=>
[],
'fdtasksnotificationsattributes'
=>
[
'resource2'
,
'resource3'
],
'fdtasksnotificationsresource'
=>
[
'test resource'
],
'fdtasksnotificationsstate'
=>
[
'test state'
],
'fdtasksnotificationssubstate'
=>
[
'test substate'
],
]
],
'fdtasksgranularref'
=>
[
'resource1'
],
'fdtasksgranulardn'
=>
[
'granulardn'
],
'dn'
=>
'testdn'
,
'cn'
=>
[
'mycn'
],
'monitoredattrs'
=>
[
[
'fdauditattributes'
=>
[
json_encode
([
'resource2'
=>
'{test resource}test state:test substate'
])],
]
]
];
$taskGateway
=
$this
->
createMock
(
TaskGateway
::
class
);
$taskGateway
->
expects
(
$this
->
once
())
->
method
(
'statusAndScheduleCheck'
)
->
willReturnCallback
(
function
(
$task
)
{
return
$task
[
'status'
]
==
1
;
});
$taskGateway
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'getLdapTasks'
)
->
willReturnCallback
(
function
(
$filter
,
$attrs
,
$attachmentsCN
,
$dn
)
use
(
$taskData
)
{
if
(
$dn
==
'resource1'
)
{
return
$taskData
[
'monitoredattrs'
];
}
return
$taskData
[
'maintask'
][
0
][
'mailInfos'
];
});
$notifications
=
$this
->
getMockBuilder
(
Notifications
::
class
)
->
setConstructorArgs
([
$taskGateway
])
->
onlyMethods
([
'getNotificationsMainTask'
,
'sendNotificationsMail'
])
->
getMock
();
$notifications
->
expects
(
$this
->
once
())
->
method
(
'getNotificationsMainTask'
)
->
willReturn
(
$taskData
[
'maintask'
]);
$notifications
->
expects
(
$this
->
once
())
->
method
(
'sendNotificationsMail'
)
->
willReturn
([
TRUE
]);
$task
=
new
NotificationsTask
(
$taskData
);
$result
=
$notifications
->
processNotifications
([
$task
->
toArray
()]);
$expectedOutput
=
[[
TRUE
]];
$this
->
assertEquals
(
$expectedOutput
,
$result
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets