Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Nextcloud mail - PostGuard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Kolijn
Nextcloud mail - PostGuard
Commits
c97a6371
Commit
c97a6371
authored
9 years ago
by
Christoph Wurst
Browse files
Options
Downloads
Patches
Plain Diff
add tests for accountsservice
parent
fb060f86
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/service/accoutservicetest.php
+138
-0
138 additions, 0 deletions
tests/service/accoutservicetest.php
with
138 additions
and
0 deletions
tests/service/accoutservicetest.php
0 → 100644
+
138
−
0
View file @
c97a6371
<?php
/**
* ownCloud - Mail
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @copyright Christoph Wurst 2015
*/
use
Test\TestCase
;
use
OCA\Mail\Account
;
use
OCA\Mail\Service\AccountService
;
class
AccountServiceTest
extends
TestCase
{
private
$user
=
'herbert'
;
private
$mapper
;
private
$l10n
;
private
$service
;
private
$account1
;
private
$account2
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mapper
=
$this
->
getMockBuilder
(
'OCA\Mail\Db\MailAccountMapper'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
l10n
=
$this
->
getMockBuilder
(
'\OCP\IL10N'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
service
=
new
AccountService
(
$this
->
mapper
,
$this
->
l10n
);
$this
->
account1
=
$this
->
getMockBuilder
(
'OCA\Mail\Db\MailAccount'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
account2
=
$this
->
getMockBuilder
(
'OCA\Mail\Db\MailAccount'
)
->
disableOriginalConstructor
()
->
getMock
();
}
public
function
testFindByUserId
()
{
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'findByUserId'
)
->
with
(
$this
->
user
)
->
will
(
$this
->
returnValue
([
$this
->
account1
]));
$expected
=
[
new
Account
(
$this
->
account1
)
];
$actual
=
$this
->
service
->
findByUserId
(
$this
->
user
);
$this
->
assertEquals
(
$expected
,
$actual
);
}
public
function
testFindByUserIdUnifiedInbox
()
{
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'findByUserId'
)
->
with
(
$this
->
user
)
->
will
(
$this
->
returnValue
([
$this
->
account1
,
$this
->
account2
,
]));
$expected
=
[
null
,
new
Account
(
$this
->
account1
),
new
Account
(
$this
->
account2
),
];
$actual
=
$this
->
service
->
findByUserId
(
$this
->
user
);
$this
->
assertCount
(
3
,
$actual
);
$this
->
assertEquals
(
$expected
[
1
],
$actual
[
1
]);
$this
->
assertEquals
(
$expected
[
2
],
$actual
[
2
]);
}
public
function
testFind
()
{
$accountId
=
123
;
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'find'
)
->
with
(
$this
->
user
,
$accountId
)
->
will
(
$this
->
returnValue
(
$this
->
account1
));
$expected
=
new
Account
(
$this
->
account1
);
$actual
=
$this
->
service
->
find
(
$this
->
user
,
$accountId
);
$this
->
assertEquals
(
$expected
,
$actual
);
}
public
function
testFindNotFound
()
{
// TODO: implement code + write tests
}
public
function
testDelete
()
{
$accountId
=
33
;
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'find'
)
->
with
(
$this
->
user
,
$accountId
)
->
will
(
$this
->
returnValue
(
$this
->
account1
));
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'delete'
)
->
with
(
$this
->
account1
);
$this
->
service
->
delete
(
$this
->
user
,
$accountId
);
}
public
function
testDeleteUnifiedInbox
()
{
$accountId
=
-
1
;
$this
->
mapper
->
expects
(
$this
->
never
())
->
method
(
'find'
)
->
with
(
$this
->
user
,
$accountId
)
->
will
(
$this
->
returnValue
(
$this
->
account1
));
$this
->
mapper
->
expects
(
$this
->
never
())
->
method
(
'delete'
)
->
with
(
$this
->
account1
);
$this
->
service
->
delete
(
$this
->
user
,
$accountId
);
}
public
function
testSave
()
{
$account
=
new
OCA\Mail\Db\MailAccount
();
$expected
=
42
;
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
'save'
)
->
with
(
$account
)
->
will
(
$this
->
returnValue
(
$expected
));
$actual
=
$this
->
service
->
save
(
$account
);
$this
->
assertEquals
(
$expected
,
$actual
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment