Exemplo n.º 1
0
 public function testCountRidesForContactId()
 {
     TestUtils::clearDatabase();
     $testContact = $this->dbh->addContact('test1', '1234', '*****@*****.**', ROLE_IDENTIFIED_REGISTERED);
     if (!$testContact) {
         $this->fail('addContact failed');
     }
     $count = $this->dbh->countRidesForContactId($testContact);
     $this->assertEquals(0, $count);
     $testRide1 = $this->dbh->addRide(1, 'city_1', 2, 'city_2', TIME_IRRELEVANT, TIME_IRRELEVANT, $testContact, '', RIDE_ACTIVE, 0, 1);
     if (!$testRide1) {
         $this->fail('addRide failed');
     }
     $count = $this->dbh->countRidesForContactId($testContact);
     $this->assertEquals(1, $count);
     $testRide2 = $this->dbh->addRide(1, 'city_1', 2, 'city_2', TIME_IRRELEVANT, TIME_IRRELEVANT, $testContact, '', RIDE_INACTIVE, 0, 1);
     if (!$testRide2) {
         $this->fail('addRide failed');
     }
     // Inactive rides also count
     $count = $this->dbh->countRidesForContactId($testContact);
     $this->assertEquals(2, $count);
     // Now, make sure we get 0 for non-existent contact
     $count = $this->dbh->countRidesForContactId($testContact + 1);
     $this->assertEquals(0, $count);
 }
 function testSuccessLogonExistingUser()
 {
     TestUtils::clearDatabase();
     $params = array('user' => 'User2', 'password' => 'User2');
     $this->assertEquals(0, $this->contactsCount());
     $contact = $this->helper->authenticate($params);
     $this->assertTrue($contact !== false);
     // A new user should be created
     $this->assertTrue($this->contactExists($contact['Id']));
     $this->assertEquals(1, $this->contactsCount());
     // Now, let's authenticate the same user
     $contact2 = $this->helper->authenticate($params);
     $this->assertTrue($contact['Id'] === $contact2['Id']);
 }
 function testSuccessLogonNewUser()
 {
     TestUtils::clearDatabase();
     $id = DatabaseHelper::getInstance()->addContact('user2', '', '*****@*****.**', ROLE_IDENTIFIED, Utils::hashPassword('---longpassword123---'));
     // First let's fail
     $params1 = array('email' => '*****@*****.**', 'password' => '---longpassword12---');
     $this->assertFalse($this->helper->authenticate($params1));
     // This should work
     $params2 = array('email' => '*****@*****.**', 'password' => '---longpassword123---');
     $contact = $this->helper->authenticate($params2);
     $this->assertTrue($contact !== false);
     $this->assertEquals($id, $contact['Id']);
     $this->assertEquals(ROLE_IDENTIFIED, $contact['Role']);
 }
 /**
  * 
  * @depends testFindPotentialRides
  * @depends testFindRidesToNotify
  */
 function testSearchForMatchingRides()
 {
     TestUtils::clearDatabase();
     $ride1 = TestUtils::createSimpleRide(1, 2, STATUS_LOOKING);
     $ride2 = TestUtils::createSimpleRide(1, 3, STATUS_LOOKING);
     $ride3 = TestUtils::createSimpleRide(1, 2, STATUS_OFFERED);
     $ride4 = TestUtils::createSimpleRide(3, 4, STATUS_OFFERED);
     $ride5 = TestUtils::createSimpleRide(1, 7, STATUS_OFFERED);
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_LOOKING, 1);
     $potentials = Service_ShowInterest::findPotentialRides(STATUS_LOOKING, 1);
     $matching = Service_ShowInterest::searchForMatchingRides($potentials, $toNotify);
     $expectedResults = array($ride1 => array($ride3));
     $this->assertMatchingResults($matching, $expectedResults, "TestSearchForMatchingRides: Test 1");
     // Now, see what happens with don't-cares
     $ride6 = TestUtils::createSimpleRide(1, LOCATION_DONT_CARE, STATUS_LOOKING);
     $ride7 = TestUtils::createSimpleRide(LOCATION_DONT_CARE, 7, STATUS_LOOKING);
     // One for the sharing
     $ride8 = TestUtils::createSimpleRide(1, 2, STATUS_SHARING);
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_LOOKING, 1);
     $potentials = Service_ShowInterest::findPotentialRides(STATUS_LOOKING, 1);
     $matching = Service_ShowInterest::searchForMatchingRides($potentials, $toNotify);
     // We should now have 3 results:
     //   ride1: ride3, ride8
     //   ride6: ride3, ride5, ride8
     //   ride7: ride5
     $expectedResults = array($ride1 => array($ride3, $ride8), $ride6 => array($ride3, $ride5, $ride8), $ride7 => array($ride5));
     $this->assertMatchingResults($matching, $expectedResults, "TestSearchForMatchingRides: Test 2");
     // Now test the other way
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_OFFERED, 1);
     $potentials = Service_ShowInterest::findPotentialRides(STATUS_OFFERED, 1);
     $matching = Service_ShowInterest::searchForMatchingRides($potentials, $toNotify);
     // We should now have (wildcards in the rides to notify are not supported yet):
     //   ride3: ride1
     // TODO: Implement support for wildcards on the other way as well
     $expectedResults = array($ride3 => array($ride1, $ride8));
     $this->assertMatchingResults($matching, $expectedResults, "TestSearchForMatchingRides: Test 3");
     // And what happens when they share
     $toNotify = Service_ShowInterest::findRidesToNotify(STATUS_SHARING, 1);
     $potentials = Service_ShowInterest::findPotentialRides(STATUS_SHARING, 1);
     $matching = Service_ShowInterest::searchForMatchingRides($potentials, $toNotify);
     // We should now have the following results:
     //   ride8: ride1, ride3
     $expectedResults = array($ride8 => array($ride3, $ride1));
     $this->assertMatchingResults($matching, $expectedResults, "TestSearchForMatchingRides: Test 4");
 }
Exemplo n.º 5
0
 public function testUpdate3()
 {
     TestUtils::clearDatabase();
     DatabaseHelper::getInstance()->insert('Contacts', array('Email' => '*****@*****.**', 'Phone' => '123', 'Name' => 'test1', 'Role' => ROLE_GUEST));
     $contact = DatabaseHelper::getInstance()->getContactByEmail('*****@*****.**');
     $this->assertTrue($contact !== false);
     $this->assertEquals('test1', $contact['Name']);
     $updatedData = array('Phone' => '987', 'Name' => null, 'Role' => ROLE_ADMINISTRATOR, 'Email' => null);
     DatabaseHelper::getInstance()->update('Contacts', $updatedData, 'id=?', array($contact['Id']), true);
     // Make sure only the relevant fields were changed
     $contact = DatabaseHelper::getInstance()->getContactByEmail('*****@*****.**');
     $this->assertTrue($contact !== false);
     $this->assertEquals('test1', $contact['Name']);
     $this->assertEquals('987', $contact['Phone']);
     $this->assertEquals(ROLE_ADMINISTRATOR, $contact['Role']);
 }