Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP和Laravel中使用Select2jQuery插件进行集成测试_Php_Jquery_Laravel_Phpunit - Fatal编程技术网

如何在PHP和Laravel中使用Select2jQuery插件进行集成测试

如何在PHP和Laravel中使用Select2jQuery插件进行集成测试,php,jquery,laravel,phpunit,Php,Jquery,Laravel,Phpunit,我正在使用PHPUnit和laravel5以及Laracasts集成包来集成测试我的web应用程序中的表单。表单由三个字段组成;标题、说明和标签。除了Tags字段外,所有字段都是输入文本字段,Tags字段是一个启用Tags选项的Select2插件 使用PHPUnit和Laracasts集成,我试图提交包含以下信息的表单: $this->submitForm('Post Job', [ 'title' => 'A test title', 'descript

我正在使用PHPUnit和laravel5以及Laracasts集成包来集成测试我的web应用程序中的表单。表单由三个字段组成;标题、说明和标签。除了Tags字段外,所有字段都是输入文本字段,Tags字段是一个启用Tags选项的Select2插件

使用PHPUnit和Laracasts集成,我试图提交包含以下信息的表单:

$this->submitForm('Post Job', [
    'title'       => 'A test title',
    'description' => 'A test description',
    'tags'        => 'Tag1, Tag2, Tag3'
]);
但是,我不断遇到以下错误:

There was 1 error:

1) PostAJobTest::it_successfully_posts_a_job
InvalidArgumentException: Input "tags" cannot take "Tag1, Tag2, Tag3" as a value (possible values: ).

/home/vagrant/Code/myproject/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Field/ChoiceFormField.php:144
/home/vagrant/Code/myproject/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/FormFieldRegistry.php:128
/home/vagrant/Code/myproject/vendor/symfony/dom-crawler/Symfony/Component/DomCrawler/Form.php:76
/home/vagrant/Code/myproject/vendor/laracasts/integrated/src/Extensions/IntegrationTrait.php:380
/home/vagrant/Code/myproject/vendor/laracasts/integrated/src/Extensions/Traits/LaravelTestCase.php:47
/home/vagrant/Code/myproject/tests/phpunit/HelpersTrait.php:107
/home/vagrant/Code/myproject/tests/phpunit/Functional/PostAJobTest.php:14
作为参考,my Select2元素的JS是:

$("#tags").select2({
    tags: true,
    tokenSeparators: [',', ','],
    maximumSelectionLength: 3,
    ajax: {
        url: "/api/tags",
        dataType: 'json',
        delay: 250,
        data: function (params) {
            return {
                tag: params.term
            };
        },
        processResults: function (data) {
            return {
                results: $.map(data, function (item) {
                    return {
                        id: item.id,
                        text: item.name
                    }
                 })
             };
        },
        cache: true
    }
});

使用“Tag1、Tag2和Tag3”输入Tags字段的方式似乎没有在Select2中注册,我无法解决此问题?

尝试将其设置为数组“Tags”=>[“Tag1”、“Tag2”、“Tag3”]应该说我已经尝试过了,但它不起作用如果您仔细想想,我们只是尝试将数据输入到文本字段中,为什么要将数据输入数组中的文本字段中。插件无论如何都会将其转换为数组。问题是我们如何将它插入一个字段中。这个插件只是一个很好的界面,可以控制一个底层的选择框或多选框。PHP不关心也不知道select2发生了什么,它所看到的只是底层的选择框,所以select2可能会被忽略,我们只是为select2设置值。