<?php

$app = 'isernweb';
define('SF_APP', 'isernweb');
require dirname(__FILE__) . '/OrganizationBaseTest.php';
class OrganizationTest extends OrganizationBaseTest
{
    public function test_delete_ok()
    {
        $oldCount = OrganizationPeer::doCount(new Criteria());
        $this->goto_edit();
        $this->b->click('delete')->isRedirected()->followRedirect()->checkResponseElement('body', '/Organizations/')->checkResponseElement('body', '!/' . $this->Organizations['o1']['name'] . '/');
        $this->b->test()->is($oldCount - 1, OrganizationPeer::doCount(new Criteria()), "Organization count should be one less than {$oldCount}");
        echo "org is " . $this->Organizations['o1']['name'] . "\n";
    }
}
$test = new OrganizationTest();
$test->execute();
 /**
  * @depends testCreate
  */
 public function testInviteVolunteer()
 {
     // invite an existing user by an email address
     $this->assertInstanceOf('app\\volunteers\\models\\Volunteer', self::$org->inviteVolunteer('*****@*****.**'));
     $this->assertEquals(Volunteer::ROLE_VOLUNTEER, self::$org->getRoleOfUser(self::$user));
     // invite an existing user by an email address again
     $this->assertInstanceOf('app\\volunteers\\models\\Volunteer', self::$org->inviteVolunteer('*****@*****.**'));
     $this->assertEquals(Volunteer::ROLE_VOLUNTEER, self::$org->getRoleOfUser(self::$user));
     // invite an existing user by username
     $this->assertInstanceOf('app\\volunteers\\models\\Volunteer', self::$org->inviteVolunteer('testvolunteer2'));
     $this->assertEquals(Volunteer::ROLE_VOLUNTEER, self::$org->getRoleOfUser(self::$user2));
     // invite a non-existent user by email address
     $this->assertInstanceOf('app\\volunteers\\models\\Volunteer', self::$org->inviteVolunteer('*****@*****.**'));
     // check that user exists and is temporary
     self::$tempUser = User::findOne(['where' => ['user_email' => '*****@*****.**']]);
     $this->assertTrue(self::$tempUser->exists());
     $this->assertTrue(self::$tempUser->isTemporary());
     $this->assertEquals(self::$org->id(), self::$tempUser->invited_by);
     $this->assertEquals(Volunteer::ROLE_VOLUNTEER, self::$org->getRoleOfUser(self::$tempUser));
     // invite a non-existent user by username
     $this->assertFalse(self::$org->inviteVolunteer('badusername'));
 }