/**
  * @covers ::getByName
  */
 public function testGetUserPreferencesNoArea()
 {
     $mockdb = new \TMT\MockDB();
     $mockdb->expectPrepare("SELECT * FROM notificationPreferences WHERE netId=:netId");
     $mockdb->expectExecute(array(':netId' => "netId"));
     $mockdb->setReturnData(array((object) array("netId" => "netId", "type" => "type1", "method" => "email", "area" => "area1"), (object) array("netId" => "netId", "type" => "type2", "method" => "onsite", "area" => "area2")));
     $expected = array(new \TMT\model\NotificationPreference(array("netId" => "netId", "type" => "type1", "method" => "email", "area" => "area1")), new \TMT\model\NotificationPreference(array("netId" => "netId", "type" => "type2", "method" => "onsite", "area" => "area2")));
     $accessor = new NotificationPreferences($mockdb);
     $actual = $accessor->getUserPreferences("netId");
     $this->assertEquals($expected, $actual);
     $mockdb->verify();
 }
 /**
  * @covers ::getByName
  */
 public function testGetByName()
 {
     $mockdb = new \TMT\MockDB();
     $mockdb->expectPrepare("SELECT * FROM notificationTypes WHERE name=:name");
     $mockdb->expectExecute(array(':name' => "type1"));
     $mockdb->setReturnData(array((object) array("guid" => "guid1", "name" => "type1", "resource" => "resguid1", "verb" => "read")));
     $expected = new \TMT\model\NotificationType(array("guid" => "guid1", "name" => "type1", "resource" => "resguid1", "verb" => "read"));
     $accessor = new NotificationType($mockdb);
     $actual = $accessor->getByName("type1");
     $this->assertEquals($expected, $actual);
     $mockdb->verify();
 }
 /**
  * @covers ::getAll
  */
 public function testGet()
 {
     $mockdb = new \TMT\MockDB();
     $mockdb->expectPrepare("SELECT name FROM notificationMethods");
     $mockdb->expectExecute();
     $mockdb->setReturnData(array((object) array("name" => "email"), (object) array("name" => "onsite")));
     $expected = array("email", "onsite");
     $accessor = new NotificationMethod($mockdb);
     $actual = $accessor->getAll();
     $this->assertEquals($expected, $actual);
     $mockdb->verify();
 }
 /**
  * @covers ::getByArea
  */
 public function testGetByArea()
 {
     $mockdb = new \TMT\MockDB();
     $mockdb->expectPrepare("SELECT * FROM notificationEmails WHERE area=:area");
     $mockdb->expectExecute(array(':area' => "areaguid"));
     $mockdb->setReturnData(array((object) array("guid" => "guid1", "email" => "*****@*****.**", "type" => "type1", "area" => "areaguid"), (object) array("guid" => "guid2", "email" => "*****@*****.**", "type" => "type2", "area" => "areaguid")));
     $expected = array(new \TMT\model\NotificationEmail(array("guid" => "guid1", "email" => "*****@*****.**", "type" => "type1", "area" => "areaguid")), new \TMT\model\NotificationEmail(array("guid" => "guid2", "email" => "*****@*****.**", "type" => "type2", "area" => "areaguid")));
     $accessor = new NotificationEmail($mockdb);
     $actual = $accessor->getByArea("areaguid");
     $this->assertEquals($expected, $actual);
     $mockdb->verify();
 }
 /**
  * @covers ::getUserNotifications
  */
 public function testGetUserNotificationsUnreadOnly()
 {
     $mockdb = new \TMT\MockDB();
     $mockdb->expectPrepare("SELECT notifications.*, userNotifications.netId, userNotifications.read FROM notifications JOIN userNotifications\n\t\t\tON notifications.guid=userNotifications.notificationGuid WHERE userNotifications.netId=:netId AND userNotifications.deleted=0 AND userNotifications.read=0");
     $mockdb->expectExecute(array(':netId' => "netId"));
     $mockdb->setReturnData(array((object) array("guid" => "guid1", "netId" => "netId", "timestamp" => "2000-01-01 00:00:00", "message" => "message", "area" => "areaguid", "type" => "type1", "read" => "0"), (object) array("guid" => "guid2", "netId" => "netId", "timestamp" => "2000-01-01 11:11:11", "message" => "stuff", "area" => "area2", "type" => "type2", "read" => "0")));
     $expected = array(new \TMT\model\UserNotification(array("guid" => "guid1", "netId" => "netId", "timestamp" => "2000-01-01 00:00:00", "message" => "message", "area" => "areaguid", "type" => "type1", "read" => "0")), new \TMT\model\UserNotification(array("guid" => "guid2", "netId" => "netId", "timestamp" => "2000-01-01 11:11:11", "message" => "stuff", "area" => "area2", "type" => "type2", "read" => "0")));
     $accessor = new UserNotification($mockdb);
     $actual = $accessor->getUserNotifications("netId", false);
     $this->assertEquals($expected, $actual);
     $mockdb->verify();
 }
 /**
  * @covers ::update
  */
 public function testUpdate()
 {
     $mockdb = new \TMT\MockDB();
     $mockdb->expectPrepare("UPDATE quicklinks SET name=:name, url=:url WHERE guid=:guid");
     $mockdb->expectExecute(array(':name' => "testname", ':url' => "testurl", ':guid' => "testguid"));
     $mockdb->expectPrepare("SELECT * FROM quicklinks WHERE guid=:guid");
     $mockdb->expectExecute(array(':guid' => "testguid"));
     $mockdb->setReturnData(array((object) array('guid' => "testguid", 'name' => "testname", 'netId' => "testnetId", 'url' => "testurl")));
     $expected = new \TMT\model\QuickLink((object) array('guid' => "testguid", 'name' => "testname", 'netId' => "testnetId", 'url' => "testurl"));
     $accessor = new Quicklinks($mockdb);
     $actual = $accessor->update(new \TMT\model\QuickLink((object) array('guid' => "testguid", 'name' => "testname", 'netId' => "testnetId", 'url' => "testurl")));
     $this->assertEquals($expected, $actual);
     $mockdb->verify();
 }
 /**
  * @covers ::search
  */
 public function testSearchDateRange()
 {
     $mockdb = new \TMT\MockDB();
     $accessor = new Notification($mockdb);
     $mockdb->expectPrepare("SELECT * FROM notifications WHERE (timestamp >= :startDate AND timestamp <= :endDate)");
     $mockdb->expectExecute(array(':startDate' => "2000-01-01 00:00:00", ':endDate' => "2000-01-01 00:00:00"));
     $mockdb->setReturnData(array((object) array("guid" => "guid1", "timestamp" => "2000-01-01 00:00:00", "message" => "something happened", "area" => "area1", "type" => "type1")));
     $result = $accessor->search(array('startDate' => "2000-01-01 00:00:00", 'endDate' => "2000-01-01 00:00:00"));
     $this->assertEquals(array(new \TMT\model\Notification(array("guid" => "guid1", "timestamp" => "2000-01-01 00:00:00", "message" => "something happened", "area" => "area1", "type" => "type1"))), $result);
     $mockdb->verify();
 }