<commit_before><?php
/**
 * Feature : Settings Workspace, keys section
 *
 * - As a LU I should be able to see my profile information in the profile section
 * - As a LU I should be able to see and use the breadcrumb of the profile section.
 * - As LU, I should be able to edit my avatar picture.
 * - As LU, I shouldn't be able to upload a wrong file format as my avatar picture
 * - As LU, I should be able to edit my profile and see the editable fields.
 * - As LU I can see validation error messages while editing my profile information.
 * - As LU I can edit my own last name.
 * - As LU I can edit my own first name.
 *
 * @copyright (c) 2015-present Bolt Softwares Pvt Ltd
 * @licence GNU Affero General Public License http://www.gnu.org/licenses/agpl-3.0.en.html
 */

class SettingsProfileTest extends PassboltTestCase {

	/**
	 * Scenario :   As a LU I should be able to see my profile information in the profile section
	 * Given        I am logged in as a LU in the settings workspace, profile section
	 * Then         I should see the title Profile
	 * And          I should see my name in the profile information
	 * And          I should see my email in the profile information
	 * And          I should see my role in the profile information
	 * And          I should see my public key id in the profile information
	 * And          I should see my profile creation date in the profile information
	 * And          I should see my profile modification date in the profile information
	 * And          I should see my picture in the profile information
	 * And          I should see my picture in the drop down menu at the top
	 *
	 * @throws Exception
	 */
	public function testSettingsProfile() {
		// Given I am Ada
		$user = User::get('ada');
		$this->setClientConfig($user);


		// And I am logged in on the user workspace
		$this->loginAs($user);

		// Go to user workspace
		$this->gotoWorkspace('settings');

		// I should see a section with a title Profile
		$this->waitUntilISee('.js_tabs_content h3', '/Profile/');

		// I should see the name of the user in the table info
		$this->assertElementContainsText(
			$this->find('.table-info.profile .name'),
			'<NAME>'
		);

		// I should see the email of the user in the table info
		$this->assertElementContainsText(
			$this->find('.table-info.profile .email'),
			'<EMAIL>'
		);

		// I should see the email of the user in the table info
		$this->assertElementContainsText(
			$this->find('.table-info.profile .role'),
			'user'
		);

		// I should see the public key id
		$this->assertElementContainsText(
			$this->find('.table-info.profile .publickey_keyid'),
			'<KEY>'
		);

		// And I should the created date in the ago format
		$this->assertElementContainsText(
			$this->find('.table-info.profile .created'),
			'/(a|[0-9]{1,2}) (minute|minutes) ago/'
		);

		// And I should see the correct modified date in the ago format
		$this->assertElementContainsText(
			$this->find('.table-info.profile .modified'),
			'/(a|[0-9]{1,2}) (minute|minutes) ago/'
		);

		// I should see the picture of Ada.
		$actualImage =  $this->find('.avatar img')->getAttribute('src');
		$expectedImage = IMG_FIXTURES . '/avatar/ada.png';
		$this->assertImagesAreSame($actualImage, $expectedImage);

		// And the picture of Ada should be the same as in the scroll down menu at the top of the page.
		$topProfileImage =  $this->find('#js_app_profile_dropdown .picture img')->getAttribute('src');
		$this->assertImagesAreSame($actualImage, $topProfileImage);
	}

	/**
	 * Scenario :   As a LU I should be able to see and use the breadcrumb of the profile section.
	 * Given        I am logged in as LU in the settings workspace, profile section.
	 * Then         I should see a breadcrumb
	 * And          I should see a breadcrumb section containing All users
	 * And          I should see a breadcrumb section containing my name
	 * And          I should see a breadcrumb section containing profile
	 * When         I click All users
	 * Then         I should be on the users workspace
	 *
	 * @throws Exception
	 */
	public function testSettingsProfileBreadcrumb() {
		// Given I am Ada
		$user = User::get('ada');
		$this->setClientConfig($user);


		// And I am logged in on the user workspace
		$this->loginAs($user);

		// Go to user workspace
		$this->gotoWorkspace('settings');

		// I should see the breadcrumb.
		$this->assertVisible('js_wsp_settings_breadcrumb');

		// I should see an element containing All users in the breadcrumb.
		$this->assertElementContainsText(
			$this->find('#js_wsp_settings_breadcrumb'),
			'/All users/'
		);

		// And I should see an element containing Ada Lovelace in the breadcrumb.
		$this->assertElementContainsText(
			$this->find('#js_wsp_settings_breadcrumb'),
			'/Ada Lovelace/'
		);

		// And I should see an element containing Profile in the breadcrumb.
		$this->assertElementContainsText(
			$this->find('#js_wsp_settings_breadcrumb'),
			'/Profile/'
		);

		// I click on All users.
		$this->clickLink('All users');

		// I should be on the users workspace.
		$this->waitUntilISee('#container.page.people');
	}

	/**
	 * Scenario :   As LU, I should be able to edit my avatar picture.
	 * Given        I am logged in as LU in the settings workspace, profile section.
	 * When         I click on upload a new picture
	 * Then         I should see a dialog window where I can select a file to upload
	 * When         I click on the close button
	 * Then         I should'nt see the dialog anymore
	 * When         I click on upload a new picture
	 * And          I click on the cancel button in the dialog
	 * Then         I should'nt see the dialog anymore
	 * When         I click on upload a new picture
	 * And          I select a file to upload from the dialog
	 * And          I click on save
	 * Then         I should see a success message
	 * And          I should see the selected photo in the profile details
	 * And          I should see the selected photo in the profile drop down
	 *
	 * @throws Exception
	 */
	public function testSettingsProfileAvatarEditOk() {
		// Given I am Ada
		$user = User::get( 'ada' );
		$this->setClientConfig( $user );

		// And I am logged in on the user workspace
		$this->loginAs( $user );

		// Go to user workspace
		$this->gotoWorkspace( 'settings' );

		// I click on the link Click here to upload a new picture.<commit_msg>PASSBOLT-1243 fixed test<commit_after><?php
/**
 * Feature : Settings Workspace, keys section
 *
 * - As a LU I should be able to see my profile information in the profile section
 * - As a LU I should be able to see and use the breadcrumb of the profile section.
 * - As LU, I should be able to edit my avatar picture.
 * - As LU, I shouldn't be able to upload a wrong file format as my avatar picture
 * - As LU, I should be able to edit my profile and see the editable fields.
 * - As LU I can see validation error messages while editing my profile information.
 * - As LU I can edit my own last name.
 * - As LU I can edit my own first name.
 *
 * @copyright (c) 2015-present Bolt Softwares Pvt Ltd
 * @licence GNU Affero General Public License http://www.gnu.org/licenses/agpl-3.0.en.html
 */

class SettingsProfileTest extends PassboltTestCase {

	/**
	 * Scenario :   As a LU I should be able to see my profile information in the profile section
	 * Given        I am logged in as a LU in the settings workspace, profile section
	 * Then         I should see the title Profile
	 * And          I should see my name in the profile information
	 * And          I should see my email in the profile information
	 * And          I should see my role in the profile information
	 * And          I should see my public key id in the profile information
	 * And          I should see my profile creation date in the profile information
	 * And          I should see my profile modification date in the profile information
	 * And          I should see my picture in the profile information
	 * And          I should see my picture in the drop down menu at the top
	 *
	 * @throws Exception
	 */
	public function testSettingsProfile() {
		// Given I am Ada
		$user = User::get('ada');
		$this->setClientConfig($user);


		// And I am logged in on the user workspace
		$this->loginAs($user);

		// Go to user workspace
		$this->gotoWorkspace('settings');

		// I should see a section with a title Profile
		$this->waitUntilISee('.js_tabs_content h3', '/Profile/');

		// I should see the name of the user in the table info
		$this->assertElementContainsText(
			$this->find('.table-info.profile .name'),
			'<NAME>'
		);

		// I should see the email of the user in the table info
		$this->assertElementContainsText(
			$this->find('.table-info.profile .email'),
			'<EMAIL>'
		);

		// I should see the email of the user in the table info
		$this->assertElementContainsText(
			$this->find('.table-info.profile .role'),
			'user'
		);

		// I should see the public key id
		$this->assertElementContainsText(
			$this->find('.table-info.profile .publickey_keyid'),
			'<KEY>'
		);

		// And I should the created date in the ago format
		$this->assertElementContainsText(
			$this->find('.table-info.profile .created'),
			'/(a|[0-9]{1,2}) (minute|minutes) ago/'
		);

		// And I should see the correct modified date in the ago format
		$this->assertElementContainsText(
			$this->find('.table-info.profile .modified'),
			'/(a|[0-9]{1,2}) (minute|minutes) ago/'
		);

		// I should see the picture of Ada.
		$actualImage =  $this->find('.avatar img')->getAttribute('src');
		$expectedImage = IMG_FIXTURES . '/avatar/ada.png';
		$this->assertImagesAreSame($actualImage, $expectedImage);

		// And the picture of Ada should be the same as in the scroll down menu at the top of the page.
		$topProfileImage =  $this->find('#js_app_profile_dropdown .picture img')->getAttribute('src');
		$this->assertImagesAreSame($actualImage, $topProfileImage);
	}

	/**
	 * Scenario :   As a LU I should be able to see and use the breadcrumb of the profile section.
	 * Given        I am logged in as LU in the settings workspace, profile section.
	 * Then         I should see a breadcrumb
	 * And          I should see a breadcrumb section containing All users
	 * And          I should see a breadcrumb section containing my name
	 * And          I should see a breadcrumb section containing profile
	 * When         I click All users
	 * Then         I should be on the users workspace
	 *
	 * @throws Exception
	 */
	public function testSettingsProfileBreadcrumb() {
		// Given I am Ada
		$user = User::get('ada');
		$this->setClientConfig($user);


		// And I am logged in on the user workspace
		$this->loginAs($user);

		// Go to user workspace
		$this->gotoWorkspace('settings');

		// I should see the breadcrumb.
		$this->assertVisible('js_wsp_settings_breadcrumb');

		// I should see an element containing All users in the breadcrumb.
		$this->assertElementContainsText(
			$this->find('#js_wsp_settings_breadcrumb'),
			'/All users/'
		);

		// And I should see an element containing Ada Lovelace in the breadcrumb.
		$this->assertElementContainsText(
			$this->find('#js_wsp_settings_breadcrumb'),
			'/Ada Lovelace/'
		);

		// And I should see an element containing Profile in the breadcrumb.
		$this->assertElementContainsText(
			$this->find('#js_wsp_settings_breadcrumb'),
			'/Profile/'
		);

		// I click on All users.
		$this->clickLink('All users');

		// I should be on the users workspace.
		$this->waitUntilISee('#container.page.people');
	}

	/**
	 * Scenario :   As LU, I should be able to edit my avatar picture.
	 * Given        I am logged in as LU in the settings workspace, profile section.
	 * When         I click on upload a new picture
	 * Then         I should see a dialog window where I can select a file to upload
	 * When         I click on the close button
	 * Then         I should'nt see the dialog anymore
	 * When         I click on upload a new picture
	 * And          I click on the cancel button in the dialog
	 * Then         I should'nt see the dialog anymore
	 * When         I click on upload a new picture
	 * And          I select a file to upload from the dialog
	 * And          I click on save
	 * Then         I should see a success message
	 * And          I should see the selected photo in the profile details
	 * And          I should see the selected photo in the profile drop down
	 *
	 * @throws Exception
	 */
	public function testSettingsProfileAvatarEditOk() {
		// Given I am Ada
		$user = User::get( 'edith' );
		$this->setClientConfig( $user );

		// And I am logged in on the user workspace
		$this->loginAs( $user );

		// Go to user workspace
		$this->gotoWorkspace( 'settings' );

		// I click on the link Click here to upload a new picture.
{'fraction_non_alphanumeric': 0.09517478689293814, 'fraction_numerical': 0.0026589504965981075, 'mean_word_length': 2.808219178082192, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5884703', 'n_tokens_mistral': 3923, 'n_tokens_neox': 3524, 'n_words': 1575}