<commit_before><?php


/**
 * Class DataObjectAnnotatorTest
 */
class DataObjectAnnotatorTest extends SapphireTest
{

    /**
     * @var $annotator MockDataObjectAnnotator
     */
    private $annotator = null;

    /**
     * Setup Defaults
     */
    public function setUp()
    {
        parent::setUp();
        Config::inst()->update('DataObjectAnnotator', 'enabled', true);
        Config::inst()->update('DataObjectAnnotator', 'enabled_modules', array('ideannotator'));

        Config::inst()->update('DataObjectAnnotatorTest_Team' , 'extensions',
            array('DataObjectAnnotatorTest_Team_Extension')
        );

        $this->annotator = MockDataObjectAnnotator::create();
    }

    /**
     * Test is a module name is in the @Config enabled_modules
     * and will be seen as allowed or disallowed correctly
     */
    public function testModuleIsAllowed()
    {
        $this->assertFalse($this->annotator->moduleIsAllowed('framework'));
        $this->assertTrue($this->annotator->moduleIsAllowed('mysite'));
        $this->assertTrue($this->annotator->moduleIsAllowed('ideannotator'));
    }

    /**
     * Test if a DataObject is in an allowed module name
     * and will be seen as allowed or disallowed correctly
     */
    public function testDataObjectIsAllowed()
    {
        $this->assertTrue($this->annotator->classNameIsAllowed('DataObjectAnnotatorTest_Team'));
        $this->assertTrue($this->annotator->classNameIsAllowed('DataObjectAnnotatorTest_Team_Extension'));

        $this->assertFalse($this->annotator->classNameIsAllowed('DataObject'));
        $this->assertFalse($this->annotator->classNameIsAllowed('File'));

        Config::inst()->remove('DataObjectAnnotator', 'enabled_modules');
        Config::inst()->update('DataObjectAnnotator', 'enabled_modules', array('mysite'));

        $this->assertFalse($this->annotator->classNameIsAllowed('DataObjectAnnotatorTest_Team'));
    }

    /**
     * Test if the correct annotations are generated
     * for all database fields, relations and extensions
     * and that the start and end tags are present
     */
    public function testFileContentWithAnnotations()
    {
        $filePath = $this->annotator->getClassFilePath('DataObjectAnnotatorTest_Team');
        $content  = $this->annotator->getFileContentWithAnnotations(file_get_contents($filePath),
            'DataObjectAnnotatorTest_Team');

        $this->assertTrue((bool)strpos($content, DataObjectAnnotator::STARTTAG));
        $this->assertTrue((bool)strpos($content, DataObjectAnnotator::ENDTAG));
        // database fields
        $this->assertTrue((bool)strpos($content, '@property string Title'));
        $this->assertTrue((bool)strpos($content, '@property int VisitCount'));
        // has_one ID
        $this->assertTrue((bool)strpos($content, '@property int CaptainID'));
        // had_one relation
        $this->assertTrue((bool)strpos($content, '@method DataObjectAnnotatorTest_Player Captain'));
        // has_many relation
        $this->assertTrue((bool)strpos($content, '@method DataList SubTeams'));
        // many_many relation
        $this->assertTrue((bool)strpos($content, '@method ManyManyList Players'));
        // DataExtension
        $this->assertTrue((bool)strpos($content, '@mixin DataObjectAnnotatorTest_Team_Extension'));
    }

    /**
     * Test if there are no generated annotations present
     */
    public function testFileContentWithoutAnnotations()
    {
        $filePath = $this->annotator->getClassFilePath('DataObjectAnnotatorTest_Team');
        $content  = $this->annotator->getFileContentWithoutAnnotations(file_get_contents($filePath));

        $this->assertFalse(strpos($content, DataObjectAnnotator::STARTTAG));
        $this->assertFalse(strpos($content, DataObjectAnnotator::ENDTAG));
        $this->assertFalse(strpos($content, '@property string Title'));
        $this->assertFalse(strpos($content, '@property int VisitCount'));
        $this->assertFalse(strpos($content, '@property int CaptainID'));
        $this->assertFalse(strpos($content, '@method DataObjectAnnotatorTest_Player Captain'));
        $this->assertFalse(strpos($content, '@method DataList SubTeams'));
        $this->assertFalse(strpos($content, '@method ManyManyList Players'));
        $this->assertFalse(strpos($content, '@mixin DataObjectAnnotatorTest_Team_Extension'));
    }

    /**
     * Test if an undo action will lead to the same file as the original file
     */
    public function testFileIsTheSameAfterUndoAnnotate()
    {
        $filePath  = $this->annotator->getClassFilePath('DataObjectAnnotatorTest_Team');
        $original  = file_get_contents($filePath);
        $annotated = $this->annotator->getFileContentWithAnnotations($original, 'DataObjectAnnotatorTest_Team');
        $undone    = $this->annotator->getFileContentWithoutAnnotations($annotated);

        $this->assertEquals($original, $undone);
    }

    /**
     * Test that multiple annotation runs won't generate ducplicate docblocks
     */
    public function testNothingHasChangedAfterSecondAnnotation()
    {
        $filePath  = $this->annotator->getClassFilePath('DataObjectAnnotatorTest_Team');<commit_msg>Fix test.<commit_after><?php


/**
 * Class DataObjectAnnotatorTest
 */
class DataObjectAnnotatorTest extends SapphireTest
{

    /**
     * @var $annotator MockDataObjectAnnotator
     */
    private $annotator = null;

    /**
     * Setup Defaults
     */
    public function setUp()
    {
        parent::setUp();
        Config::inst()->update('DataObjectAnnotator', 'enabled', true);
        Config::inst()->update('DataObjectAnnotator', 'enabled_modules', array('ideannotator'));

        Config::inst()->update('DataObjectAnnotatorTest_Team' , 'extensions',
            array('DataObjectAnnotatorTest_Team_Extension')
        );

        $this->annotator = MockDataObjectAnnotator::create();
    }

    /**
     * Test is a module name is in the @Config enabled_modules
     * and will be seen as allowed or disallowed correctly
     */
    public function testModuleIsAllowed()
    {
        $this->assertFalse($this->annotator->moduleIsAllowed('framework'));
        $this->assertTrue($this->annotator->moduleIsAllowed('mysite'));
        $this->assertTrue($this->annotator->moduleIsAllowed('ideannotator'));
    }

    /**
     * Test if a DataObject is in an allowed module name
     * and will be seen as allowed or disallowed correctly
     */
    public function testDataObjectIsAllowed()
    {
        $this->assertTrue($this->annotator->classNameIsAllowed('DataObjectAnnotatorTest_Team'));
        $this->assertTrue($this->annotator->classNameIsAllowed('DataObjectAnnotatorTest_Team_Extension'));

        $this->assertFalse($this->annotator->classNameIsAllowed('DataObject'));
        $this->assertFalse($this->annotator->classNameIsAllowed('File'));

        Config::inst()->remove('DataObjectAnnotator', 'enabled_modules');
        Config::inst()->update('DataObjectAnnotator', 'enabled_modules', array('mysite'));

        $this->assertFalse($this->annotator->classNameIsAllowed('DataObjectAnnotatorTest_Team'));
    }

    /**
     * Test if the correct annotations are generated
     * for all database fields, relations and extensions
     * and that the start and end tags are present
     */
    public function testFileContentWithAnnotations()
    {
        $filePath = $this->annotator->getClassFilePath('DataObjectAnnotatorTest_Team');
        $content  = $this->annotator->getFileContentWithAnnotations(file_get_contents($filePath),
            'DataObjectAnnotatorTest_Team');

        $this->assertTrue((bool)strpos($content, DataObjectAnnotator::STARTTAG));
        $this->assertTrue((bool)strpos($content, DataObjectAnnotator::ENDTAG));
        // database fields
        $this->assertTrue((bool)strpos($content, '@property string Title'));
        $this->assertTrue((bool)strpos($content, '@property int VisitCount'));
        // has_one ID
        $this->assertTrue((bool)strpos($content, '@property int CaptainID'));
        // had_one relation
        $this->assertTrue((bool)strpos($content, '@method DataObjectAnnotatorTest_Player Captain'));
        // has_many relation
        $this->assertTrue((bool)strpos($content, '@method DataList|DataObjectAnnotatorTest_SubTeam[] SubTeams'));
        // many_many relation
        $this->assertTrue((bool)strpos($content, '@method ManyManyList|Player[] Players'));
        // DataExtension
        $this->assertTrue((bool)strpos($content, '@mixin DataObjectAnnotatorTest_Team_Extension'));
    }

    /**
     * Test if there are no generated annotations present
     */
    public function testFileContentWithoutAnnotations()
    {
        $filePath = $this->annotator->getClassFilePath('DataObjectAnnotatorTest_Team');
        $content  = $this->annotator->getFileContentWithoutAnnotations(file_get_contents($filePath));

        $this->assertFalse(strpos($content, DataObjectAnnotator::STARTTAG));
        $this->assertFalse(strpos($content, DataObjectAnnotator::ENDTAG));
        $this->assertFalse(strpos($content, '@property string Title'));
        $this->assertFalse(strpos($content, '@property int VisitCount'));
        $this->assertFalse(strpos($content, '@property int CaptainID'));
        $this->assertFalse(strpos($content, '@method DataObjectAnnotatorTest_Player Captain'));
        $this->assertFalse(strpos($content, '@method DataList|DataObjectAnnotatorTest_SubTeam[] SubTeams'));
        $this->assertFalse(strpos($content, '@method ManyManyList|DataObjectAnnotatorTest_Player[] Players'));
        $this->assertFalse(strpos($content, '@mixin DataObjectAnnotatorTest_Team_Extension'));
    }

    /**
     * Test if an undo action will lead to the same file as the original file
     */
    public function testFileIsTheSameAfterUndoAnnotate()
    {
        $filePath  = $this->annotator->getClassFilePath('DataObjectAnnotatorTest_Team');
        $original  = file_get_contents($filePath);
        $annotated = $this->annotator->getFileContentWithAnnotations($original, 'DataObjectAnnotatorTest_Team');
        $undone    = $this->annotator->getFileContentWithoutAnnotations($annotated);

        $this->assertEquals($original, $undone);
    }

    /**
     * Test that multiple annotation runs won't generate ducplicate docblocks
     */
    public function testNothingHasChangedAfterSecondAnnotation()
    {
        $filePath  = $this->annotator->getClassFilePath('DataObjectAnnotatorTest_Team');
{'fraction_non_alphanumeric': 0.13386051829268292, 'fraction_numerical': 0.0, 'mean_word_length': 3.8755225267069204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 133, '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': '6519862', 'n_tokens_mistral': 2823, 'n_tokens_neox': 2836, 'n_words': 498}