<commit_before><?php

use PHPUnit\Framework\TestCase;

// fixme - there should be a pattern for this
require_once realpath(dirname(__FILE__)) .  '/../../CRM/Clif/CRM_Clif_Engine.php';


class AgcClifTest extends TestCase {

  public function testGetLogic() {
    // Arrange
    $list_A = array(1, 2, 3);
    $list_B = array(3, 4, 5);
    $list_C = array(6, 8);
    $filter_A = CRM_Clif_Engine::contactIdsToClif($list_A);
    $filter_B = CRM_Clif_Engine::contactIdsToClif($list_B);
    $filter_C = CRM_Clif_Engine::contactIdsToClif($list_C);
    $tests = array(
      array(
        'title' => 'empty',
        'clif' => array('type' => 'empty'), // bad case
        'expected' => array()
      ),
      array(
        'title' => 'raw',
        'clif' => array(
          'type' => 'raw',
          'params'=> array(10=>1, 20=>1)
        ),
        'expected' => array(10,20)
      ),
      array(
        'title' => 'union',
        'clif' => array(
          'type' => 'union',
          'params'=> array($filter_A, $filter_B)
        ),
        'expected' => array(1,2,3,4,5)
      ),
      array(
        'title' => 'intersection',
        'clif' => array(
          'type' => 'intersection',
          'params'=> array($filter_A, $filter_B)
        ),
        'expected' => array(3)
      ),
    );
    foreach ($tests as $test) {
      // Act
      $clif = new CRM_Clif_Engine(array(
        'clif' => $test['clif'],
      ));
      try {
        $result = $clif->get(array(
          'length' => 1000,
        ));
      }
      catch (Exception $e) {<commit_msg>perform test with API mock<commit_after><?php

use PHPUnit\Framework\TestCase;

// fixme - there should be a pattern for this
require_once realpath(dirname(__FILE__)) .  '/../../CRM/Clif/CRM_Clif_Engine.php';


class AgcClifTest extends TestCase {

  public function testGetLogic() {
    $api_mock = function($entity, $action, $params) {
      $values = array(
         array(
          "entity_id" => "3",
          "id" => "503"
        ),
         array(
          "entity_id" => "5",
          "id" => "505"
        ),
      );
      return array(
        "is_error" => 0,
        "version" => 3,
        "count" => count($values),
        "values" => $values
        );
    };

    // Arrange
    $list_A = array(1, 2, 3);
    $list_B = array(3, 4, 5);
    $list_C = array(6, 8);
    $filter_A = CRM_Clif_Engine::contactIdsToClif($list_A);
    $filter_B = CRM_Clif_Engine::contactIdsToClif($list_B);
    $filter_C = CRM_Clif_Engine::contactIdsToClif($list_C);
    // todo test this!
    $filter_api_group = array(
      'type' => 'api3',
      'params' => array(
        'entity' => "GroupContact",
        'action' => "get",
        'params' => array(
          'group_id' => array('IN' => array("Qld_All", "L2Vic")),
          'status' => "Added",
        )
      )
    );
    $filter_api_group = array(
      'type' => 'api3',
      'params' => array(
        'entity' => 'EntityTag',
        'action' => "get",
        'params' => array(
          'tag_id' => array('IN' => array("testing tag 1473109397")),
          'entity_table' => "civicrm_contact",
        )
      )
    );

    $tests = array(
      array(
        'title' => 'empty',
        'clif' => array('type' => 'empty'), // bad case
        'expected' => array()
      ),
      array(
        'title' => 'raw',
        'clif' => array(
          'type' => 'raw',
          'params'=> array(10=>1, 20=>1)
        ),
        'expected' => array(10,20)
      ),
      array(
        'title' => 'union',
        'clif' => array(
          'type' => 'union',
          'params'=> array($filter_A, $filter_B)
        ),
        'expected' => array(1,2,3,4,5)
      ),
      array(
        'title' => 'intersection',
        'clif' => array(
          'type' => 'intersection',
          'params'=> array($filter_A, $filter_B)
        ),
        'expected' => array(3)
      ),
      array(
        'title' => 'api group',
        'clif' => $filter_api_group,
        'expected' => array(3,5)
      ),
    );
    foreach ($tests as $test) {
      // Act
      $clif = new CRM_Clif_Engine(array(
        'clif' => $test['clif'],
        'inject' => array(
          'api3' => $api_mock
        )
      ));
      try {
        $result = $clif->get(array(
          'length' => 1000,
        ));
      }
      catch (Exception $e) {
{'fraction_non_alphanumeric': 0.18400549954170486, 'fraction_numerical': 0.018790100824931256, 'mean_word_length': 1.8325762491888384, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 80, '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': '6249222', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1501, 'n_words': 292}