<commit_before><?php
define('TOGGLE_BUTTON_PRESSED', 1);
define('TOGGLE_BUTTON_UNPRESSED', 0);

use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverKeys;
use Facebook\WebDriver\WebDriverSelect;
use Facebook\WebDriver\Exception\NoSuchElementException;
use Facebook\WebDriver\Exception\StaleElementReferenceException;
use Facebook\WebDriver\Remote\DriverCommand;

/**
 * Passbolt Test Case
 * The base class for test cases related to passbolt.
 *
 * @copyright (c) 2017 Passbolt SARL
 * @licence GNU Affero General Public License http://www.gnu.org/licenses/agpl-3.0.en.html
 */
class PassboltTestCase extends WebDriverTestCase {

	// indicate if the database should be reset at the end of the test
	protected $resetDatabaseWhenComplete = false;

	// the current username
	protected $currentUsername = null;

	// the cookies used to log the different user.
	protected static $loginCookies = array();

	/**
	 * Called before the first test of the test case class is run
	 */
	public static function setUpBeforeClass() {
		// Nothing to add here for now.
	}


	/**
	 * Executed before every tests
	 */
	protected function setUp() {
		// Setup test.
		parent::setUp();
	}


	/**
	 * Executed after every tests
	 */
	protected function tearDown() {
		if ($this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE && Config::read('testserver.selenium.screenshotOnFail')) {
			$this->takeScreenshot();
			sleep(10);
		}
		// Reset the database if mentioned.
		if ($this->resetDatabaseWhenComplete) {
			PassboltServer::resetDatabase(Config::read('passbolt.url'));
		}

		parent::tearDown();
	}


	/**
	 * Mark the database to be reset at the end of the test
	 */
	public function resetDatabaseWhenComplete() {
		$this->resetDatabaseWhenComplete = true;
	}

	/**
	 * Take screenshot of what's happening on the vnc console of the selenium server.
	 */
	public function takeScreenshot() {
		$vncSnapshotBin = Config::read('testserver.selenium.screenshots.binary');
		$screenshotPath = Config::read('testserver.selenium.screenshots.path');
		$seleniumServerUrl = Config::read('testserver.selenium.url');
		echo "\n take screenshot from $seleniumServerUrl\n";
		preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $seleniumServerUrl, $ip);
		$ip = $ip[0];
		exec("$vncSnapshotBin $ip:0 $screenshotPath/{$this->testName}.jpg > /dev/null 2>&1");
		exec("$vncSnapshotBin $ip:1 $screenshotPath/{$this->testName}_1.jpg > /dev/null 2>&1");
		exec("$vncSnapshotBin $ip:2 $screenshotPath/{$this->testName}_2.jpg > /dev/null 2>&1");
		exec("$vncSnapshotBin $ip:3 $screenshotPath/{$this->testName}_3.jpg > /dev/null 2>&1");
	}

	/********************************************************************************
	 * Passbolt Application Helpers
	 ********************************************************************************/

	/**
	 * Go to debug page.
	 */
	public function goToDebug() {<commit_msg>PASSBOLT-2080 debug<commit_after><?php
define('TOGGLE_BUTTON_PRESSED', 1);
define('TOGGLE_BUTTON_UNPRESSED', 0);

use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverKeys;
use Facebook\WebDriver\WebDriverSelect;
use Facebook\WebDriver\Exception\NoSuchElementException;
use Facebook\WebDriver\Exception\StaleElementReferenceException;
use Facebook\WebDriver\Remote\DriverCommand;

/**
 * Passbolt Test Case
 * The base class for test cases related to passbolt.
 *
 * @copyright (c) 2017 Passbolt SARL
 * @licence GNU Affero General Public License http://www.gnu.org/licenses/agpl-3.0.en.html
 */
class PassboltTestCase extends WebDriverTestCase {

	// indicate if the database should be reset at the end of the test
	protected $resetDatabaseWhenComplete = false;

	// the current username
	protected $currentUsername = null;

	// the cookies used to log the different user.
	protected static $loginCookies = array();

	/**
	 * Called before the first test of the test case class is run
	 */
	public static function setUpBeforeClass() {
		// Nothing to add here for now.
	}


	/**
	 * Executed before every tests
	 */
	protected function setUp() {
		// Setup test.
		parent::setUp();
	}


	/**
	 * Executed after every tests
	 */
	protected function tearDown() {
		if ($this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE && Config::read('testserver.selenium.screenshotOnFail')) {
			$this->takeScreenshot();
		}
		// Reset the database if mentioned.
		if ($this->resetDatabaseWhenComplete) {
			PassboltServer::resetDatabase(Config::read('passbolt.url'));
		}

		parent::tearDown();
	}


	/**
	 * Mark the database to be reset at the end of the test
	 */
	public function resetDatabaseWhenComplete() {
		$this->resetDatabaseWhenComplete = true;
	}

	/**
	 * Take screenshot of what's happening on the vnc console of the selenium server.
	 */
	public function takeScreenshot() {
		$vncSnapshotBin = Config::read('testserver.selenium.screenshots.binary');
		$screenshotPath = Config::read('testserver.selenium.screenshots.path');
		$seleniumServerUrl = Config::read('testserver.selenium.url');
		echo "\n take screenshot from $seleniumServerUrl\n";
		preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $seleniumServerUrl, $ip);
		$ip = $ip[0];
		exec("$vncSnapshotBin $ip $screenshotPath/{$this->testName}.jpg > /dev/null 2>&1");
		exec("$vncSnapshotBin $ip $screenshotPath/{$this->testName}_1.jpg > /dev/null 2>&1");
	}

	/********************************************************************************
	 * Passbolt Application Helpers
	 ********************************************************************************/

	/**
	 * Go to debug page.
	 */
	public function goToDebug() {
{'fraction_non_alphanumeric': 0.1865432538269847, 'fraction_numerical': 0.01067995728017088, 'mean_word_length': 4.68149646107179, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1980477', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1673, 'n_words': 416}