<commit_before><?php defined('SYSPATH') OR die('No direct script access.');

/**
 * @package Jamaker
 * @group   jamaker
 * @group   jamaker.definition
 * @group   jamaker.definition.attributes
 */
class Jamaker_Definition_AttributesTest extends Unittest_Jamaker_TestCase {

	public function provider_static()
	{
		return array(
			array(array('first_name' => 'John', 'last_name' => 'Doe', 'admin' => TRUE)),
			array(array('first_name' => 'Michael', 'last_name' => 'Smith', 'admin' => FALSE)),
			array(array('first_name' => 'Alex', 'last_name' => 'Hill', 'admin' => TRUE)),
		);
	}

	/**
	 * @dataProvider provider_static
	 */
	public function test_static($attributes)
	{
		Jamaker::define('jamaker_user', $attributes);

		$user = Jamaker::build('jamaker_user', array('email' => '<EMAIL>'));

		$this->assertInstanceOf('Model_Jamaker_User', $user, 'Should build the right Jelly_Model object');
		$this->assertAttributes($attributes, $user);
		$this->assertEquals('<EMAIL>', $user->email, 'Should use overrides');
	}

	public function test_sequence()
	{
		$user_maker = Jamaker::define('jamaker_user', array(
			// Sequence only iterator number
			'id' => Jamaker::sequence(),

			// Sequence with initial parameter
			'first_name' => Jamaker::sequence('Name$n', 10),

			// Sequence of arrays, will loop through them continuously
			'last_name' => Jamaker::sequence(array('Fam1', 'Fam2', 'Fam3')),

			// Sequence with a callback
			'email' => Jamaker::sequence(function($n){ return 'me'.$n.'<EMAIL>'; }),

			// Shorthand string sequence
			'username' => 'user-$n',

			'admin' => array(TRUE, FALSE)
		));

		$user_maker = array(
			Jamaker::build('jamaker_user'),
			Jamaker::build('jamaker_user'),
			Jamaker::build('jamaker_user'),
			Jamaker::build('jamaker_user')
		);

		$this->assertAttributes(array(
			'id' => 1, 
			'first_name' => 'Name10', 
			'last_name' => 'Fam1', 
			'email' => '<EMAIL>', 
			'username' => 'user-1', 
			'admin' => TRUE, 
		), $user_maker[0]);

		$this->assertAttributes(array(
			'id' => 2, 
			'first_name' => 'Name11', 
			'last_name' => 'Fam2', 
			'email' => '<EMAIL>', 
			'username' => 'user-2', 
			'admin' => FALSE, 
		), $user_maker[1]);

		$this->assertAttributes(array(
			'id' => 3, 
			'first_name' => 'Name12', 
			'last_name' => 'Fam3', 
			'email' => '<EMAIL>', 
			'username' => 'user-3', 
			'admin' => TRUE, 
		), $user_maker[2]);

		$this->assertAttributes(array(
			'id' => 4, 
			'first_name' => 'Name13', 
			'last_name' => 'Fam1', 
			'email' => '<EMAIL>', 
			'username' => 'user-4', 
			'admin' => FALSE, 
		), $user_maker[3]);

	}

	public function test_dynamic()
	{
		Jamaker::define('jamaker_user', array(
			'id' => 10,
			'first_name' => function($attrs){ return $attrs['id'].' clusure'; },
			'last_name' => 'Jamaker_Definition_AttributesTest::_test_dynamic_call',
		));

		$user = Jamaker::build('jamaker_user');
		$this->assertAttributes(array('id' => 10, 'first_name' => '10 clusure', 'last_name' => '10 method 10 clusure' ), $user);
	}

	static public function _test_dynamic_call($attrs)
	{
		return $attrs['id'].' method '.$attrs['first_name'];
	}

	public function test_association_belongsto()
	{
		Jamaker::define('jamaker_user', array(
			'first_name' => 'John',
			'last_name' => 'Doe',
		));

		Jamaker::define('jamaker_invite', array(
			'user' => 'jamaker_user',
		));

		Jamaker::define('jamaker_account', array(
			'user' => Jamaker::association('jamaker_user', array('last_name' => 'Dimo'), 'create')
		));

		$jamaker_user = Jamaker::build('jamaker_user');

		Jamaker::factory('jamaker_account_static', array('class' => 'Model_Jamaker_User'), array(
			'user' => $jamaker_user
		));

		$invite = Jamaker::build('jamaker_invite');<commit_msg>fixes in populator::all_terms and content tests<commit_after><?php defined('SYSPATH') OR die('No direct script access.');

/**
 * @package Jamaker
 * @group   jamaker
 * @group   jamaker.definition
 * @group   jamaker.definition.attributes
 */
class Jamaker_Definition_AttributesTest extends Unittest_Jamaker_TestCase {

	public function provider_static()
	{
		return array(
			array(array('first_name' => 'John', 'last_name' => 'Doe', 'admin' => TRUE)),
			array(array('first_name' => 'Michael', 'last_name' => 'Smith', 'admin' => FALSE)),
			array(array('first_name' => 'Alex', 'last_name' => 'Hill', 'admin' => TRUE)),
		);
	}

	/**
	 * @dataProvider provider_static
	 */
	public function test_static($attributes)
	{
		Jamaker::define('jamaker_user', $attributes);

		$user = Jamaker::build('jamaker_user', array('email' => '<EMAIL>'));

		$this->assertInstanceOf('Model_Jamaker_User', $user, 'Should build the right Jelly_Model object');
		$this->assertAttributes($attributes, $user);
		$this->assertEquals('<EMAIL>', $user->email, 'Should use overrides');
	}

	public function test_sequence()
	{
		$user_maker = Jamaker::define('jamaker_user', array(
			// Sequence only iterator number
			'id' => Jamaker::sequence(),

			// Sequence with initial parameter
			'first_name' => Jamaker::sequence('Name$n', 10),

			// Sequence of arrays, will loop through them continuously
			'last_name' => Jamaker::sequence(array('Fam1', 'Fam2', 'Fam3')),

			// Sequence with a callback
			'email' => Jamaker::sequence(function($n){ return 'me'.$n.'<EMAIL>'; }),

			// Shorthand string sequence
			'username' => 'user-$n',

			'admin' => array(TRUE, FALSE)
		));

		$user_maker = array(
			Jamaker::build('jamaker_user'),
			Jamaker::build('jamaker_user'),
			Jamaker::build('jamaker_user'),
			Jamaker::build('jamaker_user')
		);

		$this->assertAttributes(array(
			'id' => 1, 
			'first_name' => 'Name10', 
			'last_name' => 'Fam1', 
			'email' => '<EMAIL>', 
			'username' => 'user-1', 
			'admin' => TRUE, 
		), $user_maker[0]);

		$this->assertAttributes(array(
			'id' => 2, 
			'first_name' => 'Name11', 
			'last_name' => 'Fam2', 
			'email' => '<EMAIL>', 
			'username' => 'user-2', 
			'admin' => FALSE, 
		), $user_maker[1]);

		$this->assertAttributes(array(
			'id' => 3, 
			'first_name' => 'Name12', 
			'last_name' => 'Fam3', 
			'email' => '<EMAIL>', 
			'username' => 'user-3', 
			'admin' => TRUE, 
		), $user_maker[2]);

		$this->assertAttributes(array(
			'id' => 4, 
			'first_name' => 'Name13', 
			'last_name' => 'Fam1', 
			'email' => '<EMAIL>', 
			'username' => 'user-4', 
			'admin' => FALSE, 
		), $user_maker[3]);

	}

	public function test_dynamic()
	{
		Jamaker::define('jamaker_user', array(
			'id' => 10,
			'first_name' => function($attrs){ return $attrs['id'].' clusure'; },
			'last_name' => 'Jamaker_Definition_AttributesTest::_test_dynamic_call',
		));

		$user = Jamaker::build('jamaker_user');
		$this->assertAttributes(array('id' => 10, 'first_name' => '10 clusure', 'last_name' => '10 method 10 clusure' ), $user);
	}

	static public function _test_dynamic_call($attrs)
	{
		return $attrs['id'].' method '.$attrs['first_name'];
	}

	public function test_association_belongsto()
	{
		Jamaker::define('jamaker_user', array(
			'first_name' => 'John',
			'last_name' => 'Doe',
		));

		Jamaker::define('jamaker_invite', array(
			'user' => 'jamaker_user',
		));

		Jamaker::define('jamaker_account', array(
			'user' => Jamaker::association('jamaker_user', array('last_name' => 'Dimo'), 'create')
		));

		$jamaker_user = Jamaker::build('jamaker_user');

		Jamaker::define('jamaker_account_static', array('class' => 'Model_Jamaker_User'), array(
			'user' => $jamaker_user
		));

		$invite = Jamaker::build('jamaker_invite');
{'fraction_non_alphanumeric': 0.203874415497662, 'fraction_numerical': 0.010420841683366733, 'mean_word_length': 4.488269794721408, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 141, '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': '4322386', 'n_tokens_mistral': 3083, 'n_tokens_neox': 2655, 'n_words': 488}