3 * Pre-requisites: phpunit, phpunit-selenium, selenium-standalone-server, chrome driver, php-curl extension
8 require_once __DIR__
.'/../../../vendor/autoload.php';
10 class CheckCreateUserTest
extends PHPUnit_Extensions_Selenium2TestCase
12 const BROWSER
= "chrome";
13 const BROWSER_URL
= "http://localhost/openemr";
14 const URL
= "http://localhost/openemr/interface/login/login.php?site=default";
15 const VAR_AUTHUSER
= "admin";
16 const VAR_PASS
= "pass";
20 protected function setUp(){
21 $this->setBrowser(self
::BROWSER
);
22 $this->setBrowserUrl(self
::BROWSER_URL
);
24 protected function tearDown() {
30 * Generate random names and numbers
32 public function generateTestData() {
33 $name = $this->generateRandomString();
34 $lname = $this->generateRandomString();
35 $dob = $this->generateRandomDate();
36 $randint = rand(100000,200000);
38 return array( 'name'=>$name, 'lname'=>$lname, 'dob'=>$dob, 'randint'=> $randint );
43 * Tests Add Patient to openEMR
45 public function testAddPatient( ){
46 $testset = $this->generateTestData();
48 /*connect to openemr*/
49 $this->url(self
::URL
);
50 /*Move to frame Login and add login values*/
51 $this->frame("Login");
52 $this->byName('authUser')->value(self
::VAR_AUTHUSER
);
53 $this->byName('clearPass')->value(self
::VAR_PASS
);
54 $sumbmitClick=$this->byClassName("button");
55 $sumbmitClick->click();
57 /*Check that the login was succesfull coparing the title from the page*/
58 $this->assertEquals('OpenEMR',$this->title(),"Login Failed");
60 /*Move to frame left nav and click on new patient*/
61 $this->frame("left_nav");
62 $newPatientLink=$this->byId('new0');
63 $newPatientLink->click();
68 /*Fill the form and submit it*/
69 $this->byName('form_fname')->value( $testset['name'] );
70 $this->byName('form_lname')->value( $testset['lname'] );
71 $this->byName('form_DOB')->value( $testset['dob'] );
72 $this->byName('form_ss')->value( $testset['randint'] );
74 $this->select($this->byId('form_title'))->selectOptionByValue("Mr.");
75 $this->select($this->byId('form_sex'))->selectOptionByValue("Male");
76 $createLink= $this->byName('create');
79 /*Move to the popup and click on create patient*/
80 $handles=$this->windowHandles();
81 $this->window($handles[1]);
82 $createButton=$this->byXPath("//input[@type='button']");
83 $createButton->click();
86 /*Accept the alert when creating a new patient*/
87 $this->window($handles[0]);
96 * Check that the new patient exist in the database
98 * @depends testAddPatient
100 public function testFindPatient( $testset ) {
101 $this->database_connection();
102 $sql=sprintf( "SELECT * FROM patient_data where fname='%s' and lname='%s' and DOB = '%s' ", $testset['name'],$testset['lname'],$testset['dob']);
103 $res=$this->dbconn
->query($sql);
104 $numRows=mysqli_num_rows($res);
105 $this->assertEquals(1,$numRows,"Patient doesn't exists in the database");
109 * Generate random string used for names
113 private function generateRandomString($length = 8) {
114 $characters = 'abcdefghijklmnopqrstuvwxyz';
115 $charactersLength = strlen($characters);
117 for ($i = 0; $i < $length; $i++
) {
118 $randomString .= $characters[rand(0, $charactersLength - 1)];
120 return $randomString;
125 * Generate random date in the past
126 * @return bool|string
128 private function generateRandomDate(){
129 $int= rand(1100000000,1262055681);
130 $string = date("Y-m-d",$int);
135 * connect to OpenEMR database
137 private function database_connection(){
138 require_once( __DIR__
."/../../sites/default/sqlconf.php" );
141 $this->dbconn
= new mysqli( $sqlconf['host'],$sqlconf['login'], $sqlconf['pass'], $sqlconf['dbase'] );