<commit_before><?php

namespace SilverStripe\AssetAdmin\Tests\Forms;

use SilverStripe\AssetAdmin\Controller\AssetAdmin;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\AssetAdmin\Tests\Forms\FileFormBuilderTest\FileOwner;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Image;
use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\ORM\ArrayList;

/**
 * @skipUpgrade
 */
class UploadFieldTest extends SapphireTest
{
    protected static $fixture_file = 'FileFormBuilderTest.yml';

    protected static $extra_dataobjects = [
        FileOwner::class,
    ];

    protected function setUp()
    {
        parent::setUp();

        // Set backend and base url
        TestAssetStore::activate('FileFormBuilderTest');

        /** @var File $testfile */
        $testfile = $this->objFromFixture(File::class, 'file1');
        $testfile->setFromLocalFile(__DIR__ . '/fixtures/testfile.txt', 'files/testfile.txt');
        $testfile->write();

        /** @var Image $testimage */
        $testimage = $this->objFromFixture(Image::class, 'image1');
        $testimage->setFromLocalFile(__DIR__ . '/fixtures/testimage.png', 'files/testimage.png');
    }

    public function tearDown()
    {
        TestAssetStore::reset();
        parent::tearDown();
    }

    public function testGetAttributes()
    {
        $field = UploadField::create('MyField');
        $field->addExtraClass('myfield');
        $field->setIsMultiUpload(false);
        $field->setFolderName('/');
        /** @var Image $image */
        $image = $this->objFromFixture(Image::class, 'image1');
        $field->setItems(new ArrayList([$image]));
        $admin = AssetAdmin::create();
        Form::create($admin, 'MyForm', FieldList::create($field), FieldList::create());

        $attributes = $field->getAttributes();
        $schema = [
            'name' => 'MyField',
            'id' => 'Form_MyForm_MyField',
            'type' => 'file',
            'component' => 'UploadField',
            'holderId' => 'Form_MyForm_MyField_Holder',
            'title' => 'My Field',
            'source' => null,
            'extraClass' => 'entwine-uploadfield uploadfield myfield',
            'description' => null,
            'rightTitle' => null,
            'leftTitle' => null,<commit_msg>Fix case difference in form field label assertion failure<commit_after><?php

namespace SilverStripe\AssetAdmin\Tests\Forms;

use SilverStripe\AssetAdmin\Controller\AssetAdmin;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\AssetAdmin\Tests\Forms\FileFormBuilderTest\FileOwner;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Image;
use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\ORM\ArrayList;

/**
 * @skipUpgrade
 */
class UploadFieldTest extends SapphireTest
{
    protected static $fixture_file = 'FileFormBuilderTest.yml';

    protected static $extra_dataobjects = [
        FileOwner::class,
    ];

    protected function setUp()
    {
        parent::setUp();

        // Set backend and base url
        TestAssetStore::activate('FileFormBuilderTest');

        /** @var File $testfile */
        $testfile = $this->objFromFixture(File::class, 'file1');
        $testfile->setFromLocalFile(__DIR__ . '/fixtures/testfile.txt', 'files/testfile.txt');
        $testfile->write();

        /** @var Image $testimage */
        $testimage = $this->objFromFixture(Image::class, 'image1');
        $testimage->setFromLocalFile(__DIR__ . '/fixtures/testimage.png', 'files/testimage.png');
    }

    public function tearDown()
    {
        TestAssetStore::reset();
        parent::tearDown();
    }

    public function testGetAttributes()
    {
        $field = UploadField::create('MyField');
        $field->addExtraClass('myfield');
        $field->setIsMultiUpload(false);
        $field->setFolderName('/');
        /** @var Image $image */
        $image = $this->objFromFixture(Image::class, 'image1');
        $field->setItems(new ArrayList([$image]));
        $admin = AssetAdmin::create();
        Form::create($admin, 'MyForm', FieldList::create($field), FieldList::create());

        $attributes = $field->getAttributes();
        $schema = [
            'name' => 'MyField',
            'id' => 'Form_MyForm_MyField',
            'type' => 'file',
            'component' => 'UploadField',
            'holderId' => 'Form_MyForm_MyField_Holder',
            'title' => 'My field',
            'source' => null,
            'extraClass' => 'entwine-uploadfield uploadfield myfield',
            'description' => null,
            'rightTitle' => null,
            'leftTitle' => null,
{'fraction_non_alphanumeric': 0.14616977225672878, 'fraction_numerical': 0.0012422360248447205, 'mean_word_length': 2.9565929565929565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '912307', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1430, 'n_words': 247}