<commit_before><?php

/**
 *
 * Test case for the mySQLDAO class
 * 
 * @package Alpha Core Unit Tests
 * @author <NAME> <<EMAIL>>
 * @copyright 2008 <NAME>
 * @version $Id$ 
 * 
 */
class mysqlDAO_Test extends PHPUnit_Framework_TestCase
{
	/**
	 * A person_object for testing (any business object will do)
	 * 
	 * @var person_object
	 */
	private $person;
	
	/**
     * called before the test functions will be executed
     * this function is defined in PHPUnit_TestCase and overwritten
     * here
     */
    protected function setUp() {        
        $this->person = new person_object();
        $this->person->set_displayname('unitTestUser');
        $this->person->set_email('<EMAIL>');
        $this->person->set_password('password');
    }
    
    /** 
     * called after the test functions are executed
     * this function is defined in PHPUnit_TestCase and overwritten
     * here
     */    
    protected function tearDown() {
    	if(!$this->person->isTransient())
    		$this->person->delete(); 
        unset($this->person);
    }
    
    /*
     * TODO: add test methods for the following:
     *
     * - loadAllByAttribute
     */
    
    /**
     * test that the constructor sets the correct values of the "house keeping" attributes
     */
    public function testDefaultHouseKeepingValues() {
    	// make sure the person logged in is the same person to create/update the object
    	$this->assertEquals($_SESSION["current_user"]->getID(), $this->person->getCreatorId()->getValue(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    	$this->assertEquals($_SESSION["current_user"]->getID(), $this->person->getUpdatorId()->getValue(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    	// as it is a new object, make sure the version number is zero
    	$this->assertEquals(0, $this->person->getVersionNumber()->getValue(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    
    	// check that the date created and updated equal to today
    	$today = date('Y-m-d');
    	$this->assertEquals($today, $this->person->getCreateTS()->getDate(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    	$this->assertEquals($today, $this->person->getUpdateTS()->getDate(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    
    	// make sure the object is transient
    	$this->assertTrue($this->person->isTransient(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    }
    
    /**
     * testing the basic load/save functionality
     */
    public function testBasicLoadSave() {
    	$this->person->save();
    	$id = $this->person->getMAX();
    	$this->person->load($id);
    	$this->assertEquals('unitTestUser', $this->person->get_displayname(), 'testing the basic load/save functionality');
    }
    
    /**
     * testing the loadByAttribute method
     */
    public function testLoadByAttribute() {
    	$this->person->save();
    	$this->person->loadByAttribute('displayname','unitTestUser');
    	$this->assertEquals('<EMAIL>', $this->person->get_email(), 'testing the loadByAttribute method');
    	$this->person->loadByAttribute('email','<EMAIL>');
    	$this->assertEquals('unitTestUser', $this->person->get_displayname(), 'testing the loadByAttribute method');
    }
    
    /**
     * testing loadAll method
     */
    public function testLoadAll() {
    	$peopleCount = $this->person->getCount();
    	$people = $this->person->loadAll();
    	$this->assertEquals($peopleCount, count($people), 'testing loadAll method');
    	// only load 1
    	$people = $this->person->loadAll(0, 1);
    	$this->assertEquals(1, count($people), 'testing loadAll method');
    }
    
}

?><commit_msg>Added the testLoadAllByAttribute() test method<commit_after><?php

/**
 *
 * Test case for the mySQLDAO class
 * 
 * @package Alpha Core Unit Tests
 * @author <NAME> <<EMAIL>>
 * @copyright 2008 <NAME>
 * @version $Id$ 
 * 
 */
class mysqlDAO_Test extends PHPUnit_Framework_TestCase
{
	/**
	 * A person_object for testing (any business object will do)
	 * 
	 * @var person_object
	 */
	private $person;
	
	/**
     * called before the test functions will be executed
     * this function is defined in PHPUnit_TestCase and overwritten
     * here
     */
    protected function setUp() {        
        $this->person = new person_object();
        $this->person->set_displayname('unitTestUser');
        $this->person->set_email('<EMAIL>');
        $this->person->set_password('password');
    }
    
    /** 
     * called after the test functions are executed
     * this function is defined in PHPUnit_TestCase and overwritten
     * here
     */    
    protected function tearDown() {
    	if(!$this->person->isTransient())
    		$this->person->delete(); 
        unset($this->person);
    }
    
    /**
     * test that the constructor sets the correct values of the "house keeping" attributes
     */
    public function testDefaultHouseKeepingValues() {
    	// make sure the person logged in is the same person to create/update the object
    	$this->assertEquals($_SESSION["current_user"]->getID(), $this->person->getCreatorId()->getValue(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    	$this->assertEquals($_SESSION["current_user"]->getID(), $this->person->getUpdatorId()->getValue(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    	// as it is a new object, make sure the version number is zero
    	$this->assertEquals(0, $this->person->getVersionNumber()->getValue(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    
    	// check that the date created and updated equal to today
    	$today = date('Y-m-d');
    	$this->assertEquals($today, $this->person->getCreateTS()->getDate(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    	$this->assertEquals($today, $this->person->getUpdateTS()->getDate(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    
    	// make sure the object is transient
    	$this->assertTrue($this->person->isTransient(), 'test that the constructor sets the correct values of the "house keeping" attributes');
    }
    
    /**
     * testing the basic load/save functionality
     */
    public function testBasicLoadSave() {
    	$this->person->save();
    	$id = $this->person->getMAX();
    	$this->person->load($id);
    	$this->assertEquals('unitTestUser', $this->person->get_displayname(), 'testing the basic load/save functionality');
    }
    
    /**
     * testing the loadByAttribute method
     */
    public function testLoadByAttribute() {
    	$this->person->save();
    	$this->person->loadByAttribute('displayname','unitTestUser');
    	$this->assertEquals('<EMAIL>', $this->person->get_email(), 'testing the loadByAttribute method');
    	$this->person->loadByAttribute('email','<EMAIL>');
    	$this->assertEquals('unitTestUser', $this->person->get_displayname(), 'testing the loadByAttribute method');
    }
    
    /**
     * testing loadAll method
     */
    public function testLoadAll() {
    	$peopleCount = $this->person->getCount();
    	$people = $this->person->loadAll();
    	$this->assertEquals($peopleCount, count($people), 'testing loadAll method');
    	// only load 1
    	$people = $this->person->loadAll(0, 1);
    	$this->assertEquals(1, count($people), 'testing loadAll method');
    }
    
    /**
     * testing the loadAllByAttribute method
     */
    public function testLoadAllByAttribute() {
    	$this->person->save();
    	$people = $this->person->loadAllByAttribute('email','<EMAIL>');
    	$this->assertEquals(1, count($people), 'testing the loadAllByAttribute method');
    	$this->assertEquals('unitTestUser', $people[0]->get_displayname(), 'testing the loadAllByAttribute method');
    	$people[0]->delete();
    }    
}

?>
{'fraction_non_alphanumeric': 0.13860554422176888, 'fraction_numerical': 0.002520100804032161, 'mean_word_length': 2.9742489270386265, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 160, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4192315', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2256, 'n_words': 639}