public function testPermissions() { $tag = new VolunteerHourTag(); $user = new User(-1); $this->assertFalse($tag->can('create', $user)); $this->assertFalse($tag->can('edit', $user)); $this->assertFalse($tag->can('delete', $user)); $this->assertFalse($tag->can('view', $user)); }
/** * @depends testEdit * @depends testCreateWithTags */ public function testEditWithTags() { $this->assertTrue(self::$hour5->set('tags', 'other tags tags')); $this->assertEquals(2, VolunteerHourTag::totalRecords(['hour' => self::$hour5->id()])); }
protected function postSetHook() { $user = $this->relation('uid'); // increment user's stats $metrics = $this->metrics(); foreach ($this->_delta as $key => &$value) { $value = $metrics[$key] - $value; } $user->incrementStats($this->_delta); // update tags if ($this->setTags) { // remove existing tags Database::delete('VolunteerHourTags', ['hour' => $this->id()]); $tags = array_unique($this->setTags); foreach ($tags as $tag) { $tagModel = new VolunteerHourTag(); $tagModel->grantAllPermissions(); $tagModel->create(['tag' => $tag, 'hour' => $this->id(), 'organization' => $this->organization]); } $this->setTags = false; } // email user if going from unapproved to approved if ($this->needsApproveEmail) { if (!$this->canSendEmail()) { return; } $org = $this->relation('organization'); $user->sendEmail('volunteer-hours-approved', ['subject' => 'Your volunteer hours were approved on InspireVive', 'orgname' => $org->name, 'place_name' => $this->relation('place')->name, 'day' => date('l, M j, Y', $this->timestamp), 'hours' => $this->hours]); // update last sent time $volunteer = $this->volunteer(); $volunteer->grantAllPermissions(); $volunteer->set('last_email_sent_about_hours', time()); $this->needsApproveEmail = false; } }