Mangled path fax send (#7515)
[openemr.git] / tests / e2e / CheckCreateUser.php
blob6486f1ea3e42ce0125a33242fc462ef4d9acf8b8
1 <?php
3 /**
4 * Pre-requisites: phpunit, phpunit-selenium, selenium-standalone-server, chrome driver, php-curl extension
7 * @Matrix Israel Ltd.
8 */
10 require_once __DIR__ . '/../../../vendor/autoload.php';
12 class CheckCreateUserTest extends PHPUnit_Extensions_Selenium2TestCase
14 const BROWSER = "chrome";
15 const BROWSER_URL = "http://localhost/openemr";
16 const URL = "http://localhost/openemr/interface/login/login.php?site=default";
17 const VAR_AUTHUSER = "admin";
18 const VAR_PASS = "pass";
20 private $dbconn;
22 protected function setUp()
24 $this->setBrowser(self::BROWSER);
25 $this->setBrowserUrl(self::BROWSER_URL);
27 protected function tearDown()
29 parent::tearDown();
33 /**
34 * Generate random names and numbers
36 public function generateTestData()
38 $name = $this->generateRandomString();
39 $lname = $this->generateRandomString();
40 $dob = $this->generateRandomDate();
41 $randint = rand(100000, 200000);
43 return array( 'name' => $name, 'lname' => $lname, 'dob' => $dob, 'randint' => $randint );
47 /**
48 * Tests Add Patient to openEMR
50 public function testAddPatient()
52 $testset = $this->generateTestData();
54 /*connect to openemr*/
55 $this->url(self::URL);
56 /*Move to frame Login and add login values*/
57 $this->frame("Login");
58 $this->byName('authUser')->value(self::VAR_AUTHUSER);
59 $this->byName('clearPass')->value(self::VAR_PASS);
60 $sumbmitClick = $this->byClassName("button");
61 $sumbmitClick->click();
63 /*Check that the login was succesfull coparing the title from the page*/
64 $this->assertEquals('OpenEMR', $this->title(), "Login Failed");
66 /*Move to frame left nav and click on new patient*/
67 $this->frame("left_nav");
68 $newPatientLink = $this->byId('new0');
69 $newPatientLink->click();
70 $this->frame(null);
71 $this->frame("RTop");
74 /*Fill the form and submit it*/
75 $this->byName('form_fname')->value($testset['name']);
76 $this->byName('form_lname')->value($testset['lname']);
77 $this->byName('form_DOB')->value($testset['dob']);
78 $this->byName('form_ss')->value($testset['randint']);
80 $this->select($this->byId('form_title'))->selectOptionByValue("Mr.");
81 $this->select($this->byId('form_sex'))->selectOptionByValue("Male");
82 $createLink = $this->byName('create');
83 $createLink->click();
85 /*Move to the popup and click on create patient*/
86 $handles = $this->windowHandles();
87 $this->window($handles[1]);
88 $createButton = $this->byXPath("//input[@type='button']");
89 $createButton->click();
90 sleep(2);
92 /*Accept the alert when creating a new patient*/
93 $this->window($handles[0]);
94 $this->acceptAlert();
95 sleep(1);
96 return $testset;
102 * Check that the new patient exist in the database
104 * @depends testAddPatient
106 public function testFindPatient($testset)
108 $this->database_connection();
109 $sql = sprintf("SELECT * FROM patient_data where fname='%s' and lname='%s' and DOB = '%s' ", $testset['name'], $testset['lname'], $testset['dob']);
110 $res = $this->dbconn->query($sql);
111 $numRows = mysqli_num_rows($res);
112 $this->assertEquals(1, $numRows, "Patient doesn't exists in the database");
116 * Generate random string used for names
117 * @param int $length
118 * @return string
120 private function generateRandomString($length = 8)
122 $characters = 'abcdefghijklmnopqrstuvwxyz';
123 $charactersLength = strlen($characters);
124 $randomString = '';
125 for ($i = 0; $i < $length; $i++) {
126 $randomString .= $characters[rand(0, $charactersLength - 1)];
128 return $randomString;
133 * Generate random date in the past
134 * @return bool|string
136 private function generateRandomDate()
138 $int = rand(1100000000, 1262055681);
139 $string = date("Y-m-d", $int);
140 return $string;
144 * connect to OpenEMR database
146 private function database_connection()
148 require_once(__DIR__ . "/../../sites/default/sqlconf.php");
150 // Create connection
151 $this->dbconn = new mysqli($sqlconf['host'], $sqlconf['login'], $sqlconf['pass'], $sqlconf['dbase']);