participant.displayName.toLowerCase().indexOf(lowerSearchText) !== -1 || participant.userId.toLowerCase().indexOf(lowerSearchText) !== -1)
+ participants = participants.filter(participant => {
+ return participant.displayName.toLowerCase().indexOf(lowerSearchText) !== -1
+ || (participant.actorType !== 'guests'
+ && participant.actorId.toLowerCase().indexOf(lowerSearchText) !== -1)
+ })
}
return participants.slice().sort(this.sortParticipants)
@@ -89,7 +93,8 @@ export default {
this.$store.dispatch('updateUser', {
token: this.token,
participantIdentifier: {
- userId: state.userId,
+ actorType: 'users',
+ actorId: state.userId,
},
updatedData: {
status: state.status,
diff --git a/src/components/RightSidebar/Participants/ParticipantsList/Participant/Participant.vue b/src/components/RightSidebar/Participants/ParticipantsList/Participant/Participant.vue
index 4e578373f23..cf19d95037e 100644
--- a/src/components/RightSidebar/Participants/ParticipantsList/Participant/Participant.vue
+++ b/src/components/RightSidebar/Participants/ParticipantsList/Participant/Participant.vue
@@ -36,7 +36,7 @@
:show-user-status="showUserStatus && !isSearched"
:show-user-status-compact="false"
:name="computedName"
- :source="participant.source"
+ :source="participant.source || participant.actorType"
:offline="isOffline" />
+
+ {{ attendeePin }}
+
@@ -104,6 +110,7 @@
diff --git a/src/components/TopBar/TopBar.vue b/src/components/TopBar/TopBar.vue
index 7efdae757c6..4765a79ae9f 100644
--- a/src/components/TopBar/TopBar.vue
+++ b/src/components/TopBar/TopBar.vue
@@ -133,6 +133,12 @@
@change="setLobbyTimer">
{{ t('spreed', 'Start time (optional)') }}
+
+ {{ t('spreed', 'Enable SIP dial-in') }}
+
@@ -283,6 +289,9 @@ export default {
showModerationOptions() {
return !this.isOneToOneConversation && this.canModerate
},
+ canUserEnableSIP() {
+ return this.conversation.canEnableSIP
+ },
token() {
return this.$store.getters.getToken()
},
@@ -298,6 +307,7 @@ export default {
displayName: '',
isFavorite: false,
hasPassword: false,
+ canEnableSIP: false,
type: CONVERSATION.TYPE.PUBLIC,
lobbyState: WEBINAR.LOBBY.NONE,
lobbyTimer: 0,
@@ -349,6 +359,9 @@ export default {
confirm: true,
}
},
+ hasSIPEnabled() {
+ return this.conversation.sipEnabled === WEBINAR.SIP.ENABLED
+ },
isGrid() {
return this.$store.getters.isGrid
},
@@ -440,6 +453,19 @@ export default {
})
},
+ async toggleSIPEnabled(checked) {
+ try {
+ await this.$store.dispatch('setSIPEnabled', {
+ token: this.token,
+ state: checked ? WEBINAR.SIP.ENABLED : WEBINAR.SIP.DISABLED,
+ })
+ } catch (e) {
+ // TODO check "precondition failed"
+ // TODO showError()
+ console.error(e)
+ }
+ },
+
async setLobbyTimer(date) {
this.lobbyTimerLoading = true
diff --git a/src/constants.js b/src/constants.js
index 4caa62ba778..a3d3c0a9855 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -49,6 +49,12 @@ export const PARTICIPANT = {
WITH_VIDEO: 4,
WITH_PHONE: 8,
},
+ SIP_FLAG: {
+ MUTE_MICROPHONE: 1,
+ MUTE_SPEAKER: 2,
+ SPEAKING: 4,
+ RAISE_HAND: 8,
+ },
NOTIFY: {
DEFAULT: 0,
ALWAYS: 1,
@@ -69,6 +75,10 @@ export const WEBINAR = {
NONE: 0,
NON_MODERATORS: 1,
},
+ SIP: {
+ DISABLED: 0,
+ ENABLED: 1,
+ },
}
export const SHARE = {
TYPE: {
diff --git a/src/services/callsService.js b/src/services/callsService.js
index 3298522c0ea..86b39cb2498 100644
--- a/src/services/callsService.js
+++ b/src/services/callsService.js
@@ -53,17 +53,9 @@ const leaveCall = async function(token) {
}
}
-/**
- * Fetches all peers for a call
- * @param {string} token The token of the call to be fetched.
- */
-const fetchPeers = async function(token) {
- try {
- const response = await axios.get(generateOcsUrl('apps/spreed/api/v1', 2) + `call/${token}`)
- return response
- } catch (error) {
- console.debug('Error while fetching the peers: ', error)
- }
+const fetchPeers = async function(token, options) {
+ const response = await axios.get(generateOcsUrl('apps/spreed/api/v3', 2) + `call/${token}`, options)
+ return response
}
export {
diff --git a/src/services/conversationsService.js b/src/services/conversationsService.js
index af11a70a643..7189800ecf8 100644
--- a/src/services/conversationsService.js
+++ b/src/services/conversationsService.js
@@ -33,7 +33,7 @@ let maintenanceWarning = null
*/
const fetchConversations = async function() {
try {
- const response = await axios.get(generateOcsUrl('apps/spreed/api/v2', 2) + 'room')
+ const response = await axios.get(generateOcsUrl('apps/spreed/api/v3', 2) + 'room')
if (maintenanceWarning) {
maintenanceWarning.hideToast()
@@ -59,7 +59,7 @@ const fetchConversations = async function() {
*/
const fetchConversation = async function(token) {
try {
- const response = await axios.get(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}`)
+ const response = await axios.get(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}`)
if (maintenanceWarning) {
maintenanceWarning.hideToast()
@@ -129,7 +129,7 @@ const searchPossibleConversations = async function(searchText, token, onlyUsers)
*/
const createOneToOneConversation = async function(userId) {
try {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room`, { roomType: CONVERSATION.TYPE.ONE_TO_ONE, invite: userId })
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room`, { roomType: CONVERSATION.TYPE.ONE_TO_ONE, invite: userId })
return response
} catch (error) {
console.debug('Error creating new one to one conversation: ', error)
@@ -143,7 +143,7 @@ const createOneToOneConversation = async function(userId) {
*/
const createGroupConversation = async function(invite, source) {
try {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room`, { roomType: CONVERSATION.TYPE.GROUP, invite, source: source || 'groups' })
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room`, { roomType: CONVERSATION.TYPE.GROUP, invite, source: source || 'groups' })
return response
} catch (error) {
console.debug('Error creating new group conversation: ', error)
@@ -156,7 +156,7 @@ const createGroupConversation = async function(invite, source) {
*/
const createPrivateConversation = async function(conversationName) {
try {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room`, { roomType: CONVERSATION.TYPE.GROUP, roomName: conversationName })
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room`, { roomType: CONVERSATION.TYPE.GROUP, roomName: conversationName })
return response
} catch (error) {
console.debug('Error creating new private conversation: ', error)
@@ -169,7 +169,7 @@ const createPrivateConversation = async function(conversationName) {
*/
const createPublicConversation = async function(conversationName) {
try {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room`, { roomType: CONVERSATION.TYPE.PUBLIC, roomName: conversationName })
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room`, { roomType: CONVERSATION.TYPE.PUBLIC, roomName: conversationName })
return response
} catch (error) {
console.debug('Error creating new public conversation: ', error)
@@ -182,7 +182,7 @@ const createPublicConversation = async function(conversationName) {
* @param {string} password the password to be set
*/
const setConversationPassword = async function(token, password) {
- const response = await axios.put(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/password`, {
+ const response = await axios.put(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/password`, {
password,
})
return response
@@ -194,7 +194,7 @@ const setConversationPassword = async function(token, password) {
* @param {string} name the name to be set
*/
const setConversationName = async function(token, name) {
- const response = await axios.put(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}`, {
+ const response = await axios.put(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}`, {
roomName: name,
})
return response
@@ -206,7 +206,7 @@ const setConversationName = async function(token, name) {
*/
const deleteConversation = async function(token) {
try {
- const response = await axios.delete(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}`)
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}`)
return response
} catch (error) {
console.debug('Error while deleting the conversation: ', error)
@@ -219,7 +219,7 @@ const deleteConversation = async function(token) {
*/
const addToFavorites = async function(token) {
try {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/favorite`)
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/favorite`)
return response
} catch (error) {
console.debug('Error while adding the conversation to favorites: ', error)
@@ -232,7 +232,7 @@ const addToFavorites = async function(token) {
*/
const removeFromFavorites = async function(token) {
try {
- const response = await axios.delete(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/favorite`)
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/favorite`)
return response
} catch (error) {
console.debug('Error while removing the conversation from favorites: ', error)
@@ -246,7 +246,7 @@ const removeFromFavorites = async function(token) {
*/
const setNotificationLevel = async function(token, level) {
try {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/notify`, { level })
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/notify`, { level })
return response
} catch (error) {
console.debug('Error while setting the notification level: ', error)
@@ -259,7 +259,7 @@ const setNotificationLevel = async function(token, level) {
*/
const makePublic = async function(token) {
try {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/public`)
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/public`)
return response
} catch (error) {
console.debug('Error while making the conversation public: ', error)
@@ -272,13 +272,24 @@ const makePublic = async function(token) {
*/
const makePrivate = async function(token) {
try {
- const response = await axios.delete(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/public`)
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/public`)
return response
} catch (error) {
console.debug('Error while making the conversation private: ', error)
}
}
+/**
+ * Change the SIP enabled
+ * @param {string} token The token of the conversation to be modified
+ * @param {int} newState The new SIP state to set
+ */
+const setSIPEnabled = async function(token, newState) {
+ return axios.put(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/webinar/sip`, {
+ state: newState,
+ })
+}
+
/**
* Change the lobby state
* @param {string} token The token of the conversation to be modified
@@ -287,7 +298,7 @@ const makePrivate = async function(token) {
*/
const changeLobbyState = async function(token, newState, timestamp) {
try {
- const response = await axios.put(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/webinar/lobby`, {
+ const response = await axios.put(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/webinar/lobby`, {
state: newState,
timer: timestamp,
})
@@ -311,6 +322,7 @@ export {
setNotificationLevel,
makePublic,
makePrivate,
+ setSIPEnabled,
changeLobbyState,
setConversationPassword,
setConversationName,
diff --git a/src/services/participantsService.js b/src/services/participantsService.js
index 26321ee56c9..f906cdb3709 100644
--- a/src/services/participantsService.js
+++ b/src/services/participantsService.js
@@ -46,7 +46,7 @@ const joinConversation = async(token) => {
const forceJoin = SessionStorage.getItem('joined_conversation') === token
try {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/participants/active`, {
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/participants/active`, {
force: forceJoin,
})
@@ -131,7 +131,7 @@ const forceJoinConversation = async(token) => {
* @param {string} token The conversation token;
*/
const rejoinConversation = async(token) => {
- return axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/participants/active`)
+ return axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/participants/active`)
}
/**
@@ -144,7 +144,7 @@ const leaveConversation = async function(token) {
// FIXME Signaling should not be synchronous
await signalingLeaveConversation(token)
- const response = await axios.delete(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/participants/active`)
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/participants/active`)
return response
} catch (error) {
console.debug(error)
@@ -157,7 +157,7 @@ const leaveConversation = async function(token) {
* @param {string} token The conversation token;
*/
const leaveConversationSync = function(token) {
- axios.delete(generateOcsUrl('apps/spreed/api/v2/room', 2) + token + '/participants/active')
+ axios.delete(generateOcsUrl('apps/spreed/api/v3/room', 2) + token + '/participants/active')
}
/**
@@ -167,7 +167,7 @@ const leaveConversationSync = function(token) {
* @param {string} source the source Source of the participant as returned by the autocomplete suggestion endpoint (default is users)
*/
const addParticipant = async function(token, newParticipant, source) {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/participants`, {
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/participants`, {
newParticipant,
source,
})
@@ -180,13 +180,13 @@ const addParticipant = async function(token, newParticipant, source) {
* @param {string} token The conversation token;
*/
const removeCurrentUserFromConversation = async function(token) {
- const response = await axios.delete(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/participants/self`)
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/participants/self`)
return response
}
const removeUserFromConversation = async function(token, userId) {
try {
- const response = await axios.delete(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/participants`, {
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/participants`, {
params: {
participant: userId,
},
@@ -199,7 +199,7 @@ const removeUserFromConversation = async function(token, userId) {
const removeGuestFromConversation = async function(token, sessionId) {
try {
- const response = await axios.delete(generateOcsUrl('apps/spreed/api/v2', 2) + `room/${token}/participants/guests`, {
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/participants/guests`, {
params: {
participant: sessionId,
},
@@ -210,13 +210,22 @@ const removeGuestFromConversation = async function(token, sessionId) {
}
}
+const removeAttendeeFromConversation = async function(token, attendeeId) {
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3', 2) + `room/${token}/attendees`, {
+ params: {
+ attendeeId,
+ },
+ })
+ return response
+}
+
const promoteToModerator = async(token, options) => {
- const response = await axios.post(generateOcsUrl('apps/spreed/api/v2/room', 2) + token + '/moderators', options)
+ const response = await axios.post(generateOcsUrl('apps/spreed/api/v3/room', 2) + token + '/moderators', options)
return response
}
const demoteFromModerator = async(token, options) => {
- const response = await axios.delete(generateOcsUrl('apps/spreed/api/v2/room', 2) + token + '/moderators', {
+ const response = await axios.delete(generateOcsUrl('apps/spreed/api/v3/room', 2) + token + '/moderators', {
params: options,
})
return response
@@ -226,7 +235,7 @@ const fetchParticipants = async(token, options) => {
options = options || {}
options.params = options.params || {}
options.params.includeStatus = true
- const response = await axios.get(generateOcsUrl('apps/spreed/api/v2/room', 2) + token + '/participants', options)
+ const response = await axios.get(generateOcsUrl('apps/spreed/api/v3/room', 2) + token + '/participants', options)
return response
}
@@ -246,6 +255,7 @@ export {
removeCurrentUserFromConversation,
removeUserFromConversation,
removeGuestFromConversation,
+ removeAttendeeFromConversation,
promoteToModerator,
demoteFromModerator,
fetchParticipants,
diff --git a/src/services/settingsService.js b/src/services/settingsService.js
index 65e262658bf..900a580592a 100644
--- a/src/services/settingsService.js
+++ b/src/services/settingsService.js
@@ -36,6 +36,23 @@ const setAttachmentFolder = async function(path) {
})
}
+/**
+ * Save the SIP settings
+ *
+ * @param {Array} sipGroups The groups allowed to enable SIP on a conversation
+ * @param {string} sharedSecret The shared secret which is used by the SIP server to authenticate
+ * @param {string} dialInInfo The dial-in Information displayed in the email and sidebar
+ * @returns {Object} The axios response
+ */
+const setSIPSettings = async function(sipGroups, sharedSecret, dialInInfo) {
+ return axios.post(generateOcsUrl('apps/spreed/api/v1/settings', 2) + 'sip', {
+ sipGroups,
+ sharedSecret,
+ dialInInfo,
+ })
+}
+
export {
setAttachmentFolder,
+ setSIPSettings,
}
diff --git a/src/services/signalingService.js b/src/services/signalingService.js
index 420de10a03a..a2806e8204b 100644
--- a/src/services/signalingService.js
+++ b/src/services/signalingService.js
@@ -27,7 +27,7 @@ import { generateOcsUrl } from '@nextcloud/router'
* @param {object} options options
*/
const fetchSignalingSettings = async({ token }, options) => {
- return axios.get(generateOcsUrl('apps/spreed/api/v1/signaling', 2) + 'settings', Object.assign(options, {
+ return axios.get(generateOcsUrl('apps/spreed/api/v2/signaling', 2) + 'settings', Object.assign(options, {
params: {
token,
},
@@ -35,11 +35,11 @@ const fetchSignalingSettings = async({ token }, options) => {
}
const pullSignalingMessages = async(token, options) => {
- return axios.get(generateOcsUrl('apps/spreed/api/v1/signaling', 2) + token, options)
+ return axios.get(generateOcsUrl('apps/spreed/api/v2/signaling', 2) + token, options)
}
const getWelcomeMessage = async(serverId) => {
- return axios.get(generateOcsUrl('apps/spreed/api/v1/signaling', 2) + 'welcome/' + serverId)
+ return axios.get(generateOcsUrl('apps/spreed/api/v2/signaling', 2) + 'welcome/' + serverId)
}
export {
diff --git a/src/store/actorStore.js b/src/store/actorStore.js
index d75fa4e2e77..076f0da957d 100644
--- a/src/store/actorStore.js
+++ b/src/store/actorStore.js
@@ -61,11 +61,13 @@ const getters = {
getParticipantIdentifier: (state) => () => {
if (state.actorType === 'guests') {
return {
+ actorType: 'guests',
sessionId: state.sessionId,
}
}
return {
- userId: state.userId,
+ actorType: 'users',
+ actorId: state.actorId,
}
},
}
@@ -134,6 +136,7 @@ const actions = {
context.commit('setUserId', user.uid)
context.commit('setDisplayName', user.displayName || user.uid)
context.commit('setActorType', 'users')
+ context.commit('setActorId', user.uid)
},
/**
diff --git a/src/store/conversationsStore.js b/src/store/conversationsStore.js
index 09f2c9f8df9..b7d494968b4 100644
--- a/src/store/conversationsStore.js
+++ b/src/store/conversationsStore.js
@@ -23,6 +23,7 @@ import Vue from 'vue'
import {
makePublic,
makePrivate,
+ setSIPEnabled,
changeLobbyState,
addToFavorites,
removeFromFavorites,
@@ -109,6 +110,9 @@ const actions = {
lastPing: conversation.lastPing,
sessionId: conversation.sessionId,
participantType: conversation.participantType,
+ attendeeId: conversation.attendeeId,
+ actorType: conversation.actorType,
+ actorId: conversation.actorId, // FIXME check public share page handling
userId: currentUser ? currentUser.uid : '',
displayName: currentUser && currentUser.displayName ? currentUser.displayName : '', // TODO guest name from localstore?
},
@@ -206,6 +210,19 @@ const actions = {
commit('addConversation', conversation)
},
+ async setSIPEnabled({ commit, getters }, { token, state }) {
+ const conversation = Object.assign({}, getters.conversations[token])
+ if (!conversation) {
+ return
+ }
+
+ // The backend requires the state and timestamp to be set together.
+ await setSIPEnabled(token, state)
+ conversation.sipEnabled = state
+
+ commit('addConversation', conversation)
+ },
+
async markConversationRead({ commit, getters }, token) {
const conversation = Object.assign({}, getters.conversations[token])
if (!conversation) {
diff --git a/src/store/participantsStore.js b/src/store/participantsStore.js
index 91a5ca695ab..b191a8a45a8 100644
--- a/src/store/participantsStore.js
+++ b/src/store/participantsStore.js
@@ -23,8 +23,7 @@ import Vue from 'vue'
import {
promoteToModerator,
demoteFromModerator,
- removeUserFromConversation,
- removeGuestFromConversation,
+ removeAttendeeFromConversation,
} from '../services/participantsService'
import {
joinCall,
@@ -35,6 +34,8 @@ import { PARTICIPANT } from '../constants'
const state = {
participants: {
},
+ peers: {
+ },
}
const getters = {
@@ -62,14 +63,27 @@ const getters = {
let index
- if (participantIdentifier.hasOwnProperty('userId')) {
- index = state.participants[token].findIndex(participant => participant.userId === participantIdentifier.userId)
+ if (participantIdentifier.hasOwnProperty('attendeeId')) {
+ index = state.participants[token].findIndex(participant => participant.attendeeId === participantIdentifier.attendeeId)
+ } else if (participantIdentifier.hasOwnProperty('actorId') && participantIdentifier.hasOwnProperty('actorType')) {
+ index = state.participants[token].findIndex(participant => participant.actorId === participantIdentifier.actorId && participant.actorType === participantIdentifier.actorType)
} else {
index = state.participants[token].findIndex(participant => participant.sessionId === participantIdentifier.sessionId)
}
return index
},
+ getPeer: (state) => (token, sessionId) => {
+ if (!state.peers[token]) {
+ return {}
+ }
+
+ if (state.peers[token].hasOwnProperty(sessionId)) {
+ return state.peers[token][sessionId]
+ }
+
+ return {}
+ },
}
const mutations = {
@@ -109,6 +123,18 @@ const mutations = {
Vue.delete(state.participants, token)
}
},
+
+ addPeer(state, { token, peer }) {
+ if (!state.peers[token]) {
+ Vue.set(state.peers, token, [])
+ }
+ Vue.set(state.peers[token], peer.sessionId, peer)
+ },
+ purgePeersStore(state, token) {
+ if (state.peers[token]) {
+ Vue.delete(state.peers, token)
+ }
+ },
}
const actions = {
@@ -138,21 +164,15 @@ const actions = {
commit('addParticipant', { token, participant })
}
},
- async promoteToModerator({ commit, getters }, { token, participantIdentifier }) {
- const index = getters.getParticipantIndex(token, participantIdentifier)
+ async promoteToModerator({ commit, getters }, { token, attendeeId }) {
+ const index = getters.getParticipantIndex(token, { attendeeId })
if (index === -1) {
return
}
- if (participantIdentifier.userId) {
- // Moderation endpoint requires "participant" instead of "userId"
- await promoteToModerator(token, {
- participant: participantIdentifier.userId,
- })
- } else {
- // Guests are identified by sessionId in both cases
- await promoteToModerator(token, participantIdentifier)
- }
+ await promoteToModerator(token, {
+ attendeeId,
+ })
const participant = getters.getParticipant(token, index)
const updatedData = {
@@ -160,21 +180,15 @@ const actions = {
}
commit('updateParticipant', { token, index, updatedData })
},
- async demoteFromModerator({ commit, getters }, { token, participantIdentifier }) {
- const index = getters.getParticipantIndex(token, participantIdentifier)
+ async demoteFromModerator({ commit, getters }, { token, attendeeId }) {
+ const index = getters.getParticipantIndex(token, { attendeeId })
if (index === -1) {
return
}
- if (participantIdentifier.userId) {
- // Moderation endpoint requires "participant" instead of "userId"
- await demoteFromModerator(token, {
- participant: participantIdentifier.userId,
- })
- } else {
- // Guests are identified by sessionId in both cases
- await demoteFromModerator(token, participantIdentifier)
- }
+ await demoteFromModerator(token, {
+ attendeeId,
+ })
const participant = getters.getParticipant(token, index)
const updatedData = {
@@ -182,18 +196,13 @@ const actions = {
}
commit('updateParticipant', { token, index, updatedData })
},
- async removeParticipant({ commit, getters }, { token, participantIdentifier }) {
- const index = getters.getParticipantIndex(token, participantIdentifier)
+ async removeParticipant({ commit, getters }, { token, attendeeId }) {
+ const index = getters.getParticipantIndex(token, { attendeeId })
if (index === -1) {
return
}
- const participant = getters.getParticipant(token, index)
- if (participant.userId) {
- await removeUserFromConversation(token, participant.userId)
- } else {
- await removeGuestFromConversation(token, participant.sessionId)
- }
+ await removeAttendeeFromConversation(token, attendeeId)
commit('deleteParticipant', { token, index })
},
/**
@@ -205,6 +214,13 @@ const actions = {
commit('purgeParticipantsStore', token)
},
+ addPeer({ commit }, { token, peer }) {
+ commit('addPeer', { token, peer })
+ },
+ purgePeersStore({ commit }, token) {
+ commit('purgePeersStore', token)
+ },
+
updateSessionId({ commit, getters }, { token, participantIdentifier, sessionId }) {
const index = getters.getParticipantIndex(token, participantIdentifier)
if (index === -1) {
diff --git a/src/utils/signaling.js b/src/utils/signaling.js
index 94a97266d32..237d3d36482 100644
--- a/src/utils/signaling.js
+++ b/src/utils/signaling.js
@@ -1148,6 +1148,9 @@ Signaling.Standalone.prototype.processRoomParticipantsEvent = function(data) {
this._trigger('usersChanged', [data.event.update.users || []])
this._trigger('participantListChanged')
break
+ case 'flags':
+ this._trigger('participantFlagsChanged', [data.event.flags || []])
+ break
default:
console.error('Unknown room participant event', data)
break
diff --git a/src/utils/webrtc/models/CallParticipantModel.js b/src/utils/webrtc/models/CallParticipantModel.js
index c4c079d452e..87d65ed72ba 100644
--- a/src/utils/webrtc/models/CallParticipantModel.js
+++ b/src/utils/webrtc/models/CallParticipantModel.js
@@ -43,6 +43,7 @@ export default function CallParticipantModel(options) {
// are used for known but negative/empty values.
userId: undefined,
name: undefined,
+ internal: undefined,
connectionState: ConnectionState.NEW,
stream: null,
// The audio element is part of the model to ensure that it can be
diff --git a/src/utils/webrtc/webrtc.js b/src/utils/webrtc/webrtc.js
index c3cb185929e..7d810289e6f 100644
--- a/src/utils/webrtc/webrtc.js
+++ b/src/utils/webrtc/webrtc.js
@@ -229,6 +229,9 @@ function usersChanged(signaling, newUsers, disconnectedSessionIds) {
})
}
callParticipantModel.setUserId(userId)
+ if (user.internal) {
+ callParticipantModel.set('internal', true)
+ }
// When the MCU is used and the other participant has no streams or
// when no MCU is used and neither the local participant nor the
@@ -384,6 +387,20 @@ export default function initWebRTC(signaling, _callParticipantCollection, _local
})
usersInCallChanged(signaling, usersInCallMapping)
})
+ signaling.on('participantFlagsChanged', function(event) {
+ /**
+ * event {
+ * roomid: "1609407087",
+ * sessionid: "…",
+ * flags: 1
+ * }
+ */
+ const callParticipantModel = callParticipantCollection.get(event.sessionid)
+ if (callParticipantModel) {
+ callParticipantModel.set('speaking', (event.flags & PARTICIPANT.SIP_FLAG.SPEAKING) > 0)
+ callParticipantModel.set('audioAvailable', (event.flags & PARTICIPANT.SIP_FLAG.MUTE_MICROPHONE) === 0)
+ }
+ })
signaling.on('usersInRoom', function(users) {
usersInCallMapping = {}
users.forEach(function(user) {
diff --git a/src/views/AdminSettings.vue b/src/views/AdminSettings.vue
index a3cc105e46a..095c7903b92 100644
--- a/src/views/AdminSettings.vue
+++ b/src/views/AdminSettings.vue
@@ -30,31 +30,34 @@
+
diff --git a/tests/integration/features/bootstrap/CommandLineTrait.php b/tests/integration/features/bootstrap/CommandLineTrait.php
new file mode 100644
index 00000000000..973dd213b59
--- /dev/null
+++ b/tests/integration/features/bootstrap/CommandLineTrait.php
@@ -0,0 +1,162 @@
+
+ * @author Lukas Reschke
+ * @author Robin Appelman
+ * @author Vincent Petry
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see
+ *
+ */
+
+use PHPUnit\Framework\Assert;
+
+require __DIR__ . '/../../vendor/autoload.php';
+
+trait CommandLineTrait {
+
+ /** @var int return code of last command */
+ private $lastCode;
+ /** @var string stdout of last command */
+ private $lastStdOut;
+ /** @var string stderr of last command */
+ private $lastStdErr;
+
+ /** @var string */
+ protected $ocPath = '../../../..';
+
+ /**
+ * Invokes an OCC command
+ *
+ * @param []string $args OCC command, the part behind "occ". For example: "files:transfer-ownership"
+ * @return int exit code
+ */
+ public function runOcc($args = []) {
+ $args = array_map(function ($arg) {
+ return escapeshellarg($arg);
+ }, $args);
+ $args[] = '--no-ansi';
+ $args = implode(' ', $args);
+
+ $descriptor = [
+ 0 => ['pipe', 'r'],
+ 1 => ['pipe', 'w'],
+ 2 => ['pipe', 'w'],
+ ];
+ $process = proc_open('php console.php ' . $args, $descriptor, $pipes, $this->ocPath);
+ $this->lastStdOut = stream_get_contents($pipes[1]);
+ $this->lastStdErr = stream_get_contents($pipes[2]);
+ $this->lastCode = proc_close($process);
+
+ // Clean opcode cache
+ $client = new GuzzleHttp\Client();
+ $client->request('GET', 'http://localhost:8080/apps/testing/clean_opcode_cache.php');
+
+ return $this->lastCode;
+ }
+
+ /**
+ * @Given /^invoking occ with "([^"]*)"$/
+ */
+ public function invokingTheCommand($cmd) {
+ $args = explode(' ', $cmd);
+ $this->runOcc($args);
+ }
+
+ /**
+ * Find exception texts in stderr
+ */
+ public function findExceptions() {
+ $exceptions = [];
+ $captureNext = false;
+ // the exception text usually appears after an "[Exception"] row
+ foreach (explode("\n", $this->lastStdErr) as $line) {
+ if (preg_match('/\[Exception\]/', $line)) {
+ $captureNext = true;
+ continue;
+ }
+ if ($captureNext) {
+ $exceptions[] = trim($line);
+ $captureNext = false;
+ }
+ }
+
+ return $exceptions;
+ }
+
+ /**
+ * @Then /^the command was successful$/
+ */
+ public function theCommandWasSuccessful() {
+ $exceptions = $this->findExceptions();
+ if ($this->lastCode !== 0) {
+ $msg = 'The command was not successful, exit code was ' . $this->lastCode . '.';
+ if (!empty($exceptions)) {
+ $msg .= ' Exceptions: ' . implode(', ', $exceptions);
+ }
+ throw new \Exception($msg);
+ } elseif (!empty($exceptions)) {
+ $msg = 'The command was successful but triggered exceptions: ' . implode(', ', $exceptions);
+ throw new \Exception($msg);
+ }
+ }
+
+ /**
+ * @Then /^the command failed with exit code ([0-9]+)$/
+ */
+ public function theCommandFailedWithExitCode($exitCode) {
+ Assert::assertEquals($exitCode, $this->lastCode, 'The commands exit code did not match');
+ }
+
+ /**
+ * @Then /^the command failed with exception text "([^"]*)"$/
+ */
+ public function theCommandFailedWithException($exceptionText) {
+ $exceptions = $this->findExceptions();
+ if (empty($exceptions)) {
+ throw new \Exception('The command did not throw any exceptions');
+ }
+
+ if (!in_array($exceptionText, $exceptions)) {
+ throw new \Exception('The command did not throw any exception with the text "' . $exceptionText . '"');
+ }
+ }
+
+ /**
+ * @Then /^the command output contains the text "([^"]*)"$/
+ */
+ public function theCommandOutputContainsTheText($text) {
+ if ($this->lastStdOut === '' && $this->lastStdErr !== '') {
+ Assert::assertContains($text, $this->lastStdErr, 'The command did not output the expected text on stdout');
+ Assert::assertTrue(false, 'The command did not output the expected text on stdout but stderr');
+ }
+
+ Assert::assertContains($text, $this->lastStdOut, 'The command did not output the expected text on stdout');
+ }
+
+ /**
+ * @Then /^the command error output contains the text "([^"]*)"$/
+ */
+ public function theCommandErrorOutputContainsTheText($text) {
+ if ($this->lastStdErr === '' && $this->lastStdOut !== '') {
+ Assert::assertContains($text, $this->lastStdOut, 'The command did not output the expected text on stdout');
+ Assert::assertTrue(false, 'The command did not output the expected text on stdout but stderr');
+ }
+
+ Assert::assertContains($text, $this->lastStdErr, 'The command did not output the expected text on stderr');
+ }
+}
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index b95e5d67f0e..492f275d47f 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -74,6 +74,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
/** @var SharingContext */
private $sharingContext;
+ use CommandLineTrait;
+
public static function getTokenForIdentifier(string $identifier) {
return self::$identifierToToken[$identifier];
}
@@ -169,12 +171,30 @@ public function userIsParticipantOfRooms($user, TableNode $formData = null) {
$participantNames[$lastParticipantKey] .= ' [exact order]';
}
- return [
- 'id' => self::$tokenToIdentifier[$room['token']],
- 'type' => (string) $room['type'],
- 'participantType' => (string) $room['participantType'],
- 'participants' => implode(', ', $participantNames),
- ];
+ $data = [];
+ if (isset($expectedRoom['id'])) {
+ $data['id'] = self::$tokenToIdentifier[$room['token']];
+ }
+ if (isset($expectedRoom['name'])) {
+ $data['name'] = $room['name'];
+ }
+ if (isset($expectedRoom['type'])) {
+ $data['type'] = (string) $room['type'];
+ }
+ if (isset($expectedRoom['hasPassword'])) {
+ $data['hasPassword'] = (string) $room['hasPassword'];
+ }
+ if (isset($expectedRoom['readOnly'])) {
+ $data['readOnly'] = (string) $room['readOnly'];
+ }
+ if (isset($expectedRoom['participantType'])) {
+ $data['participantType'] = (string) $room['participantType'];
+ }
+ if (isset($expectedRoom['participants'])) {
+ $data['participants'] = implode(', ', $participantNames);
+ }
+
+ return $data;
}, $rooms, $formData->getHash()));
}
diff --git a/tests/integration/features/command/active-calls.feature b/tests/integration/features/command/active-calls.feature
new file mode 100644
index 00000000000..e7ab23b5c44
--- /dev/null
+++ b/tests/integration/features/command/active-calls.feature
@@ -0,0 +1,42 @@
+Feature: create
+
+ Background:
+ Given user "participant1" exists
+
+ Scenario: No call in progress
+ Given invoking occ with "talk:active-calls"
+ Then the command was successful
+ And the command output contains the text "No calls in progress"
+
+ Scenario: Users only chatting
+ When user "participant1" creates room "room"
+ | roomType | 3 |
+ | roomName | room |
+ Then user "participant1" joins room "room" with 200
+
+ Given invoking occ with "talk:active-calls"
+ Then the command was successful
+ And the command output contains the text "No calls in progress"
+
+ Then user "participant1" leaves room "room" with 200
+
+
+ Scenario: Call in progress
+ When user "participant1" creates room "room"
+ | roomType | 3 |
+ | roomName | room |
+
+ Then user "participant1" joins room "room" with 200
+ And user "participant1" joins call "room" with 200
+
+ Given invoking occ with "talk:active-calls"
+ # It didn't really fail, it just has an exit code that is not 0
+ Then the command failed with exit code 1
+ And the command output contains the text "There are currently 1 calls in progress with 1 participants"
+
+ Then user "participant1" leaves call "room" with 200
+ And user "participant1" leaves room "room" with 200
+
+ Given invoking occ with "talk:active-calls"
+ Then the command was successful
+ And the command output contains the text "No calls in progress"
diff --git a/tests/integration/features/command/create.feature b/tests/integration/features/command/create.feature
new file mode 100644
index 00000000000..4148a7aec8a
--- /dev/null
+++ b/tests/integration/features/command/create.feature
@@ -0,0 +1,53 @@
+Feature: create
+
+ Background:
+ Given user "participant1" exists
+ Given user "participant2" exists
+ Given group "group1" exists
+ Given user "participant2" is member of group "group1"
+
+ Scenario: Create a room group room for participant1
+ Given invoking occ with "talk:room:create room1 --user participant1"
+ And the command output contains the text "Room successfully created"
+ Then the command was successful
+ And user "participant1" is participant of the following rooms
+ | name | type | participantType | participants |
+ | room1 | 2 | 3 | participant1-displayname |
+
+ Scenario: Create a room group room for participant1 as moderator
+ Given invoking occ with "talk:room:create room1 --user participant1 --moderator participant1"
+ And the command output contains the text "Room successfully created"
+ Then the command was successful
+ And user "participant1" is participant of the following rooms
+ | name | type | participantType | participants |
+ | room1 | 2 | 2 | participant1-displayname |
+
+ Scenario: Create a room group room for participant1 as owner
+ Given invoking occ with "talk:room:create room1 --user participant1 --owner participant1"
+ And the command output contains the text "Room successfully created"
+ Then the command was successful
+ And user "participant1" is participant of the following rooms
+ | name | type | participantType | participants |
+ | room1 | 2 | 1 | participant1-displayname |
+
+ Scenario: Create a room public room for participant1 as owner group1 as users
+ Given invoking occ with "talk:room:create room1 --user participant1 --owner participant1 --public --group group1"
+ And the command output contains the text "Room successfully created"
+ Then the command was successful
+ And user "participant1" is participant of the following rooms
+ | name | type | participantType | participants |
+ | room1 | 3 | 1 | participant1-displayname, participant2-displayname |
+ And user "participant2" is participant of the following rooms
+ | name | type | participantType | participants |
+ | room1 | 3 | 3 | participant1-displayname, participant2-displayname |
+
+ Scenario: Create a room public room for participant1 as owner group1 as users with password and readonly
+ Given invoking occ with "talk:room:create room1 --user participant1 --owner participant1 --public --group group1 --readonly --password test"
+ And the command output contains the text "Room successfully created"
+ Then the command was successful
+ And user "participant1" is participant of the following rooms
+ | name | type | readOnly | hasPassword | participantType | participants |
+ | room1 | 3 | 1 | 1 | 1 | participant1-displayname, participant2-displayname |
+ And user "participant2" is participant of the following rooms
+ | name | type | readOnly | hasPassword | participantType | participants |
+ | room1 | 3 | 1 | 1 | 3 | participant1-displayname, participant2-displayname |
diff --git a/tests/integration/spreedcheats/lib/Controller/ApiController.php b/tests/integration/spreedcheats/lib/Controller/ApiController.php
index 8a14f21e7fa..358dbafb27b 100644
--- a/tests/integration/spreedcheats/lib/Controller/ApiController.php
+++ b/tests/integration/spreedcheats/lib/Controller/ApiController.php
@@ -57,7 +57,10 @@ public function resetSpreed() {
$query->delete('talk_rooms')->execute();
$query = $this->db->getQueryBuilder();
- $query->delete('talk_participants')->execute();
+ $query->delete('talk_attendees')->execute();
+
+ $query = $this->db->getQueryBuilder();
+ $query->delete('talk_sessions')->execute();
$query = $this->db->getQueryBuilder();
$query->delete('share')
diff --git a/tests/php/CapabilitiesTest.php b/tests/php/CapabilitiesTest.php
index b2a7f94456e..58c1a1e7691 100644
--- a/tests/php/CapabilitiesTest.php
+++ b/tests/php/CapabilitiesTest.php
@@ -97,6 +97,7 @@ public function testGetCapabilitiesGuest(): void {
'chat-replies',
'circles-support',
'force-mute',
+ 'sip-support',
],
'config' => [
'attachments' => [
@@ -188,6 +189,7 @@ public function testGetCapabilitiesUserAllowed(bool $isNotAllowed, bool $canCrea
'chat-replies',
'circles-support',
'force-mute',
+ 'sip-support',
'chat-reference-id',
],
'config' => [
diff --git a/tests/php/Chat/AutoComplete/SearchPluginTest.php b/tests/php/Chat/AutoComplete/SearchPluginTest.php
index 67e094f2fac..e7cb50051f2 100644
--- a/tests/php/Chat/AutoComplete/SearchPluginTest.php
+++ b/tests/php/Chat/AutoComplete/SearchPluginTest.php
@@ -24,8 +24,11 @@
use OCA\Talk\Chat\AutoComplete\SearchPlugin;
use OCA\Talk\Files\Util;
use OCA\Talk\GuestManager;
+use OCA\Talk\Model\Attendee;
+use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCA\Talk\TalkSession;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\IL10N;
@@ -41,6 +44,8 @@ class SearchPluginTest extends \Test\TestCase {
protected $guestManager;
/** @var TalkSession|MockObject */
protected $talkSession;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var Util|MockObject */
protected $util;
/** @var IL10N|MockObject */
@@ -56,6 +61,7 @@ public function setUp(): void {
$this->userManager = $this->createMock(IUserManager::class);
$this->guestManager = $this->createMock(GuestManager::class);
$this->talkSession = $this->createMock(TalkSession::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->util = $this->createMock(Util::class);
$this->userId = 'current';
$this->l = $this->createMock(IL10N::class);
@@ -76,6 +82,7 @@ protected function getPlugin(array $methods = []) {
$this->userManager,
$this->guestManager,
$this->talkSession,
+ $this->participantService,
$this->util,
$this->userId,
$this->l
@@ -87,6 +94,7 @@ protected function getPlugin(array $methods = []) {
$this->userManager,
$this->guestManager,
$this->talkSession,
+ $this->participantService,
$this->util,
$this->userId,
$this->l,
@@ -98,15 +106,24 @@ protected function getPlugin(array $methods = []) {
protected function createParticipantMock(string $uid, string $session = ''): Participant {
/** @var Participant|MockObject $p */
$p = $this->createMock(Participant::class);
+ $a = Attendee::fromRow([
+ 'actor_type' => $uid ? 'users' : 'guests',
+ 'actor_id' => $uid ? $uid : sha1($session),
+ ]);
+ $s = Session::fromRow([
+ 'session_id' => $session,
+ ]);
$p->expects($this->any())
- ->method('getUser')
- ->willReturn($uid);
+ ->method('getAttendee')
+ ->willReturn($a);
+ $p->expects($this->any())
+ ->method('getSession')
+ ->willReturn($s);
+
$p->expects($this->any())
->method('isGuest')
->willReturn($uid === '');
- $p->expects($this->any())
- ->method('getSessionId')
- ->willReturn($session);
+
return $p;
}
@@ -114,8 +131,9 @@ public function testSearch() {
$result = $this->createMock(ISearchResult::class);
$room = $this->createMock(Room::class);
- $room->expects($this->once())
- ->method('getParticipants')
+ $this->participantService->expects($this->once())
+ ->method('getParticipantsForRoom')
+ ->with($room)
->willReturn([
$this->createParticipantMock('123'),
$this->createParticipantMock('foo'),
diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php
index b3684e1ecc8..3cd63aefa2e 100644
--- a/tests/php/Chat/ChatManagerTest.php
+++ b/tests/php/Chat/ChatManagerTest.php
@@ -29,6 +29,7 @@
use OCA\Talk\Chat\Notifier;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
@@ -50,6 +51,8 @@ class ChatManagerTest extends TestCase {
protected $dispatcher;
/** @var INotificationManager|MockObject */
protected $notificationManager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var Notifier|MockObject */
protected $notifier;
/** @var ITimeFactory|MockObject */
@@ -63,6 +66,7 @@ public function setUp(): void {
$this->commentsManager = $this->createMock(CommentsManager::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->notificationManager = $this->createMock(INotificationManager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->notifier = $this->createMock(Notifier::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$cacheFactory = $this->createMock(ICacheFactory::class);
@@ -72,6 +76,7 @@ public function setUp(): void {
$this->dispatcher,
\OC::$server->getDatabaseConnection(),
$this->notificationManager,
+ $this->participantService,
$this->notifier,
$cacheFactory,
$this->timeFactory
diff --git a/tests/php/Chat/NotifierTest.php b/tests/php/Chat/NotifierTest.php
index 8c5827e4a4b..d0214a305e1 100644
--- a/tests/php/Chat/NotifierTest.php
+++ b/tests/php/Chat/NotifierTest.php
@@ -29,6 +29,7 @@
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Comments\IComment;
use OCP\IConfig;
use OCP\Notification\IManager as INotificationManager;
@@ -43,6 +44,8 @@ class NotifierTest extends TestCase {
protected $notificationManager;
/** @var IUserManager|MockObject */
protected $userManager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var Manager|MockObject */
protected $manager;
/** @var IConfig|MockObject */
@@ -65,6 +68,7 @@ public function setUp(): void {
return $userId !== 'unknownUser';
});
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->manager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);
$this->util = $this->createMock(Util::class);
@@ -72,6 +76,7 @@ public function setUp(): void {
$this->notifier = new Notifier(
$this->notificationManager,
$this->userManager,
+ $this->participantService,
$this->manager,
$this->config,
$this->util
diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php
index 955cfaf3c8e..2f45e0b96c0 100644
--- a/tests/php/Chat/Parser/SystemMessageTest.php
+++ b/tests/php/Chat/Parser/SystemMessageTest.php
@@ -24,7 +24,9 @@
use OCA\Talk\Chat\Parser\SystemMessage;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\GuestManager;
+use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\Message;
+use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Share\RoomShareProvider;
@@ -312,20 +314,32 @@ public function testParseMessage(string $message, array $parameters, $recipientI
/** @var Participant|MockObject $participant */
$participant = $this->createMock(Participant::class);
if ($recipientId && strpos($recipientId, 'guest::') !== false) {
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'guests',
+ 'actor_id' => substr($recipientId, strlen('guest::')),
+ ]);
+ $session = Session::fromRow([
+ 'session_id' => substr($recipientId, strlen('guest::')),
+ ]);
$participant->expects($this->atLeastOnce())
->method('isGuest')
->willReturn(true);
- $participant->expects($this->atLeastOnce())
- ->method('getSessionId')
- ->willReturn(substr($recipientId, strlen('guest::')));
} else {
$participant->expects($this->atLeastOnce())
->method('isGuest')
->willReturn(false);
- $participant->expects($this->atLeastOnce())
- ->method('getUser')
- ->willReturn($recipientId);
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => $recipientId,
+ ]);
+ $session = null;
}
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
+ $participant->expects($this->any())
+ ->method('getSession')
+ ->willReturn($session);
/** @var IComment|MockObject $comment */
$comment = $this->createMock(IComment::class);
@@ -520,9 +534,13 @@ public function testGetFileFromShareForOwner() {
$participant->expects($this->once())
->method('isGuest')
->willReturn(false);
- $participant->expects($this->once())
- ->method('getUser')
- ->willReturn('owner');
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'owner',
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$parser = $this->getParser();
$this->assertSame([
@@ -557,9 +575,13 @@ public function testGetFileFromShareForRecipient() {
$participant->expects($this->once())
->method('isGuest')
->willReturn(false);
- $participant->expects($this->exactly(2))
- ->method('getUser')
- ->willReturn('user');
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'user',
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$this->shareProvider->expects($this->once())
->method('getShareById')
@@ -627,9 +649,13 @@ public function testGetFileFromShareForRecipientThrows() {
$participant->expects($this->once())
->method('isGuest')
->willReturn(false);
- $participant->expects($this->exactly(3))
- ->method('getUser')
- ->willReturn('user');
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'user',
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$this->shareProvider->expects($this->once())
->method('getShareById')
diff --git a/tests/php/Collaboration/Collaborators/RoomPluginTest.php b/tests/php/Collaboration/Collaborators/RoomPluginTest.php
index 424fbefcb3e..31f785332e6 100644
--- a/tests/php/Collaboration/Collaborators/RoomPluginTest.php
+++ b/tests/php/Collaboration/Collaborators/RoomPluginTest.php
@@ -234,7 +234,7 @@ public function testSearch(
bool $expectedHasMoreResults
) {
$this->manager->expects($this->any())
- ->method('getRoomsForParticipant')
+ ->method('getRoomsForUser')
->with('user0')
->willReturn($roomsForParticipant);
diff --git a/tests/php/Collaboration/Resources/ConversationProviderTest.php b/tests/php/Collaboration/Resources/ConversationProviderTest.php
index c76c5a752db..df80d82ed7d 100644
--- a/tests/php/Collaboration/Resources/ConversationProviderTest.php
+++ b/tests/php/Collaboration/Resources/ConversationProviderTest.php
@@ -27,6 +27,7 @@
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
+use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\Collaboration\Resources\IResource;
@@ -81,7 +82,7 @@ public function testCanAccessResourceThrowsRoom(): void {
->willReturn('token');
$this->manager->expects($this->once())
- ->method('getRoomForParticipantByToken')
+ ->method('getRoomForUserByToken')
->with('token', 'uid')
->willThrowException(new RoomNotFoundException());
@@ -105,7 +106,7 @@ public function testCanAccessResourceThrowsParticipant(): void {
->willThrowException(new ParticipantNotFoundException());
$this->manager->expects($this->once())
- ->method('getRoomForParticipantByToken')
+ ->method('getRoomForUserByToken')
->with('token', 'uid')
->willReturn($room);
@@ -124,9 +125,14 @@ public function testCanAccessResourceParticipantNotAdded(): void {
->willReturn('token');
$participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('getParticipantType')
- ->willReturn(Participant::USER_SELF_JOINED);
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'uid',
+ 'participant_type' => Participant::USER_SELF_JOINED,
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$room = $this->createMock(Room::class);
$room->expects($this->once())
->method('getParticipant')
@@ -134,7 +140,7 @@ public function testCanAccessResourceParticipantNotAdded(): void {
->willReturn($participant);
$this->manager->expects($this->once())
- ->method('getRoomForParticipantByToken')
+ ->method('getRoomForUserByToken')
->with('token', 'uid')
->willReturn($room);
@@ -164,9 +170,14 @@ public function testCanAccessResourceYes(int $participantType): void {
->willReturn('token');
$participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('getParticipantType')
- ->willReturn($participantType);
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'uid',
+ 'participant_type' => $participantType,
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$room = $this->createMock(Room::class);
$room->expects($this->once())
->method('getParticipant')
@@ -174,7 +185,7 @@ public function testCanAccessResourceYes(int $participantType): void {
->willReturn($participant);
$this->manager->expects($this->once())
- ->method('getRoomForParticipantByToken')
+ ->method('getRoomForUserByToken')
->with('token', 'uid')
->willReturn($room);
diff --git a/tests/php/Command/Room/AddTest.php b/tests/php/Command/Room/AddTest.php
deleted file mode 100644
index b0583d0f9b5..00000000000
--- a/tests/php/Command/Room/AddTest.php
+++ /dev/null
@@ -1,337 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use OCA\Talk\Command\Room\Add;
-use OCA\Talk\Exceptions\RoomNotFoundException;
-use OCA\Talk\Manager;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
-use Symfony\Component\Console\Tester\CommandTester;
-use Test\TestCase;
-
-class AddTest extends TestCase {
- use TRoomCommandTest;
-
- /** @var Add */
- private $command;
-
- /** @var Manager|MockObject */
- private $manager;
-
- /** @var RoomService|MockObject */
- private $roomService;
-
- /** @var RoomMockContainer */
- private $roomMockContainer;
-
- public function setUp(): void {
- parent::setUp();
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->command = new Add(
- $this->manager,
- $this->roomService,
- $this->userManager,
- $this->groupManager
- );
-
- $this->roomMockContainer = new RoomMockContainer($this);
-
- $this->createTestUserMocks();
- $this->createTestGroupMocks();
- }
-
- public function testMissingArguments(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "token").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([]);
- }
-
- /**
- * @dataProvider validProvider
- */
- public function testValid(array $input, array $expectedRoomData, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals("Users successfully added to room.\n", $tester->getDisplay());
-
- $this->assertEquals($expectedRoomData, $this->roomMockContainer->getRoomData());
- }
-
- public function validProvider(): array {
- return [
- [
- [
- 'token' => '__test-room',
- ],
- RoomMockContainer::prepareRoomData([]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--user' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--user' => ['user1', 'user2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--user' => ['user2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--user' => ['user3'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ['userId' => 'user3', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--group' => ['group1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--group' => ['group1', 'group2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ['userId' => 'user3', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--group' => ['group1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--group' => ['group1', 'group2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ['userId' => 'user4', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ['userId' => 'user3', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ['userId' => 'user4', 'participantType' => Participant::MODERATOR],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--group' => ['group1'],
- '--user' => ['user4'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user4', 'participantType' => Participant::USER],
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--group' => ['group1'],
- '--user' => ['user4'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user3', 'participantType' => Participant::USER],
- ['userId' => 'user4', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user3', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- ];
- }
-
- /**
- * @dataProvider invalidProvider
- */
- public function testInvalid(array $input, string $expectedOutput, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals($expectedOutput, $tester->getDisplay());
- }
-
- public function invalidProvider(): array {
- return [
- [
- [
- 'token' => '__test-invalid',
- ],
- "Room not found.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- ],
- "Room is no group call.\n",
- RoomMockContainer::prepareRoomData([
- 'type' => Room::ONE_TO_ONE_CALL,
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--user' => ['user1','invalid']
- ],
- "User 'invalid' not found.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--group' => ['group1','invalid']
- ],
- "Group 'invalid' not found.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- ];
- }
-}
diff --git a/tests/php/Command/Room/CreateTest.php b/tests/php/Command/Room/CreateTest.php
deleted file mode 100644
index 762d5dad3bc..00000000000
--- a/tests/php/Command/Room/CreateTest.php
+++ /dev/null
@@ -1,362 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use InvalidArgumentException;
-use OCA\Talk\Command\Room\Create;
-use OCA\Talk\Manager;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
-use Symfony\Component\Console\Tester\CommandTester;
-use Test\TestCase;
-
-class CreateTest extends TestCase {
- use TRoomCommandTest;
-
- /** @var Create */
- private $command;
-
- /** @var Manager|MockObject */
- private $manager;
-
- /** @var RoomService|MockObject */
- private $roomService;
-
- /** @var RoomMockContainer */
- private $roomMockContainer;
-
- public function setUp(): void {
- parent::setUp();
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->command = new Create(
- $this->manager,
- $this->roomService,
- $this->userManager,
- $this->groupManager
- );
-
- $this->roomMockContainer = new RoomMockContainer($this);
-
- $this->createTestUserMocks();
- $this->createTestGroupMocks();
- }
-
- public function testMissingArguments(): void {
- $this->roomService->expects($this->never())
- ->method('createConversation');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "name").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([]);
- }
-
- /**
- * @dataProvider validProvider
- */
- public function testValid(array $input, array $expectedRoomData): void {
- $this->roomService
- ->method('createConversation')
- ->willReturnCallback(function (int $type, string $name): Room {
- return $this->roomMockContainer->create(['name' => $name, 'type' => $type]);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals("Room successfully created.\n", $tester->getDisplay());
-
- $this->assertEquals($expectedRoomData, $this->roomMockContainer->getRoomData());
- }
-
- public function validProvider(): array {
- return [
- [
- [
- 'name' => 'PHPUnit Test Room',
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--public' => true,
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'type' => Room::PUBLIC_CALL,
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--readonly' => true,
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'readOnly' => Room::READ_ONLY,
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--public' => true,
- '--password' => 'my-secret-password',
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'type' => Room::PUBLIC_CALL,
- 'password' => 'my-secret-password',
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--user' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--user' => ['user1', 'user2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--user' => ['user1', 'user2'],
- '--moderator' => ['user2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::MODERATOR],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--user' => ['user1', 'user2', 'user3'],
- '--moderator' => ['user2', 'user3'],
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user3', 'participantType' => Participant::MODERATOR],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--user' => ['user1', 'user2'],
- '--owner' => 'user2',
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::OWNER],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--group' => ['group1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--group' => ['group1', 'group2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ['userId' => 'user3', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--group' => ['group1'],
- '--user' => ['user4'],
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user4', 'participantType' => Participant::USER],
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--group' => ['group1'],
- '--moderator' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--group' => ['group1'],
- '--owner' => 'user1',
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room',
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- ];
- }
-
- /**
- * @dataProvider invalidProvider
- */
- public function testInvalid(array $input, string $expectedOutput): void {
- if ($input['name'] !== 'PHPUnit Test Room') {
- $this->roomService
- ->method('createConversation')
- ->willThrowException(new InvalidArgumentException('name'));
- } else {
- $this->roomService
- ->method('createConversation')
- ->willReturnCallback(function (int $type, string $name): Room {
- return $this->roomMockContainer->create(['name' => $name, 'type' => $type]);
- });
- }
-
- $this->roomMockContainer->registerCallback(function (object $room) {
- /** @var Room|MockObject $room */
- $room->expects($this->once())
- ->method('deleteRoom');
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals($expectedOutput, $tester->getDisplay());
- }
-
- public function invalidProvider(): array {
- return [
- [
- [
- 'name' => '',
- ],
- "Invalid room name.\n",
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--password' => 'my-secret-password',
- ],
- "Unable to add password protection to private room.\n",
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--user' => ['user1','invalid'],
- ],
- "User 'invalid' not found.\n",
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--group' => ['group1','invalid'],
- ],
- "Group 'invalid' not found.\n",
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--user' => ['user1'],
- '--moderator' => ['user2'],
- ],
- "User 'user2' is no participant.\n",
- ],
- [
- [
- 'name' => 'PHPUnit Test Room',
- '--user' => ['user1'],
- '--owner' => 'user2',
- ],
- "User 'user2' is no participant.\n",
- ],
- ];
- }
-}
diff --git a/tests/php/Command/Room/DeleteTest.php b/tests/php/Command/Room/DeleteTest.php
deleted file mode 100644
index 2c938ada57b..00000000000
--- a/tests/php/Command/Room/DeleteTest.php
+++ /dev/null
@@ -1,159 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use OCA\Talk\Command\Room\Delete;
-use OCA\Talk\Exceptions\RoomNotFoundException;
-use OCA\Talk\Manager;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
-use Symfony\Component\Console\Tester\CommandTester;
-use Test\TestCase;
-
-class DeleteTest extends TestCase {
- use TRoomCommandTest;
-
- /** @var Delete */
- private $command;
-
- /** @var Manager|MockObject */
- private $manager;
-
- /** @var RoomService|MockObject */
- private $roomService;
-
- /** @var RoomMockContainer */
- private $roomMockContainer;
-
- public function setUp(): void {
- parent::setUp();
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->command = new Delete(
- $this->manager,
- $this->roomService,
- $this->userManager,
- $this->groupManager
- );
-
- $this->roomMockContainer = new RoomMockContainer($this);
- }
-
- public function testMissingArguments(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "token").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([]);
- }
-
- /**
- * @dataProvider validProvider
- */
- public function testValid(array $input, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $this->roomMockContainer->registerCallback(function (object $room) {
- /** @var Room|MockObject $room */
- $room->expects($this->once())
- ->method('deleteRoom');
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals("Room successfully deleted.\n", $tester->getDisplay());
- }
-
- public function validProvider(): array {
- return [
- [
- [
- 'token' => '__test-room',
- ],
- RoomMockContainer::prepareRoomData([]),
- ],
- ];
- }
-
- /**
- * @dataProvider invalidProvider
- */
- public function testInvalid(array $input, string $expectedOutput, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals($expectedOutput, $tester->getDisplay());
- }
-
- public function invalidProvider(): array {
- return [
- [
- [
- 'token' => '__test-invalid',
- ],
- "Room not found.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- ],
- "Room is no group call.\n",
- RoomMockContainer::prepareRoomData([
- 'type' => Room::ONE_TO_ONE_CALL,
- ]),
- ],
- ];
- }
-}
diff --git a/tests/php/Command/Room/DemoteTest.php b/tests/php/Command/Room/DemoteTest.php
deleted file mode 100644
index b2ea5e78d1d..00000000000
--- a/tests/php/Command/Room/DemoteTest.php
+++ /dev/null
@@ -1,257 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use OCA\Talk\Command\Room\Demote;
-use OCA\Talk\Exceptions\RoomNotFoundException;
-use OCA\Talk\Manager;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
-use Symfony\Component\Console\Tester\CommandTester;
-use Test\TestCase;
-
-class DemoteTest extends TestCase {
- use TRoomCommandTest;
-
- /** @var Demote */
- private $command;
-
- /** @var Manager|MockObject */
- private $manager;
-
- /** @var RoomService|MockObject */
- private $roomService;
-
- /** @var RoomMockContainer */
- private $roomMockContainer;
-
- public function setUp(): void {
- parent::setUp();
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->command = new Demote(
- $this->manager,
- $this->roomService,
- $this->userManager,
- $this->groupManager
- );
-
- $this->roomMockContainer = new RoomMockContainer($this);
-
- $this->createTestUserMocks();
- $this->createTestGroupMocks();
- }
-
- public function testMissingArguments(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "token, participant").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([]);
- }
-
- public function testMissingArgumentParticipant(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "participant").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([
- 'token' => '__test-room',
- ]);
- }
-
- /**
- * @dataProvider validProvider
- */
- public function testValid(array $input, array $expectedRoomData, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals("Participants successfully demoted to regular users.\n", $tester->getDisplay());
-
- $this->assertEquals($expectedRoomData, $this->roomMockContainer->getRoomData());
- }
-
- public function validProvider(): array {
- return [
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1', 'user2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user2', 'participantType' => Participant::MODERATOR],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- ];
- }
-
- /**
- * @dataProvider invalidProvider
- */
- public function testInvalid(array $input, string $expectedOutput, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals($expectedOutput, $tester->getDisplay());
- }
-
- public function invalidProvider(): array {
- return [
- [
- [
- 'token' => '__test-invalid',
- 'participant' => [''],
- ],
- "Room not found.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => [''],
- ],
- "Room is no group call.\n",
- RoomMockContainer::prepareRoomData([
- 'type' => Room::ONE_TO_ONE_CALL,
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1','invalid']
- ],
- "User 'user1' is no participant.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1','invalid']
- ],
- "User 'invalid' is no participant.\n",
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- ];
- }
-}
diff --git a/tests/php/Command/Room/PromoteTest.php b/tests/php/Command/Room/PromoteTest.php
deleted file mode 100644
index f27139365c0..00000000000
--- a/tests/php/Command/Room/PromoteTest.php
+++ /dev/null
@@ -1,241 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use OCA\Talk\Command\Room\Promote;
-use OCA\Talk\Exceptions\RoomNotFoundException;
-use OCA\Talk\Manager;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
-use Symfony\Component\Console\Tester\CommandTester;
-use Test\TestCase;
-
-class PromoteTest extends TestCase {
- use TRoomCommandTest;
-
- /** @var Promote */
- private $command;
-
- /** @var Manager|MockObject */
- private $manager;
-
- /** @var RoomService|MockObject */
- private $roomService;
-
- /** @var RoomMockContainer */
- private $roomMockContainer;
-
- public function setUp(): void {
- parent::setUp();
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->command = new Promote(
- $this->manager,
- $this->roomService,
- $this->userManager,
- $this->groupManager
- );
-
- $this->roomMockContainer = new RoomMockContainer($this);
-
- $this->createTestUserMocks();
- $this->createTestGroupMocks();
- }
-
- public function testMissingArguments(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "token, participant").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([]);
- }
-
- public function testMissingArgumentParticipant(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "participant").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([
- 'token' => '__test-room',
- ]);
- }
-
- /**
- * @dataProvider validProvider
- */
- public function testValid(array $input, array $expectedRoomData, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals("Participants successfully promoted to moderators.\n", $tester->getDisplay());
-
- $this->assertEquals($expectedRoomData, $this->roomMockContainer->getRoomData());
- }
-
- public function validProvider(): array {
- return [
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1', 'user2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::MODERATOR],
- ['userId' => 'user2', 'participantType' => Participant::MODERATOR],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ],
- ]),
- ],
- ];
- }
-
- /**
- * @dataProvider invalidProvider
- */
- public function testInvalid(array $input, string $expectedOutput, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals($expectedOutput, $tester->getDisplay());
- }
-
- public function invalidProvider(): array {
- return [
- [
- [
- 'token' => '__test-invalid',
- 'participant' => [''],
- ],
- "Room not found.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => [''],
- ],
- "Room is no group call.\n",
- RoomMockContainer::prepareRoomData([
- 'type' => Room::ONE_TO_ONE_CALL,
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1','invalid']
- ],
- "User 'user1' is no participant.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1','invalid']
- ],
- "User 'invalid' is no participant.\n",
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- ];
- }
-}
diff --git a/tests/php/Command/Room/RemoveTest.php b/tests/php/Command/Room/RemoveTest.php
deleted file mode 100644
index 737d75ba3e3..00000000000
--- a/tests/php/Command/Room/RemoveTest.php
+++ /dev/null
@@ -1,224 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use OCA\Talk\Command\Room\Remove;
-use OCA\Talk\Exceptions\RoomNotFoundException;
-use OCA\Talk\Manager;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
-use Symfony\Component\Console\Tester\CommandTester;
-use Test\TestCase;
-
-class RemoveTest extends TestCase {
- use TRoomCommandTest;
-
- /** @var Remove */
- private $command;
-
- /** @var Manager|MockObject */
- private $manager;
-
- /** @var RoomService|MockObject */
- private $roomService;
-
- /** @var RoomMockContainer */
- private $roomMockContainer;
-
- public function setUp(): void {
- parent::setUp();
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->command = new Remove(
- $this->manager,
- $this->roomService,
- $this->userManager,
- $this->groupManager
- );
-
- $this->roomMockContainer = new RoomMockContainer($this);
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->createTestUserMocks();
- $this->createTestGroupMocks();
- }
-
- public function testMissingArguments(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "token, participant").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([]);
- }
-
- public function testMissingArgumentUser(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "participant").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([
- 'token' => '__test-room',
- ]);
- }
-
- /**
- * @dataProvider validProvider
- */
- public function testValid(array $input, array $expectedRoomData, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals("Users successfully removed from room.\n", $tester->getDisplay());
-
- $this->assertEquals($expectedRoomData, $this->roomMockContainer->getRoomData());
- }
-
- public function validProvider(): array {
- return [
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1'],
- ],
- RoomMockContainer::prepareRoomData([]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1', 'user2'],
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user3', 'participantType' => Participant::USER],
- ['userId' => 'user4', 'participantType' => Participant::MODERATOR],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ['userId' => 'user3', 'participantType' => Participant::USER],
- ['userId' => 'user4', 'participantType' => Participant::MODERATOR],
- ],
- ]),
- ],
- ];
- }
-
- /**
- * @dataProvider invalidProvider
- */
- public function testInvalid(array $input, string $expectedOutput, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals($expectedOutput, $tester->getDisplay());
- }
-
- public function invalidProvider(): array {
- return [
- [
- [
- 'token' => '__test-invalid',
- 'participant' => [''],
- ],
- "Room not found.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => [''],
- ],
- "Room is no group call.\n",
- RoomMockContainer::prepareRoomData([
- 'type' => Room::ONE_TO_ONE_CALL,
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1','invalid']
- ],
- "User 'user1' is no participant.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- 'participant' => ['user1','invalid']
- ],
- "User 'invalid' is no participant.\n",
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- ];
- }
-}
diff --git a/tests/php/Command/Room/RoomMockContainer.php b/tests/php/Command/Room/RoomMockContainer.php
deleted file mode 100644
index abe712a1abc..00000000000
--- a/tests/php/Command/Room/RoomMockContainer.php
+++ /dev/null
@@ -1,221 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use InvalidArgumentException;
-use OCA\Talk\Exceptions\ParticipantNotFoundException;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCP\IUser;
-use PHPUnit\Framework\MockObject\MockObject;
-use PHPUnit\Framework\TestCase;
-
-class RoomMockContainer {
- /** @var TestCase */
- private $testCase;
-
- /** @var callable[] */
- private $callbacks = [];
-
- /** @var Room|null */
- private $room;
-
- /** @var array|null */
- private $roomData;
-
- /** @var Participant[] */
- private $participants = [];
-
- /** @var array[] */
- private $participantData = [];
-
- public function __construct(TestCase $testCase) {
- $this->testCase = $testCase;
- }
-
- public function create(array $data = []): Room {
- if ($this->room !== null) {
- throw new InvalidArgumentException(__METHOD__ . ' must not be called multiple times.');
- }
-
- /** @var Room|MockObject $room */
- $room = $this->createMock(Room::class);
-
- $this->room = $room;
- $this->roomData = self::prepareRoomData($data);
-
- // simple getter
- foreach (['token', 'name', 'type', 'readOnly'] as $key) {
- $room->method('get' . ucfirst($key))
- ->willReturnCallback(function () use ($key) {
- return $this->roomData[$key];
- });
- }
-
- // simple setter
- foreach (['name', 'type', 'readOnly', 'password'] as $key) {
- $room->method('set' . ucfirst($key))
- ->willReturnCallback(function ($value) use ($key): bool {
- $this->roomData[$key] = $value;
- return true;
- });
- }
-
- // password
- $room->method('hasPassword')
- ->willReturnCallback(function (): bool {
- return $this->roomData['password'] !== '';
- });
-
- $room->method('verifyPassword')
- ->willReturnCallback(function (string $password): array {
- return [
- 'result' => in_array($this->roomData['password'], ['', $password], true),
- 'url' => '',
- ];
- });
-
- // participants
- $room->method('getParticipants')
- ->willReturnCallback(function (): array {
- return $this->participants;
- });
-
- $room->method('getParticipant')
- ->willReturnCallback(function (?string $userId): Participant {
- if (in_array($userId, [null, ''], true)) {
- throw new ParticipantNotFoundException('Not a user');
- }
- if (!isset($this->participants[$userId])) {
- throw new ParticipantNotFoundException('User is not a participant');
- }
-
- return $this->participants[$userId];
- });
-
- $room->method('addUsers')
- ->willReturnCallback(function (array ...$participants): void {
- foreach ($participants as $participant) {
- $userId = $participant['userId'];
- $participantType = $participant['participantType'] ?? Participant::USER;
-
- $this->createParticipant($userId, ['participantType' => $participantType]);
- }
- });
-
- $room->method('removeUser')
- ->willReturnCallback(function (IUser $user): void {
- $this->removeParticipant($user->getUID());
- });
-
- $room->method('setParticipantType')
- ->willReturnCallback(function (Participant $participant, int $participantType): void {
- $userId = $participant->getUser();
- $this->updateParticipant($userId, ['participantType' => $participantType]);
- });
-
- // add participants
- foreach ($this->roomData['participants'] as $participant) {
- $userId = $participant['userId'];
- $participantType = $participant['participantType'] ?? Participant::USER;
-
- $this->createParticipant($userId, ['participantType' => $participantType]);
- }
-
- unset($this->roomData['participants']);
-
- // execute callbacks
- foreach ($this->callbacks as $callback) {
- $callback($room);
- }
-
- return $room;
- }
-
- protected function createParticipant(string $userId, array $data): Participant {
- /** @var Participant|MockObject $participant */
- $participant = $this->createMock(Participant::class);
-
- $this->participants[$userId] = $participant;
- $this->participantData[$userId] = ['userId' => $userId] + $data;
-
- $participant->method('getUser')
- ->willReturnCallback(function () use ($userId): string {
- return $this->participantData[$userId]['userId'];
- });
-
- $participant->method('getParticipantType')
- ->willReturnCallback(function () use ($userId): int {
- return $this->participantData[$userId]['participantType'];
- });
-
- return $participant;
- }
-
- protected function updateParticipant(string $userId, array $data): void {
- $this->participantData[$userId] = array_merge($this->participantData[$userId], $data);
- }
-
- protected function removeParticipant(string $userId): void {
- unset($this->participants[$userId], $this->participantData[$userId]);
- }
-
- public function registerCallback(callable $callback): void {
- $this->callbacks[] = $callback;
- }
-
- protected function createMock(string $originalClassName): MockObject {
- return $this->testCase->getMockBuilder($originalClassName)
- ->disableOriginalConstructor()
- ->disableOriginalClone()
- ->disableArgumentCloning()
- ->disallowMockingUnknownTypes()
- ->disableAutoReturnValueGeneration()
- ->getMock();
- }
-
- public function getRoom(): ?Room {
- return $this->room;
- }
-
- public function getRoomData(): ?array {
- $participants = array_values($this->participantData);
- return $this->roomData + ['participants' => $participants];
- }
-
- public static function prepareRoomData(array $data): array {
- $data += [
- 'token' => '__test-room',
- 'name' => 'PHPUnit Test Room',
- 'type' => Room::GROUP_CALL,
- 'readOnly' => Room::READ_WRITE,
- 'password' => '',
- 'participants' => [],
- ];
-
- return $data;
- }
-}
diff --git a/tests/php/Command/Room/TRoomCommandTest.php b/tests/php/Command/Room/TRoomCommandTest.php
deleted file mode 100644
index 1757d889541..00000000000
--- a/tests/php/Command/Room/TRoomCommandTest.php
+++ /dev/null
@@ -1,125 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use OCP\IGroup;
-use OCP\IGroupManager;
-use OCP\IUser;
-use OCP\IUserManager;
-use PHPUnit\Framework\MockObject\MockObject;
-
-trait TRoomCommandTest {
- /** @var IUserManager|MockObject */
- protected $userManager;
-
- /** @var IGroupManager|MockObject */
- protected $groupManager;
-
- /** @var IUser[] */
- private $userMocks;
-
- /** @var IGroup[] */
- private $groupMocks;
-
- protected function registerUserManagerMock(): void {
- $this->userManager = $this->createMock(IUserManager::class);
-
- $this->userManager->method('get')
- ->willReturnCallback([$this, 'getUserMock']);
-
- $this->overwriteService(IUserManager::class, $this->userManager);
- }
-
- protected function createTestUserMocks(): void {
- $this->createUserMock('user1');
- $this->createUserMock('user2');
- $this->createUserMock('user3');
- $this->createUserMock('user4');
- $this->createUserMock('other');
- }
-
- public function getUserMock(string $uid): ?IUser {
- return $this->userMocks[$uid] ?? null;
- }
-
- protected function createUserMock(string $uid): IUser {
- /** @var IUser|MockObject $user */
- $user = $this->createMock(IUser::class);
-
- $this->userMocks[$uid] = $user;
-
- $user->method('getUID')
- ->willReturn($uid);
-
- return $user;
- }
-
- protected function registerGroupManagerMock(): void {
- $this->groupManager = $this->createMock(IGroupManager::class);
-
- $this->groupManager->method('get')
- ->willReturnCallback([$this, 'getGroupMock']);
-
- $this->overwriteService(IGroupManager::class, $this->groupManager);
- }
-
- protected function createTestGroupMocks(): void {
- $this->createGroupMock('group1', ['user1', 'user2']);
- $this->createGroupMock('group2', ['user2', 'user3']);
- $this->createGroupMock('other', ['other']);
- }
-
- public function getGroupMock(string $gid): ?IGroup {
- return $this->groupMocks[$gid] ?? null;
- }
-
- protected function createGroupMock(string $gid, array $userIds): IGroup {
- /** @var IGroup|MockObject $group */
- $group = $this->createMock(IGroup::class);
-
- $this->groupMocks[$gid] = $group;
-
- $group->method('getGID')
- ->willReturn($gid);
-
- $group->method('getUsers')
- ->willReturnCallback(function () use ($userIds) {
- return array_map([$this, 'getUserMock'], $userIds);
- });
-
- return $group;
- }
-
- protected function createMock($originalClassName): MockObject {
- return $this->getMockBuilder($originalClassName)
- ->disableOriginalConstructor()
- ->disableOriginalClone()
- ->disableArgumentCloning()
- ->disallowMockingUnknownTypes()
- ->disableAutoReturnValueGeneration()
- ->getMock();
- }
-}
diff --git a/tests/php/Command/Room/UpdateTest.php b/tests/php/Command/Room/UpdateTest.php
deleted file mode 100644
index dc7f11d6bee..00000000000
--- a/tests/php/Command/Room/UpdateTest.php
+++ /dev/null
@@ -1,362 +0,0 @@
-
- *
- * @author Daniel Rudolf
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- *
- */
-
-namespace OCA\Talk\Tests\php\Command\Room;
-
-use OCA\Talk\Command\Room\Update;
-use OCA\Talk\Exceptions\RoomNotFoundException;
-use OCA\Talk\Manager;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use PHPUnit\Framework\MockObject\MockObject;
-use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
-use Symfony\Component\Console\Tester\CommandTester;
-use Test\TestCase;
-
-class UpdateTest extends TestCase {
- use TRoomCommandTest;
-
- /** @var Update */
- private $command;
-
- /** @var Manager|MockObject */
- private $manager;
-
- /** @var RoomService|MockObject */
- private $roomService;
-
- /** @var RoomMockContainer */
- private $roomMockContainer;
-
- public function setUp(): void {
- parent::setUp();
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->command = new Update(
- $this->manager,
- $this->roomService,
- $this->userManager,
- $this->groupManager
- );
-
- $this->roomMockContainer = new RoomMockContainer($this);
-
- $this->registerUserManagerMock();
- $this->registerGroupManagerMock();
-
- $this->createTestUserMocks();
- $this->createTestGroupMocks();
- }
-
- public function testMissingArguments(): void {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
-
- $this->expectException(ConsoleRuntimeException::class);
- $this->expectExceptionMessage('Not enough arguments (missing: "token").');
-
- $tester = new CommandTester($this->command);
- $tester->execute([]);
- }
-
- /**
- * @dataProvider validProvider
- */
- public function testValid(array $input, array $expectedRoomData, array $initialRoomData): void {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals("Room successfully updated.\n", $tester->getDisplay());
-
- $this->assertEquals($expectedRoomData, $this->roomMockContainer->getRoomData());
- }
-
- public function validProvider(): array {
- return [
- [
- [
- 'token' => '__test-room',
- ],
- RoomMockContainer::prepareRoomData([]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--name' => 'PHPUnit Test Room 2'
- ],
- RoomMockContainer::prepareRoomData([
- 'name' => 'PHPUnit Test Room 2',
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--public' => '1'
- ],
- RoomMockContainer::prepareRoomData([
- 'type' => Room::PUBLIC_CALL,
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--public' => '0'
- ],
- RoomMockContainer::prepareRoomData([]),
- RoomMockContainer::prepareRoomData([
- 'type' => Room::PUBLIC_CALL,
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--readonly' => '1'
- ],
- RoomMockContainer::prepareRoomData([
- 'readOnly' => Room::READ_ONLY,
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--readonly' => '0'
- ],
- RoomMockContainer::prepareRoomData([]),
- RoomMockContainer::prepareRoomData([
- 'readOnly' => Room::READ_ONLY,
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--readonly' => '1'
- ],
- RoomMockContainer::prepareRoomData([
- 'readOnly' => Room::READ_ONLY,
- ]),
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--password' => 'my-secret-password'
- ],
- RoomMockContainer::prepareRoomData([
- 'type' => Room::PUBLIC_CALL,
- 'password' => 'my-secret-password',
- ]),
- RoomMockContainer::prepareRoomData([
- 'type' => Room::PUBLIC_CALL,
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--password' => ''
- ],
- RoomMockContainer::prepareRoomData([
- 'type' => Room::PUBLIC_CALL,
- ]),
- RoomMockContainer::prepareRoomData([
- 'type' => Room::PUBLIC_CALL,
- 'password' => 'my-secret-password',
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--owner' => 'user1'
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--owner' => 'user2'
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::OWNER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--owner' => ''
- ],
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::USER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- RoomMockContainer::prepareRoomData([
- 'participants' => [
- ['userId' => 'user1', 'participantType' => Participant::OWNER],
- ['userId' => 'user2', 'participantType' => Participant::USER],
- ],
- ]),
- ],
- ];
- }
-
- /**
- * @dataProvider invalidProvider
- */
- public function testInvalid(array $input, string $expectedOutput, array $initialRoomData = null): void {
- if ($initialRoomData !== null) {
- $this->manager->expects($this->once())
- ->method('getRoomByToken')
- ->willReturnCallback(function (string $token) use ($initialRoomData): Room {
- if ($token !== $initialRoomData['token']) {
- throw new RoomNotFoundException();
- }
-
- return $this->roomMockContainer->create($initialRoomData);
- });
- } else {
- $this->manager->expects($this->never())
- ->method('getRoomByToken');
- }
-
- $tester = new CommandTester($this->command);
- $tester->execute($input);
-
- $this->assertEquals($expectedOutput, $tester->getDisplay());
- }
-
- public function invalidProvider(): array {
- return [
- [
- [
- 'token' => '__test-room',
- '--public' => '',
- ],
- "Invalid value for option \"--public\" given.\n",
- ],
- [
- [
- 'token' => '__test-room',
- '--readonly' => '',
- ],
- "Invalid value for option \"--readonly\" given.\n",
- ],
- [
- [
- 'token' => '__test-invalid',
- ],
- "Room not found.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- ],
- "Room is no group call.\n",
- RoomMockContainer::prepareRoomData([
- 'type' => Room::ONE_TO_ONE_CALL,
- ]),
- ],
- [
- [
- 'token' => '__test-room',
- '--name' => '',
- ],
- "Invalid room name.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--name' => ' ',
- ],
- "Invalid room name.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--name' => str_repeat('x', 256),
- ],
- "Invalid room name.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--password' => 'my-secret-password',
- ],
- "Unable to add password protection to private room.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- [
- [
- 'token' => '__test-room',
- '--owner' => 'invalid',
- ],
- "User 'invalid' is no participant.\n",
- RoomMockContainer::prepareRoomData([]),
- ],
- ];
- }
-}
diff --git a/tests/php/Controller/ChatControllerTest.php b/tests/php/Controller/ChatControllerTest.php
index 1143546b116..7b7dddd622b 100644
--- a/tests/php/Controller/ChatControllerTest.php
+++ b/tests/php/Controller/ChatControllerTest.php
@@ -31,6 +31,8 @@
use OCA\Talk\Model\Message;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
+use OCA\Talk\Service\SessionService;
use OCA\Talk\TalkSession;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
@@ -61,6 +63,10 @@ class ChatControllerTest extends TestCase {
private $appManager;
/** @var ChatManager|MockObject */
protected $chatManager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
+ /** @var SessionService|MockObject */
+ protected $sessionService;
/** @var GuestManager|MockObject */
protected $guestManager;
/** @var MessageParser|MockObject */
@@ -97,6 +103,8 @@ public function setUp(): void {
$this->session = $this->createMock(TalkSession::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->chatManager = $this->createMock(ChatManager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
+ $this->sessionService = $this->createMock(SessionService::class);
$this->guestManager = $this->createMock(GuestManager::class);
$this->messageParser = $this->createMock(MessageParser::class);
$this->autoCompleteManager = $this->createMock(IManager::class);
@@ -128,14 +136,16 @@ private function recreateChatController() {
$this->session,
$this->appManager,
$this->chatManager,
+ $this->participantService,
+ $this->sessionService,
$this->guestManager,
$this->messageParser,
$this->autoCompleteManager,
$this->statusManager,
$this->searchPlugin,
$this->searchResult,
- $this->eventDispatcher,
$this->timeFactory,
+ $this->eventDispatcher,
$this->l
);
}
diff --git a/tests/php/Controller/RoomControllerTest.php b/tests/php/Controller/RoomControllerTest.php
deleted file mode 100644
index 06807707b8c..00000000000
--- a/tests/php/Controller/RoomControllerTest.php
+++ /dev/null
@@ -1,167 +0,0 @@
-.
- *
- */
-
-namespace OCA\Talk\Tests\php\Controller;
-
-use OCA\Talk\Chat\ChatManager;
-use OCA\Talk\Chat\MessageParser;
-use OCA\Talk\Config;
-use OCA\Talk\Controller\RoomController;
-use OCA\Talk\GuestManager;
-use OCA\Talk\Manager;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use OCA\Talk\TalkSession;
-use OCP\App\IAppManager;
-use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\EventDispatcher\IEventDispatcher;
-use OCP\IConfig;
-use OCP\IGroupManager;
-use OCP\IL10N;
-use OCP\IRequest;
-use OCP\IUserManager;
-use OCP\UserStatus\IManager as IUserStatusManager;
-use PHPUnit\Framework\MockObject\MockObject;
-use Test\TestCase;
-
-class RoomControllerTest extends TestCase {
-
- /** @var string */
- private $userId;
- /** @var IAppManager|MockObject */
- private $appManager;
- /** @var TalkSession|MockObject */
- private $talkSession;
- /** @var IUserManager|MockObject */
- protected $userManager;
- /** @var IGroupManager|MockObject */
- protected $groupManager;
- /** @var IUserStatusManager|MockObject */
- protected $statusManager;
- /** @var Manager|MockObject */
- protected $manager;
- /** @var RoomService|MockObject */
- protected $roomService;
- /** @var ChatManager|MockObject */
- protected $chatManager;
- /** @var GuestManager|MockObject */
- protected $guestManager;
- /** @var IEventDispatcher|MockObject */
- protected $dispatcher;
- /** @var MessageParser|MockObject */
- protected $messageParser;
- /** @var ITimeFactory|MockObject */
- protected $timeFactory;
- /** @var IL10N|MockObject */
- private $l;
- /** @var IConfig|MockObject */
- private $serverConfig;
- /** @var Config|MockObject */
- private $talkConfig;
-
-
- public function setUp(): void {
- parent::setUp();
-
- $this->userId = 'testUser';
- $this->appManager = $this->createMock(IAppManager::class);
- $this->talkSession = $this->createMock(TalkSession::class);
- $this->userManager = $this->createMock(IUserManager::class);
- $this->groupManager = $this->createMock(IGroupManager::class);
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->guestManager = $this->createMock(GuestManager::class);
- $this->statusManager = $this->createMock(IUserStatusManager::class);
- $this->chatManager = $this->createMock(ChatManager::class);
- $this->dispatcher = $this->createMock(IEventDispatcher::class);
- $this->messageParser = $this->createMock(MessageParser::class);
- $this->timeFactory = $this->createMock(ITimeFactory::class);
- $this->l = $this->createMock(IL10N::class);
- $this->serverConfig = $this->createMock(IConfig::class);
- $this->talkConfig = $this->createMock(Config::class);
- }
-
- /**
- * @param Room|MockObject $room
- * @param Participant|MockObject $participant
- * @return RoomController
- */
- private function getController(Room $room, Participant $participant): RoomController {
- $controller = new RoomController(
- 'spreed',
- $this->userId,
- $this->createMock(IRequest::class),
- $this->appManager,
- $this->talkSession,
- $this->userManager,
- $this->groupManager,
- $this->manager,
- $this->roomService,
- $this->guestManager,
- $this->statusManager,
- $this->chatManager,
- $this->dispatcher,
- $this->messageParser,
- $this->timeFactory,
- $this->l,
- $this->serverConfig,
- $this->talkConfig
- );
- $controller->setRoom($room);
- $controller->setParticipant($participant);
- return $controller;
- }
-
- public function dataSetNotificationLevel(): array {
- return [
- [Participant::NOTIFY_ALWAYS, true],
- [Participant::NOTIFY_MENTION, true],
- [Participant::NOTIFY_NEVER, true],
- [Participant::NOTIFY_DEFAULT, false, Http::STATUS_BAD_REQUEST],
- ];
- }
-
- /**
- * @dataProvider dataSetNotificationLevel
- * @param int $level
- * @param bool $validSet
- * @param int $status
- */
- public function testSetNotificationLevel(int $level, bool $validSet, int $status = Http::STATUS_OK) {
- $participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('setNotificationLevel')
- ->with($level)
- ->willReturn($validSet);
-
- $room = $this->createMock(Room::class);
-
- $controller = $this->getController($room, $participant);
- $expected = new DataResponse([], $status);
-
- $this->assertEquals($expected, $controller->setNotificationLevel($level));
- }
-}
diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php
index 7b80df49bf0..b99e10ef191 100644
--- a/tests/php/Controller/SignalingControllerTest.php
+++ b/tests/php/Controller/SignalingControllerTest.php
@@ -29,8 +29,12 @@
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
+use OCA\Talk\Model\AttendeeMapper;
+use OCA\Talk\Model\SessionMapper;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
+use OCA\Talk\Service\SessionService;
use OCA\Talk\Signaling\Messages;
use OCA\Talk\TalkSession;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -70,6 +74,10 @@ class SignalingControllerTest extends \Test\TestCase {
private $signalingManager;
/** @var Manager|MockObject */
protected $manager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
+ /** @var SessionService|MockObject */
+ protected $sessionService;
/** @var IDBConnection|MockObject */
protected $dbConnection;
/** @var Messages|MockObject */
@@ -108,6 +116,8 @@ public function setUp(): void {
$this->dbConnection = \OC::$server->getDatabaseConnection();
$this->signalingManager = $this->createMock(\OCA\Talk\Signaling\Manager::class);
$this->manager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
+ $this->sessionService = $this->createMock(SessionService::class);
$this->messages = $this->createMock(Messages::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
@@ -124,6 +134,8 @@ private function recreateSignalingController() {
$this->signalingManager,
$this->session,
$this->manager,
+ $this->participantService,
+ $this->sessionService,
$this->dbConnection,
$this->messages,
$this->userManager,
@@ -579,10 +591,6 @@ public function testBackendRoomInvitedPublic() {
->willReturn($room);
$participant = $this->createMock(Participant::class);
- $room->expects($this->once())
- ->method('getParticipant')
- ->with($this->userId)
- ->willThrowException(new ParticipantNotFoundException());
$room->expects($this->once())
->method('getParticipantBySession')
->with($sessionId)
@@ -632,7 +640,6 @@ public function testBackendRoomAnonymousOneToOne() {
->with($roomToken)
->willReturn($room);
- $participant = $this->createMock(Participant::class);
$room->expects($this->once())
->method('getParticipantBySession')
->willThrowException(new ParticipantNotFoundException());
@@ -755,9 +762,12 @@ public function testBackendPingUser() {
$room->expects($this->once())
->method('getToken')
->willReturn($roomToken);
- $room->expects($this->once())
- ->method('pingSessionIds')
- ->with([$sessionId]);
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(123456);
+ $this->sessionService->expects($this->once())
+ ->method('updateMultipleLastPings')
+ ->with([$sessionId], 123456);
$result = $this->performBackendRequest([
'type' => 'ping',
@@ -791,9 +801,12 @@ public function testBackendPingAnonymous() {
$room->expects($this->once())
->method('getToken')
->willReturn($roomToken);
- $room->expects($this->once())
- ->method('pingSessionIds')
- ->with([$sessionId]);
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(1234567);
+ $this->sessionService->expects($this->once())
+ ->method('updateMultipleLastPings')
+ ->with([$sessionId], 1234567);
$result = $this->performBackendRequest([
'type' => 'ping',
@@ -827,9 +840,12 @@ public function testBackendPingMixedAndInactive() {
$room->expects($this->once())
->method('getToken')
->willReturn($roomToken);
- $room->expects($this->once())
- ->method('pingSessionIds')
- ->with([$sessionId . '1', $sessionId . '2']);
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(234567);
+ $this->sessionService->expects($this->once())
+ ->method('updateMultipleLastPings')
+ ->with([$sessionId . '1', $sessionId . '2'], 234567);
$result = $this->performBackendRequest([
'type' => 'ping',
@@ -865,10 +881,17 @@ public function testLeaveRoomWithOldSession() {
// Make sure that leaving a user with an old session id doesn't remove
// the current user from the room if he re-joined in the meantime.
$dbConnection = \OC::$server->getDatabaseConnection();
- $dispatcher = \OC::$server->query(IEventDispatcher::class);
+ $dispatcher = \OC::$server->get(IEventDispatcher::class);
+ /** @var ParticipantService $participantService */
+ $participantService = \OC::$server->get(ParticipantService::class);
+
$this->manager = new Manager(
$dbConnection,
\OC::$server->getConfig(),
+ $this->createMock(Config::class),
+ \OC::$server->get(AttendeeMapper::class),
+ \OC::$server->get(SessionMapper::class),
+ $participantService,
$this->secureRandom,
$this->createMock(IUserManager::class),
$this->createMock(CommentsManager::class),
@@ -891,7 +914,8 @@ public function testLeaveRoomWithOldSession() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
// The user joined the room.
- $oldSessionId = $room->joinRoom($testUser, '');
+ $oldParticipant = $participantService->joinRoom($room, $testUser, '');
+ $oldSessionId = $oldParticipant->getSession()->getSessionId();
$result = $this->performBackendRequest([
'type' => 'room',
'room' => [
@@ -902,11 +926,12 @@ public function testLeaveRoomWithOldSession() {
],
]);
$participant = $room->getParticipant($this->userId);
- $this->assertEquals($oldSessionId, $participant->getSessionId());
+ $this->assertEquals($oldSessionId, $participant->getSession()->getSessionId());
// The user is reloading the browser which will join him with another
// session id.
- $newSessionId = $room->joinRoom($testUser, '');
+ $newParticipant = $participantService->joinRoom($room, $testUser, '');
+ $newSessionId = $newParticipant->getSession()->getSessionId();
$result = $this->performBackendRequest([
'type' => 'room',
'room' => [
@@ -919,7 +944,7 @@ public function testLeaveRoomWithOldSession() {
// Now the new session id is stored in the database.
$participant = $room->getParticipant($this->userId);
- $this->assertEquals($newSessionId, $participant->getSessionId());
+ $this->assertEquals($newSessionId, $participant->getSession()->getSessionId());
// Leaving the old session id...
$result = $this->performBackendRequest([
@@ -934,6 +959,6 @@ public function testLeaveRoomWithOldSession() {
// ...will keep the new session id in the database.
$participant = $room->getParticipant($this->userId);
- $this->assertEquals($newSessionId, $participant->getSessionId());
+ $this->assertEquals($newSessionId, $participant->getSession()->getSessionId());
}
}
diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php
index b327e2d6035..fddf8fceb87 100644
--- a/tests/php/Notification/NotifierTest.php
+++ b/tests/php/Notification/NotifierTest.php
@@ -32,6 +32,7 @@
use OCA\Talk\Notification\Notifier;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Comments\IComment;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -61,6 +62,8 @@ class NotifierTest extends \Test\TestCase {
protected $shareManager;
/** @var Manager|MockObject */
protected $manager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var INotificationManager|MockObject */
protected $notificationManager;
/** @var CommentsManager|MockObject */
@@ -82,6 +85,7 @@ public function setUp(): void {
$this->guestManager = $this->createMock(GuestManager::class);
$this->shareManager = $this->createMock(IShareManager::class);
$this->manager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->notificationManager = $this->createMock(INotificationManager::class);
$this->commentsManager = $this->createMock(CommentsManager::class);
$this->messageParser = $this->createMock(MessageParser::class);
@@ -95,6 +99,7 @@ public function setUp(): void {
$this->guestManager,
$this->shareManager,
$this->manager,
+ $this->participantService,
$this->notificationManager,
$this->commentsManager,
$this->messageParser,
diff --git a/tests/php/RoomTest.php b/tests/php/RoomTest.php
index e3a3a384697..e1bba40b948 100644
--- a/tests/php/RoomTest.php
+++ b/tests/php/RoomTest.php
@@ -64,6 +64,7 @@ public function testVerifyPassword() {
Room::PUBLIC_CALL,
Room::READ_WRITE,
Webinary::LOBBY_NONE,
+ 0,
null,
'foobar',
'Test',
diff --git a/tests/php/Service/RoomServiceTest.php b/tests/php/Service/RoomServiceTest.php
index 4eba57d4390..d223c4c3ccc 100644
--- a/tests/php/Service/RoomServiceTest.php
+++ b/tests/php/Service/RoomServiceTest.php
@@ -28,6 +28,7 @@
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\RoomService;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
@@ -37,6 +38,8 @@ class RoomServiceTest extends TestCase {
/** @var Manager|MockObject */
protected $manager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var RoomService */
private $service;
@@ -45,8 +48,10 @@ public function setUp(): void {
parent::setUp();
$this->manager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->service = new RoomService(
- $this->manager
+ $this->manager,
+ $this->participantService
);
}
@@ -69,8 +74,9 @@ public function testCreateOneToOneConversationAlreadyExists(): void {
->willReturn('uid2');
$room = $this->createMock(Room::class);
- $room->expects($this->once())
- ->method('ensureOneToOneRoomIsFilled');
+ $this->participantService->expects($this->once())
+ ->method('ensureOneToOneRoomIsFilled')
+ ->with($room);
$this->manager->expects($this->once())
->method('getOne2OneRoom')
@@ -89,17 +95,21 @@ public function testCreateOneToOneConversationCreated(): void {
->willReturn('uid2');
$room = $this->createMock(Room::class);
- $room->expects($this->never())
- ->method('ensureOneToOneRoomIsFilled');
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('addUsers')
- ->with([
- 'userId' => 'uid1',
+ ->with($room, [[
+ 'actorType' => 'users',
+ 'actorId' => 'uid1',
'participantType' => Participant::OWNER,
], [
- 'userId' => 'uid2',
+ 'actorType' => 'users',
+ 'actorId' => 'uid2',
'participantType' => Participant::OWNER,
- ]);
+ ]]);
+
+ $this->participantService->expects($this->never())
+ ->method('ensureOneToOneRoomIsFilled')
+ ->with($room);
$this->manager->expects($this->once())
->method('getOne2OneRoom')
@@ -204,15 +214,16 @@ public function testCreateConversation(int $type, string $name, string $ownerId,
$owner->method('getUID')
->willReturn($ownerId);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('addUsers')
- ->with([
- 'userId' => $ownerId,
+ ->with($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $ownerId,
'participantType' => Participant::OWNER,
- ]);
+ ]]);
} else {
$owner = null;
- $room->expects($this->never())
+ $this->participantService->expects($this->never())
->method('addUsers');
}
diff --git a/tests/php/Settings/Admin/AdminSettingsTest.php b/tests/php/Settings/Admin/AdminSettingsTest.php
index 95807ee2dd8..2fcdcff65e0 100644
--- a/tests/php/Settings/Admin/AdminSettingsTest.php
+++ b/tests/php/Settings/Admin/AdminSettingsTest.php
@@ -29,6 +29,7 @@
use OCA\Talk\Settings\Admin\AdminSettings;
use OCP\ICacheFactory;
use OCP\IConfig;
+use OCP\IGroupManager;
use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IUserSession;
@@ -47,6 +48,8 @@ class AdminSettingsTest extends \Test\TestCase {
protected $initialState;
/** @var ICacheFactory|MockObject */
protected $cacheFactory;
+ /** @var IGroupManager|MockObject */
+ protected $groupManager;
/** @var MatterbridgeManager|MockObject */
protected $matterbridgeManager;
/** @var IUserSession|MockObject */
@@ -66,6 +69,7 @@ public function setUp(): void {
$this->commandService = $this->createMock(CommandService::class);
$this->initialState = $this->createMock(IInitialStateService::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
+ $this->groupManager = $this->createMock(IGroupManager::class);
$this->matterbridgeManager = $this->createMock(MatterbridgeManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->l10n = $this->createMock(IL10N::class);
@@ -86,6 +90,7 @@ protected function getAdminSettings(array $methods = []): AdminSettings {
$this->commandService,
$this->initialState,
$this->cacheFactory,
+ $this->groupManager,
$this->matterbridgeManager,
$this->userSession,
$this->l10n,
@@ -100,6 +105,7 @@ protected function getAdminSettings(array $methods = []): AdminSettings {
$this->commandService,
$this->initialState,
$this->cacheFactory,
+ $this->groupManager,
$this->matterbridgeManager,
$this->userSession,
$this->l10n,
diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php
index c775b68c59d..47777bbb744 100644
--- a/tests/php/Signaling/BackendNotifierTest.php
+++ b/tests/php/Signaling/BackendNotifierTest.php
@@ -27,8 +27,11 @@
use OCA\Talk\Config;
use OCA\Talk\Events\SignalingRoomPropertiesEvent;
use OCA\Talk\Manager;
+use OCA\Talk\Model\AttendeeMapper;
+use OCA\Talk\Model\SessionMapper;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Signaling\BackendNotifier;
use OCA\Talk\TalkSession;
use OCA\Talk\Webinary;
@@ -75,6 +78,8 @@ class BackendNotifierTest extends \Test\TestCase {
private $secureRandom;
/** @var ITimeFactory|MockObject */
private $timeFactory;
+ /** @var ParticipantService|MockObject */
+ private $participantService;
/** @var \OCA\Talk\Signaling\Manager|MockObject */
private $signalingManager;
/** @var IURLGenerator|MockObject */
@@ -119,6 +124,7 @@ public function setUp(): void {
],
]));
+ $this->participantService = \OC::$server->get(ParticipantService::class);
$this->signalingManager = $this->createMock(\OCA\Talk\Signaling\Manager::class);
$this->signalingManager->expects($this->any())
->method('getSignalingServerForConversation')
@@ -134,6 +140,10 @@ public function setUp(): void {
$this->manager = new Manager(
$dbConnection,
$config,
+ $this->config,
+ \OC::$server->get(AttendeeMapper::class),
+ \OC::$server->get(SessionMapper::class),
+ $this->participantService,
$this->secureRandom,
$this->createMock(IUserManager::class),
$this->createMock(CommentsManager::class),
@@ -159,6 +169,7 @@ private function recreateBackendNotifier() {
$this->createMock(IClientService::class),
$this->secureRandom,
$this->signalingManager,
+ $this->participantService,
$this->urlGenerator
);
}
@@ -194,7 +205,7 @@ private function assertMessageWasSent(Room $room, array $message): void {
$bodies = array_map([$this, 'sortParticipantUsers'], $bodies);
$message = $this->sortParticipantUsers($message);
- $this->assertContains($message, $bodies);
+ $this->assertContains($message, $bodies, json_encode($bodies, JSON_PRETTY_PRINT));
}
private function sortParticipantUsers(array $message): array {
@@ -207,14 +218,24 @@ private function sortParticipantUsers(array $message): array {
;
});
}
+ if ($message['type'] === 'incall') {
+ usort($message['incall']['users'], static function ($a, $b) {
+ return
+ [$a['userId'] ?? '', $a['participantType'], $a['sessionId'], $a['lastPing']]
+ <=>
+ [$b['userId'] ?? '', $b['participantType'], $b['sessionId'], $b['lastPing']]
+ ;
+ });
+ }
return $message;
}
public function testRoomInvite() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $room->addUsers([
- 'userId' => $this->userId,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
$this->assertMessageWasSent($room, [
'type' => 'invite',
@@ -232,6 +253,7 @@ public function testRoomInvite() {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -239,16 +261,17 @@ public function testRoomInvite() {
public function testRoomDisinvite() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $room->addUsers([
- 'userId' => $this->userId,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
$this->controller->clearRequests();
/** @var IUser|MockObject $testUser */
$testUser = $this->createMock(IUser::class);
$testUser->expects($this->any())
->method('getUID')
->willReturn($this->userId);
- $room->removeUser($testUser, Room::PARTICIPANT_REMOVED);
+ $this->participantService->removeUser($room, $testUser, Room::PARTICIPANT_REMOVED);
$this->assertMessageWasSent($room, [
'type' => 'disinvite',
@@ -265,6 +288,7 @@ public function testRoomDisinvite() {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -286,6 +310,7 @@ public function testRoomNameChanged() {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -307,6 +332,7 @@ public function testRoomPasswordChanged() {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -328,6 +354,7 @@ public function testRoomTypeChanged() {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -349,6 +376,7 @@ public function testRoomReadOnlyChanged() {
'lobby-timer' => null,
'read-only' => Room::READ_ONLY,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -370,6 +398,7 @@ public function testRoomLobbyStateChanged() {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -377,9 +406,10 @@ public function testRoomLobbyStateChanged() {
public function testRoomDelete() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $room->addUsers([
- 'userId' => $this->userId,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
$room->deleteRoom();
$this->assertMessageWasSent($room, [
@@ -394,13 +424,22 @@ public function testRoomDelete() {
public function testRoomInCallChanged() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $userSession = 'user-session';
- $room->addUsers([
- 'userId' => $this->userId,
- 'sessionId' => $userSession,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
+
+ /** @var IUser|MockObject $testUser */
+ $testUser = $this->createMock(IUser::class);
+ $testUser->expects($this->any())
+ ->method('getUID')
+ ->willReturn($this->userId);
+
+ $participant = $this->participantService->joinRoom($room, $testUser, '');
+ $userSession = $participant->getSession()->getSessionId();
$participant = $room->getParticipantBySession($userSession);
- $room->changeInCall($participant, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
+
+ $this->participantService->changeInCall($room, $participant, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
$this->assertMessageWasSent($room, [
'type' => 'incall',
@@ -428,9 +467,11 @@ public function testRoomInCallChanged() {
]);
$this->controller->clearRequests();
- $guestSession = $room->joinRoomGuest('');
+
+ $guestParticipant = $this->participantService->joinRoomAsNewGuest($room, '');
+ $guestSession = $guestParticipant->getSession()->getSessionId();
$guestParticipant = $room->getParticipantBySession($guestSession);
- $room->changeInCall($guestParticipant, Participant::FLAG_IN_CALL);
+ $this->participantService->changeInCall($room, $guestParticipant, Participant::FLAG_IN_CALL);
$this->assertMessageWasSent($room, [
'type' => 'incall',
@@ -463,7 +504,7 @@ public function testRoomInCallChanged() {
]);
$this->controller->clearRequests();
- $room->changeInCall($participant, Participant::FLAG_DISCONNECTED);
+ $this->participantService->changeInCall($room, $participant, Participant::FLAG_DISCONNECTED);
$this->assertMessageWasSent($room, [
'type' => 'incall',
@@ -515,6 +556,7 @@ public function testRoomPropertiesEvent(): void {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
'foo' => 'bar',
'room' => $room->getToken(),
],
@@ -524,13 +566,22 @@ public function testRoomPropertiesEvent(): void {
public function testParticipantsTypeChanged() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $userSession = 'user-session';
- $room->addUsers([
- 'userId' => $this->userId,
- 'sessionId' => $userSession,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
+
+ /** @var IUser|MockObject $testUser */
+ $testUser = $this->createMock(IUser::class);
+ $testUser->expects($this->any())
+ ->method('getUID')
+ ->willReturn($this->userId);
+
+ $participant = $this->participantService->joinRoom($room, $testUser, '');
+ $userSession = $participant->getSession()->getSessionId();
$participant = $room->getParticipantBySession($userSession);
- $room->setParticipantType($participant, Participant::MODERATOR);
+
+ $this->participantService->updateParticipantType($room, $participant, Participant::MODERATOR);
$this->assertMessageWasSent($room, [
'type' => 'participants',
@@ -558,9 +609,12 @@ public function testParticipantsTypeChanged() {
]);
$this->controller->clearRequests();
- $guestSession = $room->joinRoomGuest('');
+
+ $guestParticipant = $this->participantService->joinRoomAsNewGuest($room, '');
+ $guestSession = $guestParticipant->getSession()->getSessionId();
$guestParticipant = $room->getParticipantBySession($guestSession);
- $room->setParticipantType($guestParticipant, Participant::GUEST_MODERATOR);
+
+ $this->participantService->updateParticipantType($room, $guestParticipant, Participant::GUEST_MODERATOR);
$this->assertMessageWasSent($room, [
'type' => 'participants',
@@ -594,11 +648,13 @@ public function testParticipantsTypeChanged() {
$this->controller->clearRequests();
$notJoinedUserId = 'not-joined-user-id';
- $room->addUsers([
- 'userId' => $notJoinedUserId,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $notJoinedUserId,
+ ]]);
+
$notJoinedParticipant = $room->getParticipant($notJoinedUserId);
- $room->setParticipantType($notJoinedParticipant, Participant::MODERATOR);
+ $this->participantService->updateParticipantType($room, $notJoinedParticipant, Participant::MODERATOR);
$this->assertMessageWasSent($room, [
'type' => 'participants',
@@ -631,7 +687,7 @@ public function testParticipantsTypeChanged() {
]);
$this->controller->clearRequests();
- $room->setParticipantType($participant, Participant::USER);
+ $this->participantService->updateParticipantType($room, $participant, Participant::USER);
$this->assertMessageWasSent($room, [
'type' => 'participants',
@@ -672,7 +728,7 @@ public function testParticipantsTypeChanged() {
]);
$this->controller->clearRequests();
- $room->setParticipantType($guestParticipant, Participant::GUEST);
+ $this->participantService->updateParticipantType($room, $guestParticipant, Participant::GUEST);
$this->assertMessageWasSent($room, [
'type' => 'participants',
diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml
index 0df7fc7c7b0..41b7cd0b6b6 100644
--- a/tests/psalm-baseline.xml
+++ b/tests/psalm-baseline.xml
@@ -292,7 +292,7 @@
-
+
$this->commentsManager
$this->commentsManager
@@ -301,11 +301,10 @@
-
+
IAuthTokenProvider
IToken
IToken
- UniqueConstraintViolationException
$this->tokenProvider
@@ -314,202 +313,44 @@
IAuthTokenProvider
-
-
- Type
- Type
- Type
-
-
-
-
- Type
- Type
-
-
-
-
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
-
-
$return['num_rooms']
-
+
PostgreSqlPlatform
PostgreSqlPlatform
- Type
$this->db->getDatabasePlatform()
$this->db->getDatabasePlatform()
-
-
- Type
- Type
- Type
- Type
-
-
-
-
- Type
-
-
-
-
- Type
- Type
-
-
-
+
PostgreSqlPlatform
TableNotFoundException
TableNotFoundException
TableNotFoundException
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
$this->connection->getDatabasePlatform()
-
-
- Type
-
-
-
+
PostgreSqlPlatform
- Type
- Type
- Type
- Type
- Type
- Type
- Type
- Type
$this->connection->getDatabasePlatform()
-
-
- Type
- Type
-
-
-
-
- Type
-
-
-
-
- Type
-
-
-
-
- Type
-
-
-
-
- Type
- Type
-
-
-
-
- Type
-
-
-
-
- Type
-
-
-
-
- Type
-
-
-
-
- Type
- Type
- Type
- Type
- Type
- Type
- Type
-
-
-
-
- Type
-
-
-
-
- Type
- Type
-
-
-
-
- Type
-
-
-
- Type
- Type
-
-
-
- Type
-
-
$this->participants
@@ -582,12 +423,6 @@
Cache
-
-
- IURLGenerator
- IUrlGenerator
-
-
IRootFolder