Example #1
0
 /**
  * Attempt to login with curlLogin and ensure that a page which requires login can be viewed 
  */
 public function testCurlLogin()
 {
     // ensure that page which should require login can't be viewed before logging in
     $sessionId = uniqid();
     $cookies = "PHPSESSID={$sessionId}; path=/;";
     $curlHandle = curl_init(TEST_BASE_URL . 'profile/settings');
     curl_setopt($curlHandle, CURLOPT_HTTPGET, 1);
     curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curlHandle, CURLOPT_COOKIE, $cookies);
     ob_start();
     $result = curl_exec($curlHandle);
     ob_clean();
     $this->assertFalse((bool) preg_match('/Change Personal Settings/', $result));
     // log in and then request the same page
     $sessionId = TestingAuxLib::curlLogin('testuser', 'password');
     $cookies = "PHPSESSID={$sessionId};";
     $curlHandle = curl_init(TEST_BASE_URL . 'profile/settings');
     curl_setopt($curlHandle, CURLOPT_HTTPGET, 1);
     curl_setopt($curlHandle, CURLOPT_HEADER, 1);
     curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curlHandle, CURLOPT_COOKIE, $cookies);
     ob_start();
     $result = curl_exec($curlHandle);
     ob_clean();
     //print_r ("document.cookie = 'PHPSESSID=$sessionId; path=/;';\n");
     //print_r ($result);
     $this->assertTrue((bool) preg_match('/Change Personal Settings/', $result));
 }