<commit_before><?php

namespace Tools\Test\TestCase\Model\Behavior;

use Cake\Database\Query;
use Cake\Datasource\ConnectionManager;
use Cake\Event\Event;
use Cake\ORM\Entity;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Cake\Core\Configure;

/**
 * SluggedBehaviorTest
 */
class SluggedBehaviorTest extends TestCase {

/**
 * Fixture
 *
 * @var array
 */
	public $fixtures = [
		'plugin.tools.slugged_articles'
	];

/**
 * setup
 *
 * @return void
 */
	public function setUp() {
		parent::setUp();
		//$this->connection = ConnectionManager::get('test');

		$options = ['alias' => 'Articles'];
		$this->articles = TableRegistry::get('SluggedArticles', $options);
		Configure::delete('Slugged');

		$this->articles->addBehavior('Tools.Slugged');
	}

/**
 * teardown
 *
 * @return void
 */
	public function tearDown() {
		unset($this->articles);

 		TableRegistry::clear();
 		parent::tearDown();
	}

/**
 * Testing simple slugging when adding a record
 *
 * @return void
 */
	public function testAdd() {
		$entity = $this->_getEntity();
		$result = $this->articles->save($entity);

		$this->assertEquals('test-123', $result->get('slug'));
	}

/**
 * Testing simple slugging when adding a record
 *
 * @return void
 */
	public function testAddUnique() {
		$this->articles->behaviors()->Slugged->config(['unique' => true]);

		$entity = $this->_getEntity();
		$result = $this->articles->save($entity);
		$this->assertEquals('test-123', $result->get('slug'));

		//$entity = $this->_getEntity();
		//$result = $this->articles->save($entity);
		//$this->assertEquals('test-123', $result->get('slug'));
		//debug($result);
	}

/**
 * SluggedBehaviorTest::testCustomFinder()
 *
 * @return void
 */
	public function testCustomFinder() {
		$article = $this->articles->find()->find('slugged', ['slug' => 'foo'])->first();
		$this->assertEquals('Foo', $article->get('title'));
	}

	/**
	 * Tests that manual slugging works.
	 *
	 * @return void
	 */
	public function testSlugManualSave() {
		$article = $this->articles->newEntity(array('title' => 'Some Cool String'));
		$result = $this->articles->save($article);
		$this->assertEquals('Some-Cool-String', $result['slug']);

		$this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'slug' => 'foo-bar']);
		$result = $this->articles->save($article);
		$this->assertEquals('foo-bar', $result['slug']);

		$this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'slug' => 'foo-bar-bat']);
		$result = $this->articles->save($article);<commit_msg>More tests.<commit_after><?php

namespace Tools\Test\TestCase\Model\Behavior;

use Cake\Database\Query;
use Cake\Datasource\ConnectionManager;
use Cake\Event\Event;
use Cake\ORM\Entity;
use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Cake\Core\Configure;

/**
 * SluggedBehaviorTest
 */
class SluggedBehaviorTest extends TestCase {

/**
 * Fixture
 *
 * @var array
 */
	public $fixtures = [
		'plugin.tools.slugged_articles'
	];

/**
 * setup
 *
 * @return void
 */
	public function setUp() {
		parent::setUp();
		//$this->connection = ConnectionManager::get('test');

		$options = ['alias' => 'Articles'];
		$this->articles = TableRegistry::get('SluggedArticles', $options);
		Configure::delete('Slugged');

		$this->articles->addBehavior('Tools.Slugged');
	}

/**
 * teardown
 *
 * @return void
 */
	public function tearDown() {
		unset($this->articles);

 		TableRegistry::clear();
 		parent::tearDown();
	}

/**
 * Testing simple slugging when adding a record
 *
 * @return void
 */
	public function testAdd() {
		$entity = $this->_getEntity();
		$result = $this->articles->save($entity);

		$this->assertEquals('test-123', $result->get('slug'));
	}

/**
 * Testing simple slugging when adding a record
 *
 * @return void
 */
	public function testAddUnique() {
		$this->articles->behaviors()->Slugged->config(['unique' => true]);

		$entity = $this->_getEntity();
		$result = $this->articles->save($entity);
		$this->assertEquals('test-123', $result->get('slug'));

		//$entity = $this->_getEntity();
		//$result = $this->articles->save($entity);
		//$this->assertEquals('test-123', $result->get('slug'));
		//debug($result);
	}

/**
 * SluggedBehaviorTest::testCustomFinder()
 *
 * @return void
 */
	public function testCustomFinder() {
		$article = $this->articles->find()->find('slugged', ['slug' => 'foo'])->first();
		$this->assertEquals('Foo', $article->get('title'));
	}

	/**
	 * Tests that manual slugging works.
	 *
	 * @return void
	 */
	public function testSlugManualSave() {
		$article = $this->articles->newEntity(array('title' => 'Some Cool String'));
		$result = $this->articles->save($article);
		$this->assertEquals('Some-Cool-String', $result['slug']);

		$article = $this->articles->newEntity(array('title' => 'Some Other String'));
		$result = $this->articles->save($article);
		$this->assertEquals('Some-Other-String', $result['slug']);

		$this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'slug' => 'foo-bar']);
		$result = $this->articles->save($article);
		$this->assertEquals('foo-bar', $result['slug']);

		$this->articles->patchEntity($article, ['title' => 'Some Cool Other String', 'slug' => 'foo-bar-bat']);
		$result = $this->articles->save($article);
{'fraction_non_alphanumeric': 0.21104201997361974, 'fraction_numerical': 0.0033917467495760316, 'mean_word_length': 4.5814931650893795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 113, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4039181', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1725, 'n_words': 317}