/**
  * @covers EventTicket::getAvailableForDateTime()
  */
 public function testGetAvailableForDatetimeWithQuantity()
 {
     $ticket = new EventTicket();
     $ticket->StartType = 'Date';
     $ticket->StartDate = date('Y-m-d', time() - 3600 * 24);
     $ticket->EndType = 'Date';
     $ticket->EndDate = date('Y-m-d', time() + 3600 * 24);
     $ticket->write();
     $time = new RegisterableDateTime();
     $time->write();
     $ticket->Available = 50;
     $avail = $ticket->getAvailableForDateTime($time);
     $this->assertEquals(50, $avail['available']);
     // Create a registration that consumes some of the tickets.
     $rego = new EventRegistration();
     $rego->Status = 'Valid';
     $rego->TimeID = $time->ID;
     $rego->write();
     $rego->Tickets()->add($ticket, array('Quantity' => 49));
     $avail = $ticket->getAvailableForDateTime($time);
     $this->assertEquals(1, $avail['available']);
     // Then check we can exclude it.
     $avail = $ticket->getAvailableForDateTime($time, $rego->ID);
     $this->assertEquals(50, $avail['available']);
     // Then bump up the quantity so there are no more available.
     $rego->Tickets()->remove($ticket);
     $rego->Tickets()->add($ticket, array('Quantity' => 50));
     $avail = $ticket->getAvailableForDateTime($time);
     $this->assertFalse($avail['available']);
 }
 /**
  * @covers EventInvitationField::doInvite()
  */
 public function testDoInvite()
 {
     $event = new RegisterableEvent();
     $event->write();
     $datetime = new RegisterableDateTime();
     $datetime->StartDate = date('Y-m-d');
     $datetime->EventID = $event->ID;
     $datetime->write();
     $field = new EventInvitationField($datetime, 'Invitations');
     $form = new Form(new EventInvitationFieldTest_Controller(), 'Form', new FieldSet($field), new FieldSet());
     $form->loadDataFrom($event);
     $invite = $field->InviteForm();
     $invite->dataFieldByName('Emails')->setValue(array('new' => array('Name' => array('First Test', 'Second Test'), 'Email' => array('*****@*****.**', '*****@*****.**'))));
     $invite->dataFieldByName('TimeID')->setValue($datetime->ID);
     $field->doInvite(array(), $invite);
     $this->assertEmailSent('*****@*****.**');
     $this->assertEmailSent('*****@*****.**');
     $this->clearEmails();
     $invite->dataFieldByName('Emails')->setValue(array('new' => array('Name' => array('First Test', 'Second Test', 'Third Test'), 'Email' => array('*****@*****.**', '*****@*****.**', '*****@*****.**'))));
     $field->doInvite(array(), $invite);
     $this->assertNull($this->findEmail('*****@*****.**'));
     $this->assertNull($this->findEmail('*****@*****.**'));
     $this->assertEmailSent('*****@*****.**');
 }
 /**
  * Calculates the timestamp for when this ticket stops going on sale for an
  * event date time.
  *
  * @param  RegisterableDateTime $datetime
  * @return int
  */
 public function getSaleEndForDateTime(RegisterableDateTime $datetime)
 {
     if ($this->EndType == 'Date') {
         return strtotime($this->EndDate);
     }
     $time = $datetime->getStartTimestamp();
     $time = sfTime::subtract($time, $this->EndDays, sfTime::DAY);
     $time = sfTime::subtract($time, $this->EndHours, sfTime::HOUR);
     $time = sfTime::subtract($time, $this->EndMins, sfTime::MINUTE);
     return $time;
 }