<commit_before><?php
// Copyright (c) 2011 <NAME> <<EMAIL>>

App::import('Lib', 'CakemarksWebTestCase');

/**
 * Exercises the bookmarks.
 *
 * @author <NAME> <<EMAIL>>
 */
class BookmarkTestCase extends CakemarksWebTestCase {
	/**
	 * Loads the bookmark adding view.
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function load_bookmark_add_page() {
		$this->get($this->baseurl."/bookmarks/add");
		$this->verify_page_load();
		$this->assertPattern("/Add Bookmark/");
	}

	/**
	 * Adds a bookmark which can be on the reading list and does not have any
	 * keywords.
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function bookmark_add($reading_list = false) {
		$this->load_bookmark_add_page();

		$this->input_title = String::uuid();
		$this->input_url = String::uuid().'.tld';
		$this->assertTrue($this->setField('data[Bookmark][title]', $this->input_title));
		$this->assertTrue($this->setField('data[Bookmark][url]', $this->input_url));
		$this->assertTrue($this->setField('data[Bookmark][reading_list]', $reading_list ? "1" : false));
		$this->click("Submit");

		$this->verify_page_load();

		$this->assertPattern("/$this->input_title/");
		$this->assertPattern("/$this->input_url/");

		if ($reading_list) {
			$this->assertPattern("/This is on your reading list./");
		}
		else {
			$this->assertNoPattern("/This is on your reading list./");
		}
	}

	/**
	 * Adds two bookmarks, one on the reading list, the other not.
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function test_bookmark_add_reading_list() {
		$this->bookmark_add(true);
		$this->bookmark_add(false);
	}

	/**
	 * Adds a bookmark with a new keyword.
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function test_add_bookmark_with_new_keyword() {
		$this->load_bookmark_add_page();

		$this->input_title = String::uuid();
		$this->input_url = String::uuid().'.tld';
		$this->input_new_keyword = String::uuid();
		$this->assertTrue($this->setField('data[Bookmark][title]', $this->input_title));
		$this->assertTrue($this->setField('data[Bookmark][url]', $this->input_url));
		$this->assertTrue($this->setField('data[Keyword][title]', $this->input_new_keyword));
		$this->click("Submit");

		$this->verify_page_load();

		$this->assertPattern("/$this->input_title/");
		$this->assertPattern("/$this->input_url/");
		$this->assertPattern("/$this->input_new_keyword/");
		$this->assertNoPattern("/This is on your reading list./");
	}

	/**
	 * Adds a bookmark and selects the "Linux" keyword which has to exist at ID
	 * 124 in the database before this test.
	 *
	 * TODO create a keyword dynamically
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function test_add_bookmark_with_existing_keyword() {
		$this->load_bookmark_add_page();

		$this->input_title = String::uuid();
		$this->input_url = String::uuid().'.tld';
		$this->assertTrue($this->setField('data[Bookmark][title]', $this->input_title));
		$this->assertTrue($this->setField('data[Bookmark][url]', $this->input_url));
		$this->assertTrue($this->setField('data[Keyword][Keyword][]', array(124)));
		$this->click("Submit");

		$this->verify_page_load();

		$this->assertPattern("/$this->input_title/");
		$this->assertPattern("/$this->input_url/");
		$this->assertPattern('$<a href="[^"]+" class="black">Linux</a>$');
		$this->assertNoPattern("/This is on your reading list./");
	}


	/*************************************************************************/
	/*                                                                       */
	/*                                Editing                                */
	/*                                                                       */
	/*************************************************************************/

	/**<commit_msg>better parsing for new tags, using local variables<commit_after><?php
// Copyright (c) 2011 <NAME> <<EMAIL>>

App::import('Lib', 'CakemarksWebTestCase');

/**
 * Exercises the bookmarks.
 *
 * @author <NAME> <<EMAIL>>
 */
class BookmarkTestCase extends CakemarksWebTestCase {
	/**
	 * Loads the bookmark adding view.
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function load_bookmark_add_page() {
		$this->get($this->baseurl."/bookmarks/add");
		$this->verify_page_load();
		$this->assertPattern("/Add Bookmark/");
	}

	/**
	 * Adds a bookmark which can be on the reading list and does not have any
	 * keywords.
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function bookmark_add($reading_list = false) {
		$this->load_bookmark_add_page();

		$this->input_title = String::uuid();
		$this->input_url = String::uuid().'.tld';
		$this->assertTrue($this->setField('data[Bookmark][title]', $this->input_title));
		$this->assertTrue($this->setField('data[Bookmark][url]', $this->input_url));
		$this->assertTrue($this->setField('data[Bookmark][reading_list]', $reading_list ? "1" : false));
		$this->click("Submit");

		$this->verify_page_load();

		$this->assertPattern("/$this->input_title/");
		$this->assertPattern("/$this->input_url/");

		if ($reading_list) {
			$this->assertPattern("/This is on your reading list./");
		}
		else {
			$this->assertNoPattern("/This is on your reading list./");
		}
	}

	/**
	 * Adds two bookmarks, one on the reading list, the other not.
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function test_bookmark_add_reading_list() {
		$this->bookmark_add(true);
		$this->bookmark_add(false);
	}

	/**
	 * Adds a bookmark with a new keyword.
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function test_add_bookmark_with_new_keyword() {
		$this->load_bookmark_add_page();

		$input_title = String::uuid();
		$input_url = String::uuid().'.tld';
		$input_new_keyword = String::uuid();
		$this->assertTrue($this->setField('data[Bookmark][title]', $input_title));
		$this->assertTrue($this->setField('data[Bookmark][url]', $input_url));
		$this->assertTrue($this->setField('data[Keyword][title]', $input_new_keyword));
		$this->click("Submit");

		$this->verify_page_load();

		$this->assertPattern("/$input_title/");
		$this->assertPattern("/$input_url/");
		$this->assertPattern('#<div class="small_tag">[\s\n]*<a href="[^"]+" class="black">'.$input_new_keyword.'#');
		$this->assertNoPattern("/This is on your reading list./");
	}

	/**
	 * Adds a bookmark and selects the "Linux" keyword which has to exist at ID
	 * 124 in the database before this test.
	 *
	 * TODO create a keyword dynamically
	 *
	 * @author <NAME> <<EMAIL>>
	 */
	function test_add_bookmark_with_existing_keyword() {
		$this->load_bookmark_add_page();

		$this->input_title = String::uuid();
		$this->input_url = String::uuid().'.tld';
		$this->assertTrue($this->setField('data[Bookmark][title]', $this->input_title));
		$this->assertTrue($this->setField('data[Bookmark][url]', $this->input_url));
		$this->assertTrue($this->setField('data[Keyword][Keyword][]', array(124)));
		$this->click("Submit");

		$this->verify_page_load();

		$this->assertPattern("/$this->input_title/");
		$this->assertPattern("/$this->input_url/");
		$this->assertPattern('$<div class="small_tag">\s*<a href="[^"]+" class="black">Linux</a>$');
		$this->assertNoPattern("/This is on your reading list./");
	}


	/*************************************************************************/
	/*                                                                       */
	/*                                Editing                                */
	/*                                                                       */
	/*************************************************************************/

	/**
{'fraction_non_alphanumeric': 0.23213564796124345, 'fraction_numerical': 0.002960570582694119, 'mean_word_length': 3.7037974683544306, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 175, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1540520', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2331, 'n_words': 403}