<commit_before><?php

namespace Chamilo\Core\Repository\ContentObject\Rubric\Test\Unit\Service;

use Chamilo\Core\Repository\ContentObject\Rubric\Service\RubricValidator;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\CategoryNode;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\ClusterNode;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\CriteriumNode;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\RubricData;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\TreeNode;
use Chamilo\Libraries\Architecture\Test\TestCases\ChamiloTestCase;

/**
 * Tests the RubricValidator
 *
 * @author <NAME> - Hogesch<NAME>
 */
class RubricValidatorTest extends ChamiloTestCase
{
    /**
     * @var TreeNode
     */
    protected $rootNode;

    /**
     * @var RubricData
     */
    protected $rubricData;

    /**
     * @var RubricValidator
     */
    protected $rubricValidator;

    /**
     * Setup before each test
     */
    public function setUp()
    {
        $this->rubricValidator = new RubricValidator();

        $this->rubricData = new RubricData('Test Rubric');
        $this->rootNode = $this->rubricData->getRootNode();
        $this->rootNode->setId(1);

        $this->rootNode->addChild(new ClusterNode('Test Cluster 1', $this->rubricData));

        $clusterNode2 = new ClusterNode('Test Cluster 2', $this->rubricData);
        $clusterNode2->setId(2);
        $this->rootNode->addChild($clusterNode2);

        $clusterNode3 = new ClusterNode('Test Cluster 3', $this->rubricData);
        $clusterNode3->setId(3);
        $this->rootNode->addChild($clusterNode3);

        $categoryNode = new CategoryNode('Test Category 1', $this->rubricData);
        $categoryNode->setId(4);
        $clusterNode2->addChild($categoryNode);

        $categoryNode2 = new CategoryNode('Test Category 2', $this->rubricData);
        $categoryNode2->setId(5);
        $clusterNode2->addChild($categoryNode2);

        $criteriumNode = new CriteriumNode('Test Criterium 1', $this->rubricData);
        $criteriumNode->setId(6);
        $categoryNode->addChild($criteriumNode);
    }

    /**
     * Tear down after each test
     */
    public function tearDown()
    {
        unset($this->rubricValidator);
        unset($this->rootNode);
        unset($this->rubricData);
    }

    public function testValidator()
    {
        $this->assertNull($this->rubricValidator->validateRubric($this->rubricData));
    }

    /**
     * @expectedException \Chamilo\Core\Repository\ContentObject\Rubric\Domain\Exceptions\InvalidTreeStructureException
     */
    public function testValidatorWithDoubleSortValues()
    {
        $clusterNode3 = $this->rootNode->getChildren()[2];
        $clusterNode3->setSort(2);

        $this->rubricValidator->validateRubric($this->rubricData);
    }

    /**
     * @expectedException \Chamilo\Core\Repository\ContentObject\Rubric\Domain\Exceptions\InvalidTreeStructureException
     */
    public function testValidatorWithGapSortValues()
    {
        $clusterNode2 = $this->rootNode->getChildren()[1];
        $clusterNode2->setSort(3);

        $this->rubricValidator->validateRubric($this->rubricData);
    }

    /**
     * @expectedException \Exception
     */
    public function testValidatorOutOfRange()
    {
        $clusterNode2 = $this->rootNode->getChildren()[1];
        $clusterNode2->setSort(0);

        $this->rubricValidator->validateRubric($this->rubricData);
    }

    /**
     * @expectedException \Exception
     */
    public function testValidatorOutOfRangeUpperLimit()
    {
        $clusterNode2 = $this->rootNode->getChildren()[1];
        $clusterNode2->setSort(4);

        $this->rubricValidator->validateRubric($this->rubricData);
    }


<commit_msg>[Rubric] Moving to the domain model + testing<commit_after><?php

namespace Chamilo\Core\Repository\ContentObject\Rubric\Test\Unit\Service;

use Chamilo\Core\Repository\ContentObject\Rubric\Service\RubricValidator;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\CategoryNode;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\ClusterNode;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\CriteriumNode;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\RubricData;
use Chamilo\Core\Repository\ContentObject\Rubric\Storage\Entity\TreeNode;
use Chamilo\Libraries\Architecture\Test\TestCases\ChamiloTestCase;

/**
 * Tests the RubricValidator
 *
 * @author <NAME> - <NAME>
 */
class RubricValidatorTest extends ChamiloTestCase
{
    /**
     * @var TreeNode
     */
    protected $rootNode;

    /**
     * @var RubricData
     */
    protected $rubricData;

    /**
     * @var RubricValidator
     */
    protected $rubricValidator;

    /**
     * Setup before each test
     */
    public function setUp()
    {
        $this->rubricValidator = new RubricValidator();

        $this->rubricData = new RubricData('Test Rubric');
        $this->rootNode = $this->rubricData->getRootNode();
        $this->rootNode->setId(1);

        $this->rootNode->addChild(new ClusterNode('Test Cluster 1', $this->rubricData));

        $clusterNode2 = new ClusterNode('Test Cluster 2', $this->rubricData);
        $clusterNode2->setId(2);
        $this->rootNode->addChild($clusterNode2);

        $clusterNode3 = new ClusterNode('Test Cluster 3', $this->rubricData);
        $clusterNode3->setId(3);
        $this->rootNode->addChild($clusterNode3);

        $categoryNode = new CategoryNode('Test Category 1', $this->rubricData);
        $categoryNode->setId(4);
        $clusterNode2->addChild($categoryNode);

        $categoryNode2 = new CategoryNode('Test Category 2', $this->rubricData);
        $categoryNode2->setId(5);
        $clusterNode2->addChild($categoryNode2);

        $criteriumNode = new CriteriumNode('Test Criterium 1', $this->rubricData);
        $criteriumNode->setId(6);
        $categoryNode->addChild($criteriumNode);
    }

    /**
     * Tear down after each test
     */
    public function tearDown()
    {
        unset($this->rubricValidator);
        unset($this->rootNode);
        unset($this->rubricData);
    }

    public function testValidator()
    {
        $this->assertNull($this->rubricValidator->validateRubric($this->rubricData));
    }

    /**
     * @expectedException \Chamilo\Core\Repository\ContentObject\Rubric\Domain\Exceptions\InvalidTreeStructureException
     */
    public function testValidatorWithDoubleSortValues()
    {
        $clusterNode3 = $this->rootNode->getChildren()[2];
        $clusterNode3->setSort(2);

        $this->rubricValidator->validateRubric($this->rubricData);
    }

    /**
     * @expectedException \Chamilo\Core\Repository\ContentObject\Rubric\Domain\Exceptions\InvalidTreeStructureException
     */
    public function testValidatorWithGapSortValues()
    {
        $clusterNode2 = $this->rootNode->getChildren()[1];
        $clusterNode2->setSort(3);

        $this->rubricValidator->validateRubric($this->rubricData);
    }

    /**
     * @expectedException \Exception
     */
    public function testValidatorOutOfRange()
    {
        $clusterNode2 = $this->rootNode->getChildren()[1];
        $clusterNode2->setSort(0);

        $this->rubricValidator->validateRubric($this->rubricData);
    }

    /**
     * @expectedException \Exception
     */
    public function testValidatorOutOfRangeUpperLimit()
    {
        $clusterNode2 = $this->rootNode->getChildren()[1];
        $clusterNode2->setSort(4);

        $this->rubricValidator->validateRubric($this->rubricData);
    }

    /**
     * @expectedException \Chamilo\Core\Repository\ContentObject\Rubric\Domain\Exceptions\InvalidTreeStructureException
     */
    public function testValidatorWithWrongDepth()
    {
        $clusterNode2 = $this->rootNode->getChildren()[1];
        $clusterNode2->setDepth(2);

        $this->rubricValidator->validateRubric($this->rubricData);
    }

{'fraction_non_alphanumeric': 0.13673392655721267, 'fraction_numerical': 0.010276977064795087, 'mean_word_length': 3.2199894235854045, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 129, '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': '5034863', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2360, 'n_words': 319}