<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id: CriteriaTest.class.php 9319 2007-01-17 15:07:44Z friebe $ 
 */
 
  uses(
    'rdbms.Criteria',
    'rdbms.DriverManager',
    'unittest.TestCase',
    'rdbms.join.JoinProcessor',
    'net.xp_framework.unittest.rdbms.dataset.Job'
  );

  /**
   * Test JoinProcessor class
   *
   * Note: We're relying on the connection to be a mysql connection -
   * otherwise, quoting and date representation may change and make
   * this testcase fail.
   *
   * @see      xp://rdbms.join.JoinProcessor
   * @purpose  Unit Test
   */
  class JoinProcessorTest extends TestCase {
  
    /**
     * Constructor
     *
     * @param   string name
     */
    public function __construct($name) {
      parent::__construct($name);
      ConnectionManager::getInstance()->register(DriverManager::getConnection('mysql://localhost:3306/'), 'jobs');
    }
    
    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#getAttributeString
     */
    #[@test]
    public function getAttributeStringTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array('PersonJob->Department' => 'join'));
      $this->assertEquals(
        $jp->getAttributeString(),
        JoinProcessor::FIRST.'.job_id as '.JoinProcessor::FIRST.'_job_id, '
        .JoinProcessor::FIRST.'.title as '.JoinProcessor::FIRST.'_title, '
        .JoinProcessor::FIRST.'.valid_from as '.JoinProcessor::FIRST.'_valid_from, '
        .JoinProcessor::FIRST.'.expire_at as '.JoinProcessor::FIRST.'_expire_at, '
        .JoinProcessor::pathToKey(array('PersonJob')).'.person_id as '.JoinProcessor::pathToKey(array('PersonJob')).'_person_id, '
        .JoinProcessor::pathToKey(array('PersonJob')).'.name as '.JoinProcessor::pathToKey(array('PersonJob')).'_name, '
        .JoinProcessor::pathToKey(array('PersonJob')).'.job_id as '.JoinProcessor::pathToKey(array('PersonJob')).'_job_id, '
        .JoinProcessor::pathToKey(array('PersonJob')).'.department_id as '.JoinProcessor::pathToKey(array('PersonJob')).'_department_id, '
        .JoinProcessor::pathToKey(array('PersonJob', 'Department')).'.department_id as '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).'_department_id, '
        .JoinProcessor::pathToKey(array('PersonJob', 'Department')).'.name as '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).'_name, '
        .JoinProcessor::pathToKey(array('PersonJob', 'Department')).'.chief_id as '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).'_chief_id'
      );
    }

    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#getJoinString
     */
    #[@test]
    public function getJoinStringTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array('PersonJob' => 'join'));
      $jp->setFetchModes(array('PersonJob->Department' => 'join'));
      $this->assertEquals(
        'JOBS.job as '.JoinProcessor::FIRST.' LEFT OUTER JOIN JOBS.Person as '.JoinProcessor::pathToKey(array('PersonJob')).' on ('.JoinProcessor::FIRST.'.job_id = '.JoinProcessor::pathToKey(array('PersonJob')).'.job_id) LEFT JOIN JOBS.Department as '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).' on ('.JoinProcessor::pathToKey(array('PersonJob')).'.department_id = '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).'.department_id) where ',
        $jp->getJoinString()
      );
    }

    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#setFetchModes
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function emptyModeTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array());
    }

    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#setFetchModes
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function noJoinModeTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array('JobPerson.Department' => 'select'));
    }

    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#setFetchModes
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function noSuchRoleTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array('UnknowenRole' => 'join'));
    }

  }
?>
<commit_msg>- Make independant of DriverManager<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id: CriteriaTest.class.php 9319 2007-01-17 15:07:44Z friebe $ 
 */
 
  uses(
    'rdbms.Criteria',
    'rdbms.DriverManager',
    'unittest.TestCase',
    'rdbms.join.JoinProcessor',
    'rdbms.mysql.MySQLConnection',
    'net.xp_framework.unittest.rdbms.dataset.Job'
  );

  /**
   * Test JoinProcessor class
   *
   * Note: We're relying on the connection to be a mysql connection -
   * otherwise, quoting and date representation may change and make
   * this testcase fail.
   *
   * @see      xp://rdbms.join.JoinProcessor
   * @purpose  Unit Test
   */
  class JoinProcessorTest extends TestCase {
  
    /**
     * Make Job's peer use mysql
     *
     */
    public function setUp() {
      Job::getPeer()->setConnection(new MySQLConnection(new DSN('mysql://localhost:3306/')));
    }
    
    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#getAttributeString
     */
    #[@test]
    public function getAttributeStringTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array('PersonJob->Department' => 'join'));
      $this->assertEquals(
        $jp->getAttributeString(),
        JoinProcessor::FIRST.'.job_id as '.JoinProcessor::FIRST.'_job_id, '
        .JoinProcessor::FIRST.'.title as '.JoinProcessor::FIRST.'_title, '
        .JoinProcessor::FIRST.'.valid_from as '.JoinProcessor::FIRST.'_valid_from, '
        .JoinProcessor::FIRST.'.expire_at as '.JoinProcessor::FIRST.'_expire_at, '
        .JoinProcessor::pathToKey(array('PersonJob')).'.person_id as '.JoinProcessor::pathToKey(array('PersonJob')).'_person_id, '
        .JoinProcessor::pathToKey(array('PersonJob')).'.name as '.JoinProcessor::pathToKey(array('PersonJob')).'_name, '
        .JoinProcessor::pathToKey(array('PersonJob')).'.job_id as '.JoinProcessor::pathToKey(array('PersonJob')).'_job_id, '
        .JoinProcessor::pathToKey(array('PersonJob')).'.department_id as '.JoinProcessor::pathToKey(array('PersonJob')).'_department_id, '
        .JoinProcessor::pathToKey(array('PersonJob', 'Department')).'.department_id as '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).'_department_id, '
        .JoinProcessor::pathToKey(array('PersonJob', 'Department')).'.name as '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).'_name, '
        .JoinProcessor::pathToKey(array('PersonJob', 'Department')).'.chief_id as '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).'_chief_id'
      );
    }

    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#getJoinString
     */
    #[@test]
    public function getJoinStringTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array('PersonJob' => 'join'));
      $jp->setFetchModes(array('PersonJob->Department' => 'join'));
      $this->assertEquals(
        'JOBS.job as '.JoinProcessor::FIRST.' LEFT OUTER JOIN JOBS.Person as '.JoinProcessor::pathToKey(array('PersonJob')).' on ('.JoinProcessor::FIRST.'.job_id = '.JoinProcessor::pathToKey(array('PersonJob')).'.job_id) LEFT JOIN JOBS.Department as '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).' on ('.JoinProcessor::pathToKey(array('PersonJob')).'.department_id = '.JoinProcessor::pathToKey(array('PersonJob', 'Department')).'.department_id) where ',
        $jp->getJoinString()
      );
    }

    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#setFetchModes
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function emptyModeTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array());
    }

    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#setFetchModes
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function noJoinModeTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array('JobPerson.Department' => 'select'));
    }

    /**
     * Tests extraction from record
     *
     * @see     xp://rdbms.join.JoinProcessor#setFetchModes
     */
    #[@test, @expect('lang.IllegalArgumentException')]
    public function noSuchRoleTest() {
      $jp= new JoinProcessor(Job::getPeer());
      $jp->setFetchModes(array('UnknowenRole' => 'join'));
    }

  }
?>

{'fraction_non_alphanumeric': 0.16897133220910623, 'fraction_numerical': 0.004946599213041034, 'mean_word_length': 3.562051282051282, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '2017337', 'n_tokens_mistral': 2866, 'n_tokens_neox': 2720, 'n_words': 428}