public function testSendNotifications() { $u = new User($this->container); $n = new UserNotification($this->container); $p = new Project($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $pp = new ProjectPermission($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost'))); $this->assertTrue($pp->isEverybodyAllowed(1)); $n->saveSettings(1, array('notifications_enabled' => 1, 'notifications_filter' => UserNotificationFilter::FILTER_NONE, 'notification_types' => array('web' => 1, 'email' => 1))); $notifier = $this->getMockBuilder('Stdclass')->setMethods(array('notifyUser'))->getMock(); $notifier->expects($this->exactly(2))->method('notifyUser'); $this->container['userNotificationType']->expects($this->at(0))->method('getSelectedTypes')->will($this->returnValue(array('email', 'web'))); $this->container['userNotificationType']->expects($this->at(1))->method('getType')->with($this->equalTo('email'))->will($this->returnValue($notifier)); $this->container['userNotificationType']->expects($this->at(2))->method('getType')->with($this->equalTo('web'))->will($this->returnValue($notifier)); $n->sendNotifications(Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); }
public function testFilterUserWithBothFilterAndProjectSelected() { $u = new User($this->container); $n = new UserNotification($this->container); $nf = new UserNotificationFilter($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => UserNotificationFilter::FILTER_BOTH))); $n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true))); $this->assertFalse($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3)))); $this->assertFalse($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2)))); $this->assertTrue($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 2, 'owner_id' => 3)))); $this->assertTrue($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 0, 'owner_id' => 2)))); }