<commit_before><?php

/**
 * @package         Tests
 * @copyright       Copyright (C) 2012-2016 BillRun Technologies Ltd. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Base test case class for testing an action to the API
 *
 * @package         Tests
 * @subpackage      API
 * @since           5.1
 */
require_once(APPLICATION_PATH . '/library/simpletest/autorun.php');

abstract class Tests_Api_Base_Action extends Tests_TestWrapper {

	/**
	 * Boolean indication for is the case cleared
	 * @var boolean
	 */
	protected $caseCleared = false;
	
	/**
	 * Array of tests.
	 * @var array
	 */
	protected $cases;
	
	/**
	 * Array of the API parameter names
	 * @var array
	 */
	protected $parameters;
	
	/**
	 *
	 * @var Mongodloid_Collection
	 */
	protected $coll;
	
	/**
	 * Current test case
	 * @var array
	 */
	protected $current;
	
	/**
	 * Create a new instance of the API Action test object.
	 * @param Mongodloid_Collection $collection
	 * @param type $testCases
	 * @param type $inputParameters
	 * @param type $internalTestInstance
	 * @param type $label
	 */
	public function __construct($collection, $testCases, $inputParameters, $internalTestInstance = null, $label = false) {
		if($internalTestInstance == null) {
			$internalTestInstance = $this;
		}
		parent::__construct($internalTestInstance, $label);
		
		$this->parameters = $inputParameters;
		$this->cases = $this->translateCases($testCases);
		$this->coll = $collection;
	}
	
	/**
	 * Get an instance of the action.
	 */
	protected abstract function getAction($param);
	
	/**
	 * Get the query 
	 * @return array query for the action.
	 */
	protected abstract function getQuery($case);
	
	/**
	 * Return the array of data that should be added to the DB for the current
	 * case.
	 * When the test tries to delete a record that does not exist, this function
	 * introduces the record to the DB to be removed after.
	 */
	protected abstract function getDataForDB($case);

	/**
	 * Translate the date fields
	 * Override this function for special case translation.
	 * @param type $cases
	 * @return type
	 */
	protected function translateCases($cases) {
		$translated = array();
		foreach ($cases as $caseIndex => $case) {
			if(Billrun_Util::isMultidimentionalArray($case)) {
				$translated[$caseIndex] = $this->translateCases($case);
			} else if(is_array($case)) {
				$translated[$caseIndex] = $this->translateCaseArray($case);
			} else {
				$translated[$caseIndex] = $case;
			}
		}
		return $translated;
	}<commit_msg>Fixed phpdocs<commit_after><?php

/**
 * @package         Tests
 * @copyright       Copyright (C) 2012-2016 BillRun Technologies Ltd. All rights reserved.
 * @license         GNU Affero General Public License Version 3; see LICENSE.txt
 */

/**
 * Base test case class for testing an action to the API
 *
 * @package         Tests
 * @subpackage      API
 * @since           5.1
 */
require_once(APPLICATION_PATH . '/library/simpletest/autorun.php');

abstract class Tests_Api_Base_Action extends Tests_TestWrapper {

	/**
	 * Boolean indication for is the case cleared
	 * @var boolean
	 */
	protected $caseCleared = false;
	
	/**
	 * Array of tests.
	 * @var array
	 */
	protected $cases;
	
	/**
	 * Array of the API parameter names
	 * @var array
	 */
	protected $parameters;
	
	/**
	 *
	 * @var Mongodloid_Collection
	 */
	protected $coll;
	
	/**
	 * Current test case
	 * @var array
	 */
	protected $current;
	
	/**
	 * Create a new instance of the API Action test object.
	 * @param Mongodloid_Collection $collection
	 * @param type $testCases
	 * @param type $inputParameters
	 * @param type $internalTestInstance
	 * @param type $label
	 */
	public function __construct($collection, $testCases, $inputParameters, $internalTestInstance = null, $label = false) {
		if($internalTestInstance == null) {
			$internalTestInstance = $this;
		}
		parent::__construct($internalTestInstance, $label);
		
		$this->parameters = $inputParameters;
		$this->cases = $this->translateCases($testCases);
		$this->coll = $collection;
	}
	
	/**
	 * Get an instance of the action.
	 * @return Billrun_ActionManagers_APIAction
	 */
	protected abstract function getAction($param = array());
	
	/**
	 * Get the query 
	 * @return array query for the action.
	 */
	protected abstract function getQuery($case);
	
	/**
	 * Return the array of data that should be added to the DB for the current
	 * case.
	 * When the test tries to delete a record that does not exist, this function
	 * introduces the record to the DB to be removed after.
	 * @param array $case - Current case being proccessed
	 * @return array Array to store in the data base.
	 */
	protected abstract function getDataForDB($case);

	/**
	 * Translate the date fields
	 * Override this function for special case translation.
	 * @param type $cases
	 * @return type
	 */
	protected function translateCases($cases) {
		$translated = array();
		foreach ($cases as $caseIndex => $case) {
			if(Billrun_Util::isMultidimentionalArray($case)) {
				$translated[$caseIndex] = $this->translateCases($case);
			} else if(is_array($case)) {
				$translated[$caseIndex] = $this->translateCaseArray($case);
			} else {
				$translated[$caseIndex] = $case;
			}
		}
		return $translated;
	}
{'fraction_non_alphanumeric': 0.11642411642411643, 'fraction_numerical': 0.004158004158004158, 'mean_word_length': 3.323529411764706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '1344305', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1488, 'n_words': 496}