From 2d597c2238c40ff0291fc80a4807aee6fc7bc4fc Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Sat, 24 Nov 2012 00:01:58 +0100 Subject: first unit tests implemented --- tests/lib/public/contacts.php | 80 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 tests/lib/public/contacts.php (limited to 'tests') diff --git a/tests/lib/public/contacts.php b/tests/lib/public/contacts.php new file mode 100644 index 00000000000..abe0e1f6250 --- /dev/null +++ b/tests/lib/public/contacts.php @@ -0,0 +1,80 @@ +. + */ + +OC::autoload('OCP\Contacts'); + +class Test_Contacts extends PHPUnit_Framework_TestCase +{ + + public function setUp() { + + OCP\Contacts::clear(); + } + + public function tearDown() { + } + + public function testDisabledIfEmpty() { + // pretty simple + $this->assertFalse(OCP\Contacts::isEnabled()); + } + + public function testEnabledAfterRegister() { + // create mock for the addressbook + $stub = $this->getMock("SimpleAddressBook", array('getKey')); + + // we expect getKey to be called once + $stub->expects($this->once()) + ->method('getKey'); + + // not enabled before register + $this->assertFalse(OCP\Contacts::isEnabled()); + + // register the address book + OCP\Contacts::registerAddressBook($stub); + + // contacts api shall be enabled + $this->assertTrue(OCP\Contacts::isEnabled()); + } + + // + // TODO: test unregister + // + + public function testAddressBookEnumeration() { + // create mock for the addressbook + $stub = $this->getMock("SimpleAddressBook", array('getKey', 'getDisplayName')); + + // setup return for method calls + $stub->expects($this->any()) + ->method('getKey') + ->will($this->returnValue('SIMPLE_ADDRESS_BOOK')); + $stub->expects($this->any()) + ->method('getDisplayName') + ->will($this->returnValue('A very simple Addressbook')); + + // register the address book + OCP\Contacts::registerAddressBook($stub); + $all_books = OCP\Contacts::getAddressBooks(); + + $this->assertEquals(1, count($all_books)); + } +} -- cgit v1.2.3