Skip to content

Commit

Permalink
Merge pull request #11 from jdecool/feature/select2-multiple-choices
Browse files Browse the repository at this point in the history
Allow Select2 context to add multiple choice values
  • Loading branch information
jdecool committed Jan 4, 2016
2 parents 0364b0e + e1cf534 commit b564ce4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ php:
before_script:
- export DISPLAY=:99.0
- Xvfb $DISPLAY -extension RANDR &> /dev/null &
- curl http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar > selenium.jar
- curl http://selenium-release.storage.googleapis.com/2.48/selenium-server-standalone-2.48.2.jar > selenium.jar
- java -jar selenium.jar &> /dev/null &
- php -S localhost:8000 -t tests/fixtures/ &> /dev/null &
- cp behat.yml{-dist,}
- composer selfupdate
- composer self-update
- composer install

script:
Expand Down
4 changes: 2 additions & 2 deletions src/Context/Select2Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public function iShouldSeeSelectChoices($field, $num)
*/
private function openField(DocumentElement $page, $field)
{
$fieldName = sprintf('#select2-%s-container', $field);
$fieldName = sprintf('select[name="%s"] + .select2-container', $field);

$inputField = $page->find('css', $fieldName);
if (!$inputField) {
throw new \Exception(sprintf('No field "%s" found', $field));
}

$choice = $inputField->getParent()->find('css', '.select2-selection');
$choice = $inputField->find('css', '.select2-selection');
if (!$choice) {
throw new \Exception(sprintf('No select2 choice found for "%s"', $field));
}
Expand Down
12 changes: 12 additions & 0 deletions tests/features/fr/select2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ Fonctionnalité: Select2 Feature
Etant donné je suis sur "/select2.html"
Lorsque je remplis le champs de recherche select2 "select_number" avec "F"
Alors je devrais voir 2 éléments dans le champs select2 "select_number"

@javascript
Scénario:
Etant donné je suis sur "/select2-multiple.html"
Alors je remplis le champs select2 "Two" pour "select_number"
Et je remplis le champs select2 "Three" pour "select_number"

@javascript
Scénario:
Etant donné je suis sur "/select2-multiple.html"
Alors je remplis le champs select2 "Two" pour "select_number2"
Et je remplis le champs select2 "Three" pour "select_number2"
12 changes: 12 additions & 0 deletions tests/features/select2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ Feature: Select2 Feature
Given I am on "/select2.html"
When I fill in select2 input "select_number" with "F"
Then I should see 2 choice in select2 "select_number"

@javascript
Scenario:
Given I am on "/select2-multiple.html"
Then I fill in select2 "Two" for "select_number"
And I fill in select2 "Three" for "select_number"

@javascript
Scenario:
Given I am on "/select2-multiple.html"
Then I fill in select2 "Two" for "select_number2"
And I fill in select2 "Three" for "select_number2"
26 changes: 26 additions & 0 deletions tests/fixtures/select2-multiple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<head>
<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
</head>
<body>
<select id="select_number" name="select_number" multiple="multiple">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>

<select id="select_number2" name="select_number2" multiple="multiple">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>

<script type="text/javascript">$('#select_number, #select_number2').select2();</script>
</body>
</html>

0 comments on commit b564ce4

Please sign in to comment.