diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/ContactsManagerTest.php | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/tests/lib/ContactsManagerTest.php b/tests/lib/ContactsManagerTest.php index 63491214eb7..38658c04161 100644 --- a/tests/lib/ContactsManagerTest.php +++ b/tests/lib/ContactsManagerTest.php @@ -63,11 +63,15 @@ class ContactsManagerTest extends \Test\TestCase { */ public function testSearch($search1, $search2, $expectedResult) { /** @var \PHPUnit\Framework\MockObject\MockObject|IAddressBook $addressbook */ - $addressbook1 = $this->getMockBuilder('\OCP\IAddressBook') + $addressbook1 = $this->getMockBuilder('\OCP\IAddressBookEnabled') ->disableOriginalConstructor() ->getMock(); $addressbook1->expects($this->once()) + ->method('isEnabled') + ->willReturn(true); + + $addressbook1->expects($this->once()) ->method('search') ->willReturn($search1); @@ -75,11 +79,15 @@ class ContactsManagerTest extends \Test\TestCase { ->method('getKey') ->willReturn('simple:1'); - $addressbook2 = $this->getMockBuilder('\OCP\IAddressBook') + $addressbook2 = $this->getMockBuilder('\OCP\IAddressBookEnabled') ->disableOriginalConstructor() ->getMock(); $addressbook2->expects($this->once()) + ->method('isEnabled') + ->willReturn(true); + + $addressbook2->expects($this->once()) ->method('search') ->willReturn($search2); @@ -94,6 +102,44 @@ class ContactsManagerTest extends \Test\TestCase { $this->assertEquals($expectedResult, $result); } + /** + * @dataProvider searchProvider + */ + public function testSearchDisabledAb($search1): void { + /** @var \PHPUnit\Framework\MockObject\MockObject|IAddressBookEnabled $addressbook */ + $addressbook1 = $this->getMockBuilder('\OCP\IAddressBookEnabled') + ->disableOriginalConstructor() + ->getMock(); + + $addressbook1->expects($this->once()) + ->method('isEnabled') + ->willReturn(true); + + $addressbook1->expects($this->once()) + ->method('search') + ->willReturn($search1); + + $addressbook1->expects($this->any()) + ->method('getKey') + ->willReturn('simple:1'); + + $addressbook2 = $this->getMockBuilder('\OCP\IAddressBookEnabled') + ->disableOriginalConstructor() + ->getMock(); + + $addressbook2->expects($this->once()) + ->method('isEnabled') + ->willReturn(false); + + $addressbook2->expects($this->never()) + ->method('search'); + + $this->cm->registerAddressBook($addressbook1); + $this->cm->registerAddressBook($addressbook2); + $result = $this->cm->search(''); + $this->assertEquals($search1, $result); + } + public function testDeleteHavePermission() { /** @var \PHPUnit\Framework\MockObject\MockObject|IAddressBook $addressbook */ @@ -243,8 +289,8 @@ class ContactsManagerTest extends \Test\TestCase { public function testAddressBookEnumeration() { // create mock for the addressbook - /** @var \PHPUnit\Framework\MockObject\MockObject|IAddressBook $addressbook */ - $addressbook = $this->getMockBuilder('\OCP\IAddressBook') + /** @var \PHPUnit\Framework\MockObject\MockObject|IAddressBookEnabled $addressbook */ + $addressbook = $this->getMockBuilder('\OCP\IAddressBookEnabled') ->disableOriginalConstructor() ->getMock(); |