diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..7459134 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: composer + directory: '/' + schedule: + interval: daily + - package-ecosystem: github-actions + directory: '/' + schedule: + interval: daily diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..82a5df9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,57 @@ +name: Build +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + build: + name: PHP ${{ matrix.php-versions }} ${{ matrix.composer-args }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest] + php-versions: ["8.1", "8.2", "8.3"] + composer-args: ["", "--prefer-lowest"] + runs-on: ${{ matrix.operating-system }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup PHP + uses: shivammathur/setup-php@2.30.2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring + coverage: pcov + tools: cs2pr + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: php${{ matrix.php-versions }}-composer-${{ matrix.composer-args }}-${{ hashFiles('**/composer.json') }} + restore-keys: php${{ matrix.php-versions }}-composer-${{ matrix.composer-args }}- + - name: Install Dependencies + run: | + composer update --no-progress --no-suggest --prefer-stable --optimize-autoloader ${{ matrix.composer-args }} + - name: PHPStan + run: composer phpstan + - name: Code Style Check + env: + PHP_CS_FIXER_IGNORE_ENV: true + run: composer style-check -- --format=checkstyle | cs2pr + - name: Test + run: composer test-with-coverage + - name: Upload Coverage + uses: codecov/codecov-action@v4 + with: + files: ./clover.xml + fail_ci_if_error: true + verbose: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 20e3fdd..de8fd05 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ nb-configuration.xml /build/ .idea/ composer.lock -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +.php-cs-fixer.cache +.phpunit.cache \ No newline at end of file diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..ad3993a --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,22 @@ +exclude('vendor') + ->files() + ->in(__DIR__) +; + +$config = new PhpCsFixer\Config(); +return $config->setRiskyAllowed(true) + ->setRules([ + '@PSR2' => true, + '@PHPUnit60Migration:risky' => true, + 'binary_operator_spaces' => ['operators' => ['=' => 'align', '=>' => 'align']], + 'single_quote' => true, + 'array_syntax' => ['syntax' => 'short'], + 'concat_space' => ['spacing' => 'one'], + 'no_unused_imports' => true, + ]) + ->setUsingCache(true) + ->setFinder($finder); +; diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bb21011..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: php - -sudo: false - - -matrix: - include: - - php: '7.2' - - php: '7.3' - - php: '7.4' - - php: '8.0' - env: - - COMPOSER_ARGS=--ignore-platform-reqs - -cache: - directories: - - "$HOME/.composer/cache" - -before_install: -- travis_retry composer update --prefer-dist --no-interaction --prefer-stable $COMPOSER_ARGS - -script: -- composer test:ci - diff --git a/Module.php b/Module.php index ec3eef0..0793bec 100644 --- a/Module.php +++ b/Module.php @@ -1,3 +1,3 @@ -=5.3.3 -[laminas/laminas-config](https://github.com/laminas/laminas-config) | 2.3.9 -[laminas/laminas-escaper](https://github.com/laminas/laminas-escaper) | 2.3.9 -[laminas/laminas-form](https://github.com/laminas/laminas-form) | 2.3.9 -[laminas/laminas-i18n](https://github.com/laminas/laminas-i18n) | 2.3.9 -[laminas/laminas-loader](https://github.com/laminas/laminas-loader) | 2.3.9 -[laminas/laminas-log](https://github.com/laminas/laminas-log) | 2.3.9 -[laminas/laminas-modulemanager](https://github.com/laminas/laminas-modulemanager) | 2.3.9 -[laminas/laminas-mvc](https://github.com/laminas/laminas-mvc) | 2.3.9 -[laminas/laminas-serializer](https://github.com/laminas/laminas-serializer) | 2.3.9 -[laminas/laminas-servicemanager](https://github.com/laminas/laminas-servicemanager) | 2.3.9 -[laminas/laminas-stdlib](https://github.com/laminas/laminas-stdlib) | 2.3.9 -[laminas/laminas-view](https://github.com/laminas/laminas-view) | 2.3.9 +👍 If you wish to contribute to TwbsHelper, PRs are welcome! Please read the [https://github.com/diablomedia/laminas-twb-bundle/blob/master/CONTRIBUTING.md](CONTRIBUTING.md) file. # Documentation +(These links go to the wiki of an upstream repo and may be out of date) + 1. [Installation](https://github.com/thomasvargiu/laminas-twb-bundle/wiki/1.-Installation) 2. [View Helpers](https://github.com/thomasvargiu/laminas-twb-bundle/wiki/2.-View-Helpers) 3. [Elements](https://github.com/thomasvargiu/laminas-twb-bundle/wiki/3.-Elements) diff --git a/composer.json b/composer.json index 72dd6c2..a98c4df 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "totally-tech/laminas-twb-bundle", + "name": "diablomedia/laminas-twb-bundle", "type": "library", "description": "Laminas module for easy integration of Twitter Bootstrap", "keywords": [ @@ -7,7 +7,7 @@ "Twitter Bootstrap", "module" ], - "homepage": "http://github.com/totally-tech/laminas-twb-bundle", + "homepage": "http://github.com/diablomedia/laminas-twb-bundle", "license": "MIT", "minimum-stability": "stable", "authors": [ @@ -23,15 +23,15 @@ } ], "support": { - "issues": "https://github.com/totally-tech/laminas-twb-bundle/issues" + "issues": "https://github.com/diablomedia/laminas-twb-bundle/issues" }, "suggest": { "neilime/zf2-assets-bundle": "Bundling & caching Twitter Bootstrap assets", "twitter/bootstrap": "Twitter bootstrap assets" }, "require": { - "php": "^7.2 || ^8.0", - "laminas/laminas-form": "^2.3 || ^3.0", + "php": "~8.1 || ~8.2 || ~8.3", + "laminas/laminas-form": "^3.0", "laminas/laminas-i18n": "^2.3", "laminas/laminas-modulemanager": "^2.3", "laminas/laminas-mvc": "^2.3 || ^3.0", @@ -39,11 +39,15 @@ "laminas/laminas-stdlib": "^2.3 || ^3.1", "laminas/laminas-view": "^2.3", "laminas/laminas-navigation": "^2.9", - "laminas/laminas-dependency-plugin": "^1.0 || ^2.0" + "psr/container": "^1.0 || ^2.0" }, "require-dev": { - "phpunit/phpunit": "^8.5.13 || ^9.4", - "laminas/laminas-router": "^3.3" + "friendsofphp/php-cs-fixer": "3.54.0", + "laminas/laminas-router": "^3.3", + "maglnet/composer-require-checker": "^3.0.0", + "phpro/grumphp-shim": "^2.0.0", + "phpstan/phpstan": "1.10.67", + "phpunit/phpunit": "^10.5.18" }, "autoload": { "psr-4": { @@ -51,12 +55,14 @@ } }, "scripts": { - "test": "cd tests && phpunit --colors & cd ..", - "test:ci": "cd tests && phpunit && cd .." + "test": "phpunit", + "test-with-coverage": "phpunit --coverage-clover=clover.xml", + "phpstan": "phpstan analyze -c phpstan.neon --no-progress --ansi", + "style-check": "php-cs-fixer fix --dry-run -vv" }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-php81": "4.1.x-dev" }, "laminas": { "module": "TwbBundle", @@ -65,5 +71,10 @@ }, "replace": { "neilime/zf2-twb-bundle": "^3.0" + }, + "config": { + "allow-plugins": { + "phpro/grumphp-shim": true + } } } diff --git a/config/module.config.php b/config/module.config.php index 943f846..bb09856 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,140 +1,128 @@ - [ - 'ignoredViewHelpers' => [ - 'file', - 'checkbox', - 'radio', - 'submit', - 'multi_checkbox', - 'static', - 'button', - 'reset' - ], - 'type_map' => [], - 'class_map' => [], - ], - 'service_manager' => [ - 'factories' => [ - Options\ModuleOptions::class => Options\Factory\ModuleOptionsFactory::class, - ], - ], - 'view_helpers' => [ - 'aliases' => [ - 'form' => Form\View\Helper\TwbBundleForm::class, - 'Form' => Form\View\Helper\TwbBundleForm::class, - 'form_submit' => Form\View\Helper\TwbBundleFormButton::class, - 'formsubmit' => Form\View\Helper\TwbBundleFormButton::class, - 'formSubmit' => Form\View\Helper\TwbBundleFormButton::class, - 'FormSubmit' => Form\View\Helper\TwbBundleFormButton::class, - 'formbutton' => Form\View\Helper\TwbBundleFormButton::class, - 'form_button' => Form\View\Helper\TwbBundleFormButton::class, - 'formButton' => Form\View\Helper\TwbBundleFormButton::class, - 'FormButton' => Form\View\Helper\TwbBundleFormButton::class, - 'formcheckbox' => Form\View\Helper\TwbBundleFormCheckbox::class, - 'form_checkbox' => Form\View\Helper\TwbBundleFormCheckbox::class, - 'formCheckbox' => Form\View\Helper\TwbBundleFormCheckbox::class, - 'FormCheckbox' => Form\View\Helper\TwbBundleFormCheckbox::class, - 'form_radio' => Form\View\Helper\TwbBundleFormRadio::class, - 'formradio' => Form\View\Helper\TwbBundleFormRadio::class, - 'formRadio' => Form\View\Helper\TwbBundleFormRadio::class, - 'FormRadio' => Form\View\Helper\TwbBundleFormRadio::class, - 'formcollection' => Form\View\Helper\TwbBundleFormCollection::class, - 'form_collection' => Form\View\Helper\TwbBundleFormCollection::class, - 'formCollection' => Form\View\Helper\TwbBundleFormCollection::class, - 'FormCollection' => Form\View\Helper\TwbBundleFormCollection::class, - 'form_element' => Form\View\Helper\TwbBundleFormElement::class, - 'formelement' => Form\View\Helper\TwbBundleFormElement::class, - 'formElement' => Form\View\Helper\TwbBundleFormElement::class, - 'FormElement' => Form\View\Helper\TwbBundleFormElement::class, - 'form_element_errors' => Form\View\Helper\TwbBundleFormElementErrors::class, - 'formelementerrors' => Form\View\Helper\TwbBundleFormElementErrors::class, - 'formElementErrors' => Form\View\Helper\TwbBundleFormElementErrors::class, - 'FormElementErrors' => Form\View\Helper\TwbBundleFormElementErrors::class, - 'formrow' => Form\View\Helper\TwbBundleFormRow::class, - 'form_row' => Form\View\Helper\TwbBundleFormRow::class, - 'formRow' => Form\View\Helper\TwbBundleFormRow::class, - 'FormRow' => Form\View\Helper\TwbBundleFormRow::class, - 'form_multi_checkbox' => Form\View\Helper\TwbBundleFormMultiCheckbox::class, - 'form_multicheckbox' => Form\View\Helper\TwbBundleFormMultiCheckbox::class, - 'formmulticheckbox' => Form\View\Helper\TwbBundleFormMultiCheckbox::class, - 'formMultiCheckbox' => Form\View\Helper\TwbBundleFormMultiCheckbox::class, - - 'label' => View\Helper\TwbBundleLabel::class, - - 'alert' => View\Helper\TwbBundleAlert::class, - 'form_alert' => View\Helper\TwbBundleAlert::class, - 'formalert' => View\Helper\TwbBundleAlert::class, - 'badge' => View\Helper\TwbBundleBadge::class, - 'form_badge' => View\Helper\TwbBundleBadge::class, - 'formbadge' => View\Helper\TwbBundleBadge::class, - 'button_group' => View\Helper\TwbBundleButtonGroup::class, - 'buttonGroup' => View\Helper\TwbBundleButtonGroup::class, - 'form_buttonGroup' => View\Helper\TwbBundleButtonGroup::class, - 'formbuttonGroup' => View\Helper\TwbBundleButtonGroup::class, - 'dropdown' => View\Helper\TwbBundleDropDown::class, - 'dropDown' => View\Helper\TwbBundleDropDown::class, - 'form_dropdown' => View\Helper\TwbBundleDropDown::class, - 'formdropDown' => View\Helper\TwbBundleDropDown::class, - - 'form_static' => Form\View\Helper\TwbBundleFormStatic::class, - 'formstatic' => Form\View\Helper\TwbBundleFormStatic::class, - 'formStatic' => Form\View\Helper\TwbBundleFormStatic::class, - 'form_errors' => Form\View\Helper\TwbBundleFormErrors::class, - 'formerrors' => Form\View\Helper\TwbBundleFormErrors::class, - 'formErrors' => Form\View\Helper\TwbBundleFormErrors::class, - 'glyphicon' => View\Helper\TwbBundleGlyphicon::class, - 'form_glyphicon' => View\Helper\TwbBundleGlyphicon::class, - 'formglyphicon' => View\Helper\TwbBundleGlyphicon::class, - 'formGlyphicon' => View\Helper\TwbBundleGlyphicon::class, - 'fontAwesome' => View\Helper\TwbBundleFontAwesome::class, - 'form_fontAwesome' => View\Helper\TwbBundleFontAwesome::class, - 'formfontAwesome' => View\Helper\TwbBundleFontAwesome::class, - 'formFontAwesome' => View\Helper\TwbBundleFontAwesome::class, - - 'navigation' => View\Helper\Navigation::class, - 'Navigation' => View\Helper\Navigation::class, - 'laminasviewhelpernavigation' => View\Helper\Navigation::class, - - // Legacy Zend Framework aliases - \Zend\Form\View\Helper\Form::class => Form\View\Helper\TwbBundleForm::class, - \Zend\Form\View\Helper\FormButton::class => Form\View\Helper\TwbBundleFormButton::class, - \Zend\Form\View\Helper\FormCheckbox::class => Form\View\Helper\TwbBundleFormCheckbox::class, - \Zend\Form\View\Helper\FormCollection::class => Form\View\Helper\TwbBundleFormCollection::class, - \Zend\Form\View\Helper\FormElement::class => Form\View\Helper\TwbBundleFormElement::class, - \Zend\Form\View\Helper\FormElementErrors::class => Form\View\Helper\TwbBundleFormElementErrors::class, - \Zend\Form\View\Helper\FormLabel::class => View\Helper\TwbBundleLabel::class, - \Zend\Form\View\Helper\FormMultiCheckbox::class => Form\View\Helper\TwbBundleFormMultiCheckbox::class, - \Zend\Form\View\Helper\FormRadio::class => Form\View\Helper\TwbBundleFormRadio::class, - \Zend\Form\View\Helper\FormRow::class => Form\View\Helper\TwbBundleFormRow::class, - ], - 'factories' => [ - Form\Element\StaticElement::class => InvokableFactory::class, - Form\View\Helper\TwbBundleForm::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormButton::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormCheckbox::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormCollection::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormElementErrors::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormErrors::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormMultiCheckbox::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormRadio::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormRow::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormStatic::class => InvokableFactory::class, - Form\View\Helper\TwbBundleFormElement::class => Form\View\Helper\Factory\TwbBundleFormElementFactory::class, - - View\Helper\Navigation::class => Navigation\View\NavigationHelperFactory::class, - View\Helper\TwbBundleAlert::class => InvokableFactory::class, - View\Helper\TwbBundleBadge::class => InvokableFactory::class, - View\Helper\TwbBundleButtonGroup::class => InvokableFactory::class, - View\Helper\TwbBundleDropDown::class => InvokableFactory::class, - View\Helper\TwbBundleFontAwesome::class => InvokableFactory::class, - View\Helper\TwbBundleGlyphicon::class => InvokableFactory::class, - View\Helper\TwbBundleLabel::class => InvokableFactory::class, - ], - ], -]; + [ + 'ignoredViewHelpers' => [ + 'file', + 'checkbox', + 'radio', + 'submit', + 'multi_checkbox', + 'static', + 'button', + 'reset' + ], + 'type_map' => [], + 'class_map' => [], + ], + 'service_manager' => [ + 'factories' => [ + Options\ModuleOptions::class => Options\Factory\ModuleOptionsFactory::class, + ], + ], + 'view_helpers' => [ + 'aliases' => [ + 'form' => Form\View\Helper\TwbBundleForm::class, + 'Form' => Form\View\Helper\TwbBundleForm::class, + 'form_submit' => Form\View\Helper\TwbBundleFormButton::class, + 'formsubmit' => Form\View\Helper\TwbBundleFormButton::class, + 'formSubmit' => Form\View\Helper\TwbBundleFormButton::class, + 'FormSubmit' => Form\View\Helper\TwbBundleFormButton::class, + 'formbutton' => Form\View\Helper\TwbBundleFormButton::class, + 'form_button' => Form\View\Helper\TwbBundleFormButton::class, + 'formButton' => Form\View\Helper\TwbBundleFormButton::class, + 'FormButton' => Form\View\Helper\TwbBundleFormButton::class, + 'formcheckbox' => Form\View\Helper\TwbBundleFormCheckbox::class, + 'form_checkbox' => Form\View\Helper\TwbBundleFormCheckbox::class, + 'formCheckbox' => Form\View\Helper\TwbBundleFormCheckbox::class, + 'FormCheckbox' => Form\View\Helper\TwbBundleFormCheckbox::class, + 'form_radio' => Form\View\Helper\TwbBundleFormRadio::class, + 'formradio' => Form\View\Helper\TwbBundleFormRadio::class, + 'formRadio' => Form\View\Helper\TwbBundleFormRadio::class, + 'FormRadio' => Form\View\Helper\TwbBundleFormRadio::class, + 'formcollection' => Form\View\Helper\TwbBundleFormCollection::class, + 'form_collection' => Form\View\Helper\TwbBundleFormCollection::class, + 'formCollection' => Form\View\Helper\TwbBundleFormCollection::class, + 'FormCollection' => Form\View\Helper\TwbBundleFormCollection::class, + 'form_element' => Form\View\Helper\TwbBundleFormElement::class, + 'formelement' => Form\View\Helper\TwbBundleFormElement::class, + 'formElement' => Form\View\Helper\TwbBundleFormElement::class, + 'FormElement' => Form\View\Helper\TwbBundleFormElement::class, + 'form_element_errors' => Form\View\Helper\TwbBundleFormElementErrors::class, + 'formelementerrors' => Form\View\Helper\TwbBundleFormElementErrors::class, + 'formElementErrors' => Form\View\Helper\TwbBundleFormElementErrors::class, + 'FormElementErrors' => Form\View\Helper\TwbBundleFormElementErrors::class, + 'formrow' => Form\View\Helper\TwbBundleFormRow::class, + 'form_row' => Form\View\Helper\TwbBundleFormRow::class, + 'formRow' => Form\View\Helper\TwbBundleFormRow::class, + 'FormRow' => Form\View\Helper\TwbBundleFormRow::class, + 'form_multi_checkbox' => Form\View\Helper\TwbBundleFormMultiCheckbox::class, + 'form_multicheckbox' => Form\View\Helper\TwbBundleFormMultiCheckbox::class, + 'formmulticheckbox' => Form\View\Helper\TwbBundleFormMultiCheckbox::class, + 'formMultiCheckbox' => Form\View\Helper\TwbBundleFormMultiCheckbox::class, + + 'label' => View\Helper\TwbBundleLabel::class, + + 'alert' => View\Helper\TwbBundleAlert::class, + 'form_alert' => View\Helper\TwbBundleAlert::class, + 'formalert' => View\Helper\TwbBundleAlert::class, + 'badge' => View\Helper\TwbBundleBadge::class, + 'form_badge' => View\Helper\TwbBundleBadge::class, + 'formbadge' => View\Helper\TwbBundleBadge::class, + 'button_group' => View\Helper\TwbBundleButtonGroup::class, + 'buttonGroup' => View\Helper\TwbBundleButtonGroup::class, + 'form_buttonGroup' => View\Helper\TwbBundleButtonGroup::class, + 'formbuttonGroup' => View\Helper\TwbBundleButtonGroup::class, + 'dropdown' => View\Helper\TwbBundleDropDown::class, + 'dropDown' => View\Helper\TwbBundleDropDown::class, + 'form_dropdown' => View\Helper\TwbBundleDropDown::class, + 'formdropDown' => View\Helper\TwbBundleDropDown::class, + + 'form_static' => Form\View\Helper\TwbBundleFormStatic::class, + 'formstatic' => Form\View\Helper\TwbBundleFormStatic::class, + 'formStatic' => Form\View\Helper\TwbBundleFormStatic::class, + 'form_errors' => Form\View\Helper\TwbBundleFormErrors::class, + 'formerrors' => Form\View\Helper\TwbBundleFormErrors::class, + 'formErrors' => Form\View\Helper\TwbBundleFormErrors::class, + 'glyphicon' => View\Helper\TwbBundleGlyphicon::class, + 'form_glyphicon' => View\Helper\TwbBundleGlyphicon::class, + 'formglyphicon' => View\Helper\TwbBundleGlyphicon::class, + 'formGlyphicon' => View\Helper\TwbBundleGlyphicon::class, + 'fontAwesome' => View\Helper\TwbBundleFontAwesome::class, + 'form_fontAwesome' => View\Helper\TwbBundleFontAwesome::class, + 'formfontAwesome' => View\Helper\TwbBundleFontAwesome::class, + 'formFontAwesome' => View\Helper\TwbBundleFontAwesome::class, + + 'navigation' => View\Helper\Navigation::class, + 'Navigation' => View\Helper\Navigation::class, + 'laminasviewhelpernavigation' => View\Helper\Navigation::class, + ], + 'factories' => [ + Form\Element\StaticElement::class => InvokableFactory::class, + Form\View\Helper\TwbBundleForm::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormButton::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormCheckbox::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormCollection::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormElementErrors::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormErrors::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormMultiCheckbox::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormRadio::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormRow::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormStatic::class => InvokableFactory::class, + Form\View\Helper\TwbBundleFormElement::class => Form\View\Helper\Factory\TwbBundleFormElementFactory::class, + + View\Helper\Navigation::class => Navigation\View\NavigationHelperFactory::class, + View\Helper\TwbBundleAlert::class => InvokableFactory::class, + View\Helper\TwbBundleBadge::class => InvokableFactory::class, + View\Helper\TwbBundleButtonGroup::class => InvokableFactory::class, + View\Helper\TwbBundleDropDown::class => InvokableFactory::class, + View\Helper\TwbBundleFontAwesome::class => InvokableFactory::class, + View\Helper\TwbBundleGlyphicon::class => InvokableFactory::class, + View\Helper\TwbBundleLabel::class => InvokableFactory::class, + ], + ], +]; diff --git a/grumphp.yml b/grumphp.yml new file mode 100644 index 0000000..b0b9bbb --- /dev/null +++ b/grumphp.yml @@ -0,0 +1,17 @@ +# grumphp.yml +grumphp: + tasks: + composer: + strict: true + composer_require_checker: ~ + #config_file: require-checker-config.json + phpcsfixer2: + allow_risky: true + config: .php-cs-fixer.php + phpstan: + configuration: phpstan.neon + memory_limit: 768M + phpunit: + metadata: + priority: 100 + always_execute: true diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..4223f73 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 1 + paths: + - ./ + excludePaths: + - ./vendor/* + - ./tests/* diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..c155302 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,22 @@ + + + + + ./tests + + + + + + ./src + + + diff --git a/src/TwbBundle/ConfigProvider.php b/src/TwbBundle/ConfigProvider.php index e122da2..f282e02 100644 --- a/src/TwbBundle/ConfigProvider.php +++ b/src/TwbBundle/ConfigProvider.php @@ -40,7 +40,7 @@ public function __invoke() $this->moduleConfig = require self::MODULE_CONFIG_PATH; return [ - 'twbbundle' => $this->getTwbBundleOptions(), + 'twbbundle' => $this->getTwbBundleOptions(), 'dependencies' => $this->getDependencies(), 'view_helpers' => $this->getViewHelpers() ]; diff --git a/src/TwbBundle/Form/Element/StaticElement.php b/src/TwbBundle/Form/Element/StaticElement.php index 1259722..4ac92e6 100644 --- a/src/TwbBundle/Form/Element/StaticElement.php +++ b/src/TwbBundle/Form/Element/StaticElement.php @@ -1,11 +1,13 @@ - 'static' - ); -} \ No newline at end of file + 'static' + ]; +} diff --git a/src/TwbBundle/Form/View/Helper/Factory/TwbBundleFormElementFactory.php b/src/TwbBundle/Form/View/Helper/Factory/TwbBundleFormElementFactory.php index 2333820..f92c9df 100644 --- a/src/TwbBundle/Form/View/Helper/Factory/TwbBundleFormElementFactory.php +++ b/src/TwbBundle/Form/View/Helper/Factory/TwbBundleFormElementFactory.php @@ -1,11 +1,9 @@ getServiceLocator() ?: $serviceLocator; - } - - $options = $serviceLocator->get('TwbBundle\Options\ModuleOptions'); - return new TwbBundleFormElement($options); - } - public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $options = $container->get('TwbBundle\Options\ModuleOptions'); diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleForm.php b/src/TwbBundle/Form/View/Helper/TwbBundleForm.php index 9023312..93b022c 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleForm.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleForm.php @@ -1,187 +1,187 @@ -%s'; - - /** - * Form layout (see LAYOUT_* consts) - * - * @var string - */ - protected $formLayout = null; - - /** - * @see Form::__invoke() - * @param FormInterface $oForm - * @param string $sFormLayout - * @return TwbBundleForm|string - */ - public function __invoke(FormInterface $oForm = null, $sFormLayout = self::LAYOUT_HORIZONTAL) - { - if ($oForm) { - return $this->render($oForm, $sFormLayout); - } - $this->formLayout = $sFormLayout; - return $this; - } - - /** - * Render a form from the provided $oForm, - * @see Form::render() - * @param FormInterface $oForm - * @param string $sFormLayout - * @return string - */ - public function render(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL): string - { - //Prepare form if needed - if (method_exists($oForm, 'prepare')) { - $oForm->prepare(); - } - - $this->setFormClass($oForm, $sFormLayout); - - //Set form role - if (!$oForm->getAttribute('role')) { - $oForm->setAttribute('role', 'form'); - } - - return $this->openTag($oForm) . "\n" . $this->renderElements($oForm, $sFormLayout) . $this->closeTag(); - } - - /** - * @param FormInterface $oForm - * @param string|null $sFormLayout - * @return string - */ - protected function renderElements(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL) - { - // Store button groups - $aButtonGroups = array(); - - // Store button groups column-size from buttons - $aButtonGroupsColumnSize = array(); - - // Store elements rendering - $aElementsRendering = array(); - - // Retrieve view helper plugin manager - $oHelperPluginManager = $this->getView()->getHelperPluginManager(); - - // Retrieve form row helper - $oFormRowHelper = $oHelperPluginManager->get('formRow'); - - // Retrieve form collection helper - $oFormCollectionHelper = $oHelperPluginManager->get('formCollection'); - - // Retrieve button group helper - $oButtonGroupHelper = $oHelperPluginManager->get('buttonGroup'); - - // Store column size option - $bHasColumnSize = false; - - // Prepare options - foreach ($oForm as $iKey => $oElement) { - $aOptions = $oElement->getOptions(); - if (!$bHasColumnSize && !empty($aOptions['column-size'])) { - $bHasColumnSize = true; - } - // Define layout option to form elements if not already defined - if ($sFormLayout && empty($aOptions['twb-layout'])) { - $oElement->setOption('twb-layout', $sFormLayout); - } - - // Manage button group option - if (array_key_exists('button-group', $aOptions)) { - $sButtonGroupKey = $aOptions['button-group']; - if (isset($aButtonGroups[$sButtonGroupKey])) { - $aButtonGroups[$sButtonGroupKey][] = $oElement; - } else { - $aButtonGroups[$sButtonGroupKey] = array($oElement); - $aElementsRendering[$iKey] = $sButtonGroupKey; - } - if (!empty($aOptions['column-size']) && !isset($aButtonGroupsColumnSize[$sButtonGroupKey])) { - // Only the first occured column-size will be set, other are ignored. - $aButtonGroupsColumnSize[$sButtonGroupKey] = $aOptions['column-size']; - } - } elseif ($oElement instanceof FieldsetInterface) { - $aElementsRendering[$iKey] = $oFormCollectionHelper->__invoke($oElement); - } else { - $aElementsRendering[$iKey] = $oFormRowHelper->__invoke($oElement); - } - } - - // Assemble elements rendering - $sFormContent = ''; - foreach ($aElementsRendering as $sElementRendering) { - // Check if element rendering is a button group key - if (isset($aButtonGroups[$sElementRendering])) { - $aButtons = $aButtonGroups[$sElementRendering]; - - // Render button group content - $options = (isset($aButtonGroupsColumnSize[$sElementRendering])) ? array('attributes' => array('class' => 'col-' . $aButtonGroupsColumnSize[$sElementRendering])) : null; - $sFormContent .= $oFormRowHelper->renderElementFormGroup($oButtonGroupHelper($aButtons, $options), $oFormRowHelper->getRowClassFromElement(current($aButtons))); - } else { - $sFormContent .= $sElementRendering; - } - } - - if ($bHasColumnSize && $sFormLayout !== self::LAYOUT_HORIZONTAL) { - $sFormContent = sprintf(static::$formRowFormat, $sFormContent); - } - return $sFormContent; - } - - /** - * Sets form layout class - * @param FormInterface $oForm - * @param string $sFormLayout - * @return \TwbBundle\Form\View\Helper\TwbBundleForm - */ - protected function setFormClass(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL) - { - if (is_string($sFormLayout)) { - $sLayoutClass = 'form-' . $sFormLayout; - if ($sFormClass = $oForm->getAttribute('class')) { - if (!preg_match('/(\s|^)' . preg_quote($sLayoutClass, '/') . '(\s|$)/', $sFormClass)) { - $oForm->setAttribute('class', trim($sFormClass . ' ' . $sLayoutClass)); - } - } else { - $oForm->setAttribute('class', $sLayoutClass); - } - } - return $this; - } - - /** - * Generate an opening form tag - * @param null|FormInterface $form - * @return string - */ - public function openTag(FormInterface $form = null): string - { - $this->setFormClass($form, $this->formLayout); - return parent::openTag($form); - } -} +%s'; + + /** + * Form layout (see LAYOUT_* consts) + * + * @var string + */ + protected $formLayout = null; + + /** + * @see Form::__invoke() + * @param FormInterface $oForm + * @param string $sFormLayout + * @return TwbBundleForm|string + */ + public function __invoke(FormInterface $oForm = null, $sFormLayout = self::LAYOUT_HORIZONTAL) + { + if ($oForm) { + return $this->render($oForm, $sFormLayout); + } + $this->formLayout = $sFormLayout; + return $this; + } + + /** + * Render a form from the provided $oForm, + * @see Form::render() + * @param FormInterface $oForm + * @param string $sFormLayout + * @return string + */ + public function render(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL): string + { + //Prepare form if needed + if (method_exists($oForm, 'prepare')) { + $oForm->prepare(); + } + + $this->setFormClass($oForm, $sFormLayout); + + //Set form role + if (!$oForm->getAttribute('role')) { + $oForm->setAttribute('role', 'form'); + } + + return $this->openTag($oForm) . "\n" . $this->renderElements($oForm, $sFormLayout) . $this->closeTag(); + } + + /** + * @param FormInterface $oForm + * @param string|null $sFormLayout + * @return string + */ + protected function renderElements(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL) + { + // Store button groups + $aButtonGroups = []; + + // Store button groups column-size from buttons + $aButtonGroupsColumnSize = []; + + // Store elements rendering + $aElementsRendering = []; + + // Retrieve view helper plugin manager + $oHelperPluginManager = $this->getView()->getHelperPluginManager(); + + // Retrieve form row helper + $oFormRowHelper = $oHelperPluginManager->get('formRow'); + + // Retrieve form collection helper + $oFormCollectionHelper = $oHelperPluginManager->get('formCollection'); + + // Retrieve button group helper + $oButtonGroupHelper = $oHelperPluginManager->get('buttonGroup'); + + // Store column size option + $bHasColumnSize = false; + + // Prepare options + foreach ($oForm as $iKey => $oElement) { + $aOptions = $oElement->getOptions(); + if (!$bHasColumnSize && !empty($aOptions['column-size'])) { + $bHasColumnSize = true; + } + // Define layout option to form elements if not already defined + if ($sFormLayout && empty($aOptions['twb-layout'])) { + $oElement->setOption('twb-layout', $sFormLayout); + } + + // Manage button group option + if (array_key_exists('button-group', $aOptions)) { + $sButtonGroupKey = $aOptions['button-group']; + if (isset($aButtonGroups[$sButtonGroupKey])) { + $aButtonGroups[$sButtonGroupKey][] = $oElement; + } else { + $aButtonGroups[$sButtonGroupKey] = [$oElement]; + $aElementsRendering[$iKey] = $sButtonGroupKey; + } + if (!empty($aOptions['column-size']) && !isset($aButtonGroupsColumnSize[$sButtonGroupKey])) { + // Only the first occured column-size will be set, other are ignored. + $aButtonGroupsColumnSize[$sButtonGroupKey] = $aOptions['column-size']; + } + } elseif ($oElement instanceof FieldsetInterface) { + $aElementsRendering[$iKey] = $oFormCollectionHelper->__invoke($oElement); + } else { + $aElementsRendering[$iKey] = $oFormRowHelper->__invoke($oElement); + } + } + + // Assemble elements rendering + $sFormContent = ''; + foreach ($aElementsRendering as $sElementRendering) { + // Check if element rendering is a button group key + if (isset($aButtonGroups[$sElementRendering])) { + $aButtons = $aButtonGroups[$sElementRendering]; + + // Render button group content + $options = (isset($aButtonGroupsColumnSize[$sElementRendering])) ? ['attributes' => ['class' => 'col-' . $aButtonGroupsColumnSize[$sElementRendering]]] : null; + $sFormContent .= $oFormRowHelper->renderElementFormGroup($oButtonGroupHelper($aButtons, $options), $oFormRowHelper->getRowClassFromElement(current($aButtons))); + } else { + $sFormContent .= $sElementRendering; + } + } + + if ($bHasColumnSize && $sFormLayout !== self::LAYOUT_HORIZONTAL) { + $sFormContent = sprintf(static::$formRowFormat, $sFormContent); + } + return $sFormContent; + } + + /** + * Sets form layout class + * @param FormInterface $oForm + * @param string $sFormLayout + * @return \TwbBundle\Form\View\Helper\TwbBundleForm + */ + protected function setFormClass(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL) + { + if (is_string($sFormLayout)) { + $sLayoutClass = 'form-' . $sFormLayout; + if ($sFormClass = $oForm->getAttribute('class')) { + if (!preg_match('/(\s|^)' . preg_quote($sLayoutClass, '/') . '(\s|$)/', $sFormClass)) { + $oForm->setAttribute('class', trim($sFormClass . ' ' . $sLayoutClass)); + } + } else { + $oForm->setAttribute('class', $sLayoutClass); + } + } + return $this; + } + + /** + * Generate an opening form tag + * @param null|FormInterface $form + * @return string + */ + public function openTag(FormInterface $form = null): string + { + $this->setFormClass($form, $this->formLayout); + return parent::openTag($form); + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php index a48bd41..477ce4d 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormButton.php @@ -1,239 +1,247 @@ -%s'; - - /** - * @var string - */ - protected static $dropdownToggleFormat = '%s '; - - /** - * @var string - */ - protected static $dropdownCaretFormat = ''; - - /** - * Allowed button options - * @var array - */ - protected static $buttonOptions = array('default', 'primary', 'success', 'info', 'warning', 'danger', 'link'); - - /** - * @see FormButton::render() - * @param ElementInterface $oElement - * @param string $sButtonContent - * @throws LogicException - * @throws Exception - * @return string - */ - public function render(ElementInterface $oElement, ?string $sButtonContent = null): string - { - if ($sClass = $oElement->getAttribute('class')) { - if (!preg_match('/(\s|^)btn(\s|$)/', $sClass)) { - $sClass .= ' btn'; - } - - if (!preg_match('/(\s|^)btn-.*(\s|$)/', $sClass)) { - $sClass .= ' btn-default'; - } else { - $bHasOption = false; - foreach (static::$buttonOptions as $sButtonOption) { - if (preg_match('/(\s|^)btn-' . $sButtonOption . '.*(\s|$)/', $sClass)) { - $bHasOption = true; - break; - } - } - if (!$bHasOption) { - $sClass .= ' btn-default'; - } - } - $oElement->setAttribute('class', trim($sClass)); - } else { - $oElement->setAttribute('class', 'btn btn-default'); - } - - // Retrieve icon options - if (null !== ($aIconOptions = $oElement->getOption('glyphicon'))) { - $sIconHelperMethod = 'glyphicon'; - } elseif (null !== ($aIconOptions = $oElement->getOption('fontAwesome'))) { - $sIconHelperMethod = 'fontAwesome'; - } - - /* - * Define button content - */ - if (null === $sButtonContent) { - $sButtonContent = $oElement->getLabel(); - - if (!$sButtonContent) { - $sButtonContent = $oElement->getValue(); - } - - if (null === $sButtonContent && !$aIconOptions) { - throw new DomainException(sprintf( - '%s expects either button content as the second argument, ' . - 'or that the element provided has a label value, a glyphicon option, or a fontAwesome option; none found', - __METHOD__ - )); - } - - if (null !== ($oTranslator = $this->getTranslator())) { - $sButtonContent = $oTranslator->translate( - $sButtonContent, - $this->getTranslatorTextDomain() - ); - } - } - - if (!$oElement instanceof LabelAwareInterface || !$oElement->getLabelOption('disable_html_escape')) { - $oEscapeHtmlHelper = $this->getEscapeHtmlHelper(); - $sButtonContent = $oEscapeHtmlHelper($sButtonContent); - } - - /* - * Manage icon - */ - if ($aIconOptions) { - if (is_scalar($aIconOptions)) { - $aIconOptions = array ( - 'icon' => $aIconOptions, - 'position' => self::ICON_PREPEND - ); - } - - if (!is_array($aIconOptions)) { - throw new LogicException(sprintf( - '"glyphicon" and "fontAwesome" button option expects a scalar value or an array, "%s" given', - is_object($aIconOptions) ? get_class($aIconOptions) : gettype($aIconOptions) - )); - } - - $position = 'prepend'; - - if (!empty($aIconOptions['position'])) { - $position = $aIconOptions['position']; - } - - if (!empty($aIconOptions['icon'])) { - $icon = $aIconOptions['icon']; - } - - if (!is_scalar($icon)) { - throw new LogicException(sprintf( - 'Glyphicon and fontAwesome "icon" option expects a scalar value, "%s" given', - is_object($icon) ? get_class($icon) : gettype($icon) - )); - } elseif (!is_string($position)) { - throw new LogicException(sprintf( - 'Glyphicon and fontAwesome "position" option expects a string, "%s" given', - is_object($position) ? get_class($position) : gettype($position) - )); - } elseif ($position !== self::ICON_PREPEND && $position !== self::ICON_APPEND) { - throw new LogicException(sprintf( - 'Glyphicon and fontAwesome "position" option allows "'.self::ICON_PREPEND.'" or "'.self::ICON_APPEND.'", "%s" given', - is_object($position) ? get_class($position) : gettype($position) - )); - } - - if ($sButtonContent) { - if ($position === self::ICON_PREPEND) { - $sButtonContent = $this->getView()->{$sIconHelperMethod}( - $icon, - isset($aIconOptions['attributes'])?$aIconOptions['attributes']:null - ).' '.$sButtonContent; - } else { - $sButtonContent .= ' ' . $this->getView()->{$sIconHelperMethod}( - $icon, - isset($aIconOptions['attributes'])?$aIconOptions['attributes']:null - ); - } - } else { - $sButtonContent = $this->getView()->{$sIconHelperMethod}( - $icon, - isset($aIconOptions['attributes']) ? $aIconOptions['attributes'] : null - ); - } - } - - /* - * Dropdown button - */ - if ($aDropdownOptions = $oElement->getOption('dropdown')) { - if (!is_array($aDropdownOptions)) { - throw new LogicException(sprintf( - '"dropdown" option expects an array, "%s" given', - is_object($aDropdownOptions) ? get_class($aDropdownOptions) : gettype($aDropdownOptions) - )); - } - - if (empty($aDropdownOptions['split'])) { - /* - * Class - */ - if (!preg_match('/(\s|^)dropdown-toggle(\s|$)/', $sClass = $oElement->getAttribute('class'))) { - $oElement->setAttribute('class', trim($sClass . ' dropdown-toggle')); - } - - /* - * data-toggle - */ - $oElement->setAttribute('data-toggle', 'dropdown'); - $sMarkup = $this->openTag($oElement) . - sprintf(static::$dropdownToggleFormat, $sButtonContent) . - $this->closeTag(); - } else { - /* - * Add caret element - */ - $sMarkup = $this->openTag($oElement) . - $sButtonContent . - $this->closeTag() . - sprintf(static::$dropdownCaretFormat, $oElement->getAttribute('class')); - } - - /* - * No container - */ - if ($oElement->getOption('disable-twb')) { - return $sMarkup . $this->getView()->dropdown()->renderListItems($aDropdownOptions); - } - - /* - * Render button + dropdown - */ - return sprintf( - static::$dropdownContainerFormat, - //Drop way - empty($aDropdownOptions['dropup']) ? '' : 'dropup', - $sMarkup . - $this->getView()->dropdown()->renderListItems($aDropdownOptions) - ); - } - - return $this->openTag($oElement) . $sButtonContent . $this->closeTag(); - } -} +%s'; + + /** + * @var string + */ + protected static $dropdownToggleFormat = '%s '; + + /** + * @var string + */ + protected static $dropdownCaretFormat = ''; + + /** + * Allowed button options + * @var array + */ + protected static $buttonOptions = ['default', 'primary', 'success', 'info', 'warning', 'danger', 'link']; + + /** + * @see FormButton::render() + * @param ElementInterface $oElement + * @param string $sButtonContent + * @throws LogicException + * @throws Exception + * @return string + */ + public function render(ElementInterface $oElement, ?string $sButtonContent = null): string + { + if ($sClass = $oElement->getAttribute('class')) { + if (!preg_match('/(\s|^)btn(\s|$)/', $sClass)) { + $sClass .= ' btn'; + } + + if (!preg_match('/(\s|^)btn-.*(\s|$)/', $sClass)) { + $sClass .= ' btn-default'; + } else { + $bHasOption = false; + foreach (static::$buttonOptions as $sButtonOption) { + if (preg_match('/(\s|^)btn-' . $sButtonOption . '.*(\s|$)/', $sClass)) { + $bHasOption = true; + break; + } + } + if (!$bHasOption) { + $sClass .= ' btn-default'; + } + } + $oElement->setAttribute('class', trim($sClass)); + } else { + $oElement->setAttribute('class', 'btn btn-default'); + } + + // Retrieve icon options + if (null !== ($aIconOptions = $oElement->getOption('glyphicon'))) { + $sIconHelperMethod = 'glyphicon'; + } elseif (null !== ($aIconOptions = $oElement->getOption('fontAwesome'))) { + $sIconHelperMethod = 'fontAwesome'; + } + + /* + * Define button content + */ + if (null === $sButtonContent) { + $sButtonContent = $oElement->getLabel(); + + if (!$sButtonContent) { + $sButtonContent = $oElement->getValue(); + } + + if (null === $sButtonContent && !$aIconOptions) { + throw new DomainException(sprintf( + '%s expects either button content as the second argument, ' . + 'or that the element provided has a label value, a glyphicon option, or a fontAwesome option; none found', + __METHOD__ + )); + } + + if (null !== ($oTranslator = $this->getTranslator())) { + $sButtonContent = $oTranslator->translate( + $sButtonContent, + $this->getTranslatorTextDomain() + ); + } + } + + if (!$oElement instanceof LabelAwareInterface || !$oElement->getLabelOption('disable_html_escape')) { + $oEscapeHtmlHelper = $this->getEscapeHtmlHelper(); + $sButtonContent = $oEscapeHtmlHelper($sButtonContent); + } + + /* + * Manage icon + */ + if ($aIconOptions) { + if (is_scalar($aIconOptions)) { + $aIconOptions = [ + 'icon' => $aIconOptions, + 'position' => self::ICON_PREPEND + ]; + } + + if (!is_array($aIconOptions)) { + throw new LogicException(sprintf( + '"glyphicon" and "fontAwesome" button option expects a scalar value or an array, "%s" given', + is_object($aIconOptions) ? get_class($aIconOptions) : gettype($aIconOptions) + )); + } + + $position = 'prepend'; + + if (!empty($aIconOptions['position'])) { + $position = $aIconOptions['position']; + } + + $icon = null; + + if (!empty($aIconOptions['icon'])) { + $icon = $aIconOptions['icon']; + } + + if (!is_scalar($icon)) { + throw new LogicException(sprintf( + 'Glyphicon and fontAwesome "icon" option expects a scalar value, "%s" given', + is_object($icon) ? get_class($icon) : gettype($icon) + )); + } elseif (!is_string($position)) { + throw new LogicException(sprintf( + 'Glyphicon and fontAwesome "position" option expects a string, "%s" given', + is_object($position) ? get_class($position) : gettype($position) + )); + } elseif ($position !== self::ICON_PREPEND && $position !== self::ICON_APPEND) { + throw new LogicException(sprintf( + 'Glyphicon and fontAwesome "position" option allows "' . self::ICON_PREPEND . '" or "' . self::ICON_APPEND . '", "%s" given', + is_object($position) ? get_class($position) : gettype($position) + )); + } + + if (!isset($sIconHelperMethod)) { + throw new LogicException(sprintf( + 'Button has an icon option, but no icon helper found' + )); + } + + if ($sButtonContent) { + if ($position === self::ICON_PREPEND) { + $sButtonContent = $this->getView()->{$sIconHelperMethod}( + $icon, + isset($aIconOptions['attributes'])?$aIconOptions['attributes']:null + ) . ' ' . $sButtonContent; + } else { + $sButtonContent .= ' ' . $this->getView()->{$sIconHelperMethod}( + $icon, + isset($aIconOptions['attributes'])?$aIconOptions['attributes']:null + ); + } + } else { + $sButtonContent = $this->getView()->{$sIconHelperMethod}( + $icon, + isset($aIconOptions['attributes']) ? $aIconOptions['attributes'] : null + ); + } + } + + /* + * Dropdown button + */ + if ($aDropdownOptions = $oElement->getOption('dropdown')) { + if (!is_array($aDropdownOptions)) { + throw new LogicException(sprintf( + '"dropdown" option expects an array, "%s" given', + is_object($aDropdownOptions) ? get_class($aDropdownOptions) : gettype($aDropdownOptions) + )); + } + + if (empty($aDropdownOptions['split'])) { + /* + * Class + */ + if (!preg_match('/(\s|^)dropdown-toggle(\s|$)/', $sClass = $oElement->getAttribute('class'))) { + $oElement->setAttribute('class', trim($sClass . ' dropdown-toggle')); + } + + /* + * data-toggle + */ + $oElement->setAttribute('data-toggle', 'dropdown'); + $sMarkup = $this->openTag($oElement) . + sprintf(static::$dropdownToggleFormat, $sButtonContent) . + $this->closeTag(); + } else { + /* + * Add caret element + */ + $sMarkup = $this->openTag($oElement) . + $sButtonContent . + $this->closeTag() . + sprintf(static::$dropdownCaretFormat, $oElement->getAttribute('class')); + } + + /* + * No container + */ + if ($oElement->getOption('disable-twb')) { + return $sMarkup . $this->getView()->dropdown()->renderListItems($aDropdownOptions); + } + + /* + * Render button + dropdown + */ + return sprintf( + static::$dropdownContainerFormat, + //Drop way + empty($aDropdownOptions['dropup']) ? '' : 'dropup', + $sMarkup . + $this->getView()->dropdown()->renderListItems($aDropdownOptions) + ); + } + + return $this->openTag($oElement) . $sButtonContent . $this->closeTag(); + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php index 45cf558..04c2d2a 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormCheckbox.php @@ -1,140 +1,141 @@ -getOption('disable-twb')) { - return parent::render($oElement); - } - - if (!$oElement instanceof Checkbox) { - throw new InvalidArgumentException(sprintf( - '%s requires that the element is of type Laminas\Form\Element\Checkbox', - __METHOD__ - )); - } - if (($sName = $oElement->getName()) !== 0 && empty($sName)) { - throw new LogicException(sprintf( - '%s requires that the element has an assigned name; none discovered', - __METHOD__ - )); - } - - $aAttributes = $oElement->getAttributes(); - $aAttributes['name'] = $sName; - $aAttributes['type'] = $this->getInputType(); - $aAttributes['value'] = $oElement->getCheckedValue(); - $sClosingBracket = $this->getInlineClosingBracket(); - - if ($oElement->isChecked()) { - $aAttributes['checked'] = 'checked'; - } - - // Render label - $sLabelOpen = $sLabelClose = ''; - $sLabelContent = $this->getLabelContent($oElement); - if($sLabelContent) { - $oLabelHelper = $this->getLabelHelper(); - $sLabelOpen = $oLabelHelper->openTag($oElement->getLabelAttributes() ? : null); - $sLabelClose = $oLabelHelper->closeTag(); - } - - // Render checkbox - $sElementContent = sprintf('createAttributesString($aAttributes), $sClosingBracket); - - // Add label markup - if ($this->getLabelPosition($oElement) === FormRow::LABEL_PREPEND) { - $sElementContent = $sLabelOpen . - ($sLabelContent ? rtrim($sLabelContent) . ' ' : '') . - $sElementContent . - $sLabelClose; - } else { - $sElementContent = $sLabelOpen . - $sElementContent . - ($sLabelContent ? ' ' . ltrim($sLabelContent) : '') . - $sLabelClose; - } - - //Render hidden input - if ($oElement->useHiddenElement()) { - $sElementContent = sprintf( - 'createAttributesString(array( - 'name' => $aAttributes['name'], - 'value' => $oElement->getUncheckedValue(), - )), - $sClosingBracket - ) . $sElementContent; - } - return $sElementContent; - } - - /** - * @param ElementInterface $oElement - * @return string - */ - public function getLabelContent(ElementInterface $oElement){ - $sLabelContent = $oElement->getLabel() ? : ''; - if ($sLabelContent) { - if ($oTranslator = $this->getTranslator()) { - $sLabelContent = $oTranslator->translate($sLabelContent, $this->getTranslatorTextDomain()); - } - } - return $sLabelContent; - } - - /** - * Get the label position - * @return string - */ - public function getLabelPosition(Checkbox $oElement) - { - return $oElement->getLabelOption('position')? : FormRow::LABEL_APPEND; - } - - /** - * Retrieve the FormLabel helper - * @return FormLabel - */ - protected function getLabelHelper() - { - if ($this->labelHelper) { - return $this->labelHelper; - } - if (method_exists($this->view, 'plugin')) { - $this->labelHelper = $this->view->plugin('form_label'); - } - if (!($this->labelHelper instanceof FormLabel)) { - $this->labelHelper = new FormLabel(); - } - if ($this->hasTranslator()) { - $this->labelHelper->setTranslator($this->getTranslator(), $this->getTranslatorTextDomain()); - } - return $this->labelHelper; - } -} +getOption('disable-twb')) { + return parent::render($oElement); + } + + if (!$oElement instanceof Checkbox) { + throw new InvalidArgumentException(sprintf( + '%s requires that the element is of type Laminas\Form\Element\Checkbox', + __METHOD__ + )); + } + if (($sName = $oElement->getName()) !== 0 && empty($sName)) { + throw new LogicException(sprintf( + '%s requires that the element has an assigned name; none discovered', + __METHOD__ + )); + } + + $aAttributes = $oElement->getAttributes(); + $aAttributes['name'] = $sName; + $aAttributes['type'] = $this->getInputType(); + $aAttributes['value'] = $oElement->getCheckedValue(); + $sClosingBracket = $this->getInlineClosingBracket(); + + if ($oElement->isChecked()) { + $aAttributes['checked'] = 'checked'; + } + + // Render label + $sLabelOpen = $sLabelClose = ''; + $sLabelContent = $this->getLabelContent($oElement); + if($sLabelContent) { + $oLabelHelper = $this->getLabelHelper(); + $sLabelOpen = $oLabelHelper->openTag($oElement->getLabelAttributes() ? : null); + $sLabelClose = $oLabelHelper->closeTag(); + } + + // Render checkbox + $sElementContent = sprintf('createAttributesString($aAttributes), $sClosingBracket); + + // Add label markup + if ($this->getLabelPosition($oElement) === FormRow::LABEL_PREPEND) { + $sElementContent = $sLabelOpen . + ($sLabelContent ? rtrim($sLabelContent) . ' ' : '') . + $sElementContent . + $sLabelClose; + } else { + $sElementContent = $sLabelOpen . + $sElementContent . + ($sLabelContent ? ' ' . ltrim($sLabelContent) : '') . + $sLabelClose; + } + + //Render hidden input + if ($oElement->useHiddenElement()) { + $sElementContent = sprintf( + 'createAttributesString([ + 'name' => $aAttributes['name'], + 'value' => $oElement->getUncheckedValue(), + ]), + $sClosingBracket + ) . $sElementContent; + } + return $sElementContent; + } + + /** + * @param ElementInterface $oElement + * @return string + */ + public function getLabelContent(ElementInterface $oElement) + { + $sLabelContent = $oElement->getLabel() ? : ''; + if ($sLabelContent) { + if ($oTranslator = $this->getTranslator()) { + $sLabelContent = $oTranslator->translate($sLabelContent, $this->getTranslatorTextDomain()); + } + } + return $sLabelContent; + } + + /** + * Get the label position + * @return string + */ + public function getLabelPosition(Checkbox $oElement) + { + return $oElement->getLabelOption('position')? : FormRow::LABEL_APPEND; + } + + /** + * Retrieve the FormLabel helper + * @return FormLabel + */ + protected function getLabelHelper() + { + if ($this->labelHelper) { + return $this->labelHelper; + } + if (method_exists($this->view, 'plugin')) { + $this->labelHelper = $this->view->plugin('form_label'); + } + if (!($this->labelHelper instanceof FormLabel)) { + $this->labelHelper = new FormLabel(); + } + if ($this->hasTranslator()) { + $this->labelHelper->setTranslator($this->getTranslator(), $this->getTranslatorTextDomain()); + } + return $this->labelHelper; + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php index 5fd732c..cf48856 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormCollection.php @@ -1,120 +1,124 @@ -%s'; - - /** - * @var string - */ - protected static $fieldsetFormat = '%s'; - - /** - * Attributes valid for the tag represented by this helper - * @var array - */ - protected $validTagAttributes = array( - 'disabled' => true - ); - - /** - * Render a collection by iterating through all fieldsets and elements - * @param \Laminas\Form\ElementInterface $oElement - * @return string - */ - public function render(ElementInterface $oElement): string - { - $oRenderer = $this->getView(); - if (!method_exists($oRenderer, 'plugin')) { - return ''; - } - - $bShouldWrap = $this->shouldWrap; - - $sMarkup = ''; - $sElementLayout = $oElement->getOption('twb-layout'); - if ($oElement instanceof \IteratorAggregate) { - $oElementHelper = $this->getElementHelper(); - $oFieldsetHelper = $this->getFieldsetHelper(); - - foreach ($oElement->getIterator() as $oElementOrFieldset) { - $aOptions = $oElementOrFieldset->getOptions(); - if ($sElementLayout && empty($aOptions['twb-layout'])) { - $aOptions['twb-layout'] = $sElementLayout; - $oElementOrFieldset->setOptions($aOptions); - } - - if ($oElementOrFieldset instanceof \Laminas\Form\FieldsetInterface) { - $sMarkup .= $oFieldsetHelper($oElementOrFieldset); - } elseif ($oElementOrFieldset instanceof \Laminas\Form\ElementInterface) { - if ($oElementOrFieldset->getOption('twb-row-open')) { - $sMarkup .= '
' . "\n"; - } - - $sMarkup .= $oElementHelper($oElementOrFieldset); - - if ($oElementOrFieldset->getOption('twb-row-close')) { - $sMarkup .= '
' . "\n"; - } - } - } - if ($oElement instanceof \Laminas\Form\Element\Collection && $oElement->shouldCreateTemplate()) { - $sMarkup .= $this->renderTemplate($oElement); - } - } - - if ($bShouldWrap) { - if (false != ($sLabel = $oElement->getLabel())) { - if (null !== ($oTranslator = $this->getTranslator())) { - $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); - } - - $sMarkup = sprintf( - static::$legendFormat, ($sAttributes = $this->createAttributesString($oElement->getLabelAttributes()? : array())) ? ' ' . $sAttributes : '', $this->getEscapeHtmlHelper()->__invoke($sLabel) - ) . $sMarkup; - } - - //Set form layout class - if ($sElementLayout) { - $sLayoutClass = 'form-' . $sElementLayout; - if (false != ($sElementClass = $oElement->getAttribute('class'))) { - if (!preg_match('/(\s|^)' . preg_quote($sLayoutClass, '/') . '(\s|$)/', $sElementClass)) { - $oElement->setAttribute('class', trim($sElementClass . ' ' . $sLayoutClass)); - } - } else { - $oElement->setAttribute('class', $sLayoutClass); - } - } - - $sMarkup = sprintf( - static::$fieldsetFormat, ($sAttributes = $this->createAttributesString($oElement->getAttributes())) ? ' ' . $sAttributes : '', $sMarkup - ); - } - return $sMarkup; - } - - /** - * Only render a template - * - * @param CollectionElement $collection - * @return string - */ - public function renderTemplate(CollectionElement $collection): string - { - if (false != ($sElementLayout = $collection->getOption('twb-layout'))) { - $elementOrFieldset = $collection->getTemplateElement(); - $elementOrFieldset->setOption('twb-layout', $sElementLayout); - } - - return parent::renderTemplate($collection); - } -} +%s'; + + /** + * @var string + */ + protected static $fieldsetFormat = '%s'; + + /** + * Attributes valid for the tag represented by this helper + * @var array + */ + protected $validTagAttributes = [ + 'disabled' => true + ]; + + /** + * Render a collection by iterating through all fieldsets and elements + * @param \Laminas\Form\ElementInterface $oElement + * @return string + */ + public function render(ElementInterface $oElement): string + { + $oRenderer = $this->getView(); + if (!method_exists($oRenderer, 'plugin')) { + return ''; + } + + $bShouldWrap = $this->shouldWrap; + + $sMarkup = ''; + $sElementLayout = $oElement->getOption('twb-layout'); + if ($oElement instanceof \IteratorAggregate) { + $oElementHelper = $this->getElementHelper(); + $oFieldsetHelper = $this->getFieldsetHelper(); + + foreach ($oElement->getIterator() as $oElementOrFieldset) { + $aOptions = $oElementOrFieldset->getOptions(); + if ($sElementLayout && empty($aOptions['twb-layout'])) { + $aOptions['twb-layout'] = $sElementLayout; + $oElementOrFieldset->setOptions($aOptions); + } + + if ($oElementOrFieldset instanceof \Laminas\Form\FieldsetInterface) { + $sMarkup .= $oFieldsetHelper($oElementOrFieldset); + } elseif ($oElementOrFieldset instanceof \Laminas\Form\ElementInterface) { + if ($oElementOrFieldset->getOption('twb-row-open')) { + $sMarkup .= '
' . "\n"; + } + + $sMarkup .= $oElementHelper($oElementOrFieldset); + + if ($oElementOrFieldset->getOption('twb-row-close')) { + $sMarkup .= '
' . "\n"; + } + } + } + if ($oElement instanceof \Laminas\Form\Element\Collection && $oElement->shouldCreateTemplate()) { + $sMarkup .= $this->renderTemplate($oElement); + } + } + + if ($bShouldWrap) { + if (false != ($sLabel = $oElement->getLabel())) { + if (null !== ($oTranslator = $this->getTranslator())) { + $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); + } + + $sMarkup = sprintf( + static::$legendFormat, + ($sAttributes = $this->createAttributesString($oElement->getLabelAttributes()? : [])) ? ' ' . $sAttributes : '', + $this->getEscapeHtmlHelper()->__invoke($sLabel) + ) . $sMarkup; + } + + //Set form layout class + if ($sElementLayout) { + $sLayoutClass = 'form-' . $sElementLayout; + if (false != ($sElementClass = $oElement->getAttribute('class'))) { + if (!preg_match('/(\s|^)' . preg_quote($sLayoutClass, '/') . '(\s|$)/', $sElementClass)) { + $oElement->setAttribute('class', trim($sElementClass . ' ' . $sLayoutClass)); + } + } else { + $oElement->setAttribute('class', $sLayoutClass); + } + } + + $sMarkup = sprintf( + static::$fieldsetFormat, + ($sAttributes = $this->createAttributesString($oElement->getAttributes())) ? ' ' . $sAttributes : '', + $sMarkup + ); + } + return $sMarkup; + } + + /** + * Only render a template + * + * @param CollectionElement $collection + * @return string + */ + public function renderTemplate(CollectionElement $collection): string + { + if (false != ($sElementLayout = $collection->getOption('twb-layout'))) { + $elementOrFieldset = $collection->getTemplateElement(); + $elementOrFieldset->setOption('twb-layout', $sElementLayout); + } + + return parent::renderTemplate($collection); + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php index 63f0311..63cbdbf 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php @@ -1,283 +1,283 @@ -%s'; - - /** - * @var string - */ - protected static $inputGroupFormat = '
%s
'; - - /** - * Translator (optional) - * @var Translator - */ - protected $translator; - - /** - * Translator text domain (optional) - * @var string - */ - protected $translatorTextDomain = 'default'; - - /** - * Whether translator should be used - * @var boolean - */ - protected $translatorEnabled = true; - - /** - * Hold configurable options - * @var ModuleOptions - */ - protected $options; - - /** - * Instance map to view helper - * - * @var array - */ - protected $classMap = array( - 'Laminas\Form\Element\Button' => 'formbutton', - 'Laminas\Form\Element\Captcha' => 'formcaptcha', - 'Laminas\Form\Element\Csrf' => 'formhidden', - 'Laminas\Form\Element\Collection' => 'formcollection', - 'Laminas\Form\Element\DateTimeSelect' => 'formdatetimeselect', - 'Laminas\Form\Element\DateSelect' => 'formdateselect', - 'Laminas\Form\Element\MonthSelect' => 'formmonthselect', - 'TwbBundle\Form\Element\StaticElement' => 'formStatic', - ); - - public function __construct(ModuleOptions $options) - { - if (is_array($options->getTypeMap())) { - $this->typeMap = array_merge($this->typeMap, $options->getTypeMap()); - } - if (is_array($options->getClassMap())) { - $this->classMap = array_merge($this->classMap, $options->getClassMap()); - } - $this->options = $options; - } - - /** - * Render an element - * @param ElementInterface $oElement - * @return string - */ - public function render(ElementInterface $oElement): string - { - // Add form-controll class - $sElementType = $oElement->getAttribute('type'); - if (!in_array($sElementType, $this->options->getIgnoredViewHelpers()) && - !($oElement instanceof Collection) - ) { - if ($sElementClass = $oElement->getAttribute('class')) { - if (!preg_match('/(\s|^)form-control(\s|$)/', $sElementClass)) { - $oElement->setAttribute('class', trim($sElementClass . ' form-control')); - } - } else { - $oElement->setAttribute('class', 'form-control'); - } - } - - $sMarkup = parent::render($oElement); - - // Addon prepend - if ($aAddOnPrepend = $oElement->getOption('add-on-prepend')) { - $sMarkup = $this->renderAddOn($aAddOnPrepend) . $sMarkup; - } - - // Addon append - if ($aAddOnAppend = $oElement->getOption('add-on-append')) { - $sMarkup .= $this->renderAddOn($aAddOnAppend); - } - - if ($aAddOnAppend || $aAddOnPrepend) { - $sSpecialClass = ''; - // Input size - if ($sElementClass = $oElement->getAttribute('class')) { - if (preg_match('/(\s|^)input-lg(\s|$)/', $sElementClass)) { - $sSpecialClass .= ' input-group-lg'; - } elseif (preg_match('/(\s|^)input-sm(\s|$)/', $sElementClass)) { - $sSpecialClass .= ' input-group-sm'; - } - } - return sprintf( - static::$inputGroupFormat, - trim($sSpecialClass), - $sMarkup - ); - } - return $sMarkup; - } - - /** - * Render addo-on markup - * @param string $aAddOnOptions - * @throws InvalidArgumentException - * @throws LogicException - * @return string - */ - protected function renderAddOn($aAddOnOptions) - { - if (empty($aAddOnOptions)) { - throw new InvalidArgumentException('Addon options are empty'); - } - if ($aAddOnOptions instanceof ElementInterface) { - $aAddOnOptions = array('element' => $aAddOnOptions); - } elseif (is_scalar($aAddOnOptions)) { - $aAddOnOptions = array('text' => $aAddOnOptions); - } elseif (!is_array($aAddOnOptions)) { - throw new InvalidArgumentException(sprintf( - 'Addon options expects an array or a scalar value, "%s" given', - is_object($aAddOnOptions) ? get_class($aAddOnOptions) : gettype($aAddOnOptions) - )); - } - - $sMarkup = ''; - $sAddonTagName = 'span'; - $sAddonClass = ''; - if (!empty($aAddOnOptions['text'])) { - if (!is_scalar($aAddOnOptions['text'])) { - throw new InvalidArgumentException(sprintf( - '"text" option expects a scalar value, "%s" given', - is_object($aAddOnOptions['text']) ? get_class($aAddOnOptions['text']) : gettype($aAddOnOptions['text']) - )); - } elseif (($oTranslator = $this->getTranslator())) { - $sMarkup .= $oTranslator->translate($aAddOnOptions['text'], $this->getTranslatorTextDomain()); - } else { - $sMarkup .= $aAddOnOptions['text']; - } - $sAddonClass .= ' input-group-addon'; - } elseif (!empty($aAddOnOptions['element'])) { - if (is_array($aAddOnOptions['element']) || - ($aAddOnOptions['element'] instanceof Traversable && - !($aAddOnOptions['element'] instanceof ElementInterface)) - ) { - $oFactory = new Factory(); - $aAddOnOptions['element'] = $oFactory->create($aAddOnOptions['element']); - } elseif (!($aAddOnOptions['element'] instanceof ElementInterface)) { - throw new LogicException(sprintf( - '"element" option expects an instanceof Laminas\Form\ElementInterface, "%s" given', - is_object($aAddOnOptions['element']) ? get_class($aAddOnOptions['element']) : gettype($aAddOnOptions['element']) - )); - } - - $aAddOnOptions['element']->setOptions(array_merge( - $aAddOnOptions['element']->getOptions(), - array('disable-twb' => true) - )); - - $sMarkup .= $this->render($aAddOnOptions['element']); - - //Element is a button, so add-on container must be a "div" - if ($aAddOnOptions['element'] instanceof Button) { - $sAddonClass .= ' input-group-btn'; - $sAddonTagName = 'div'; - } else { - $sAddonClass .= ' input-group-addon'; - } - } - - return sprintf(static::$addonFormat, $sAddonTagName, trim($sAddonClass), $sMarkup, $sAddonTagName); - } - - /** - * Sets translator to use in helper - * @see TranslatorAwareInterface::setTranslator() - * @param TranslatorInterface $oTranslator : [optional] translator. Default is null, which sets no translator. - * @param string $sTextDomain : [optional] text domain Default is null, which skips setTranslatorTextDomain - * @return TwbBundleFormElement - */ - public function setTranslator(TranslatorInterface $oTranslator = null, $sTextDomain = null) - { - $this->translator = $oTranslator; - if (null !== $sTextDomain) { - $this->setTranslatorTextDomain($sTextDomain); - } - return $this; - } - - /** - * Returns translator used in helper - * @see TranslatorAwareInterface::getTranslator() - * @return null|TranslatorInterface - */ - public function getTranslator() - { - return $this->isTranslatorEnabled() ? $this->translator : null; - } - - /** - * Checks if the helper has a translator - * @see TranslatorAwareInterface::hasTranslator() - * @return boolean - */ - public function hasTranslator() - { - return !!$this->getTranslator(); - } - - /** - * Sets whether translator is enabled and should be used - * @see TranslatorAwareInterface::setTranslatorEnabled() - * @param boolean $bEnabled - * @return TwbBundleFormElement - */ - public function setTranslatorEnabled($bEnabled = true) - { - $this->translatorEnabled = !!$bEnabled; - return $this; - } - - /** - * Returns whether translator is enabled and should be used - * @see TranslatorAwareInterface::isTranslatorEnabled() - * @return boolean - */ - public function isTranslatorEnabled() - { - return $this->translatorEnabled; - } - - /** - * Set translation text domain - * @see TranslatorAwareInterface::setTranslatorTextDomain() - * @param string $sTextDomain - * @return TwbBundleFormElement - */ - public function setTranslatorTextDomain($sTextDomain = 'default') - { - $this->translatorTextDomain = $sTextDomain; - return $this; - } - - /** - * Return the translation text domain - * @see TranslatorAwareInterface::getTranslatorTextDomain() - * @return string - */ - public function getTranslatorTextDomain() - { - return $this->translatorTextDomain; - } -} +%s'; + + /** + * @var string + */ + protected static $inputGroupFormat = '
%s
'; + + /** + * Translator (optional) + * @var Translator + */ + protected $translator; + + /** + * Translator text domain (optional) + * @var string + */ + protected $translatorTextDomain = 'default'; + + /** + * Whether translator should be used + * @var boolean + */ + protected $translatorEnabled = true; + + /** + * Hold configurable options + * @var ModuleOptions + */ + protected $options; + + /** + * Instance map to view helper + * + * @var array + */ + protected $classMap = [ + 'Laminas\Form\Element\Button' => 'formbutton', + 'Laminas\Form\Element\Captcha' => 'formcaptcha', + 'Laminas\Form\Element\Csrf' => 'formhidden', + 'Laminas\Form\Element\Collection' => 'formcollection', + 'Laminas\Form\Element\DateTimeSelect' => 'formdatetimeselect', + 'Laminas\Form\Element\DateSelect' => 'formdateselect', + 'Laminas\Form\Element\MonthSelect' => 'formmonthselect', + 'TwbBundle\Form\Element\StaticElement' => 'formStatic', + ]; + + public function __construct(ModuleOptions $options) + { + if (is_array($options->getTypeMap())) { + $this->typeMap = array_merge($this->typeMap, $options->getTypeMap()); + } + if (is_array($options->getClassMap())) { + $this->classMap = array_merge($this->classMap, $options->getClassMap()); + } + $this->options = $options; + } + + /** + * Render an element + * @param ElementInterface $oElement + * @return string + */ + public function render(ElementInterface $oElement): string + { + // Add form-controll class + $sElementType = $oElement->getAttribute('type'); + if (!in_array($sElementType, $this->options->getIgnoredViewHelpers()) && + !($oElement instanceof Collection) + ) { + if ($sElementClass = $oElement->getAttribute('class')) { + if (!preg_match('/(\s|^)form-control(\s|$)/', $sElementClass)) { + $oElement->setAttribute('class', trim($sElementClass . ' form-control')); + } + } else { + $oElement->setAttribute('class', 'form-control'); + } + } + + $sMarkup = parent::render($oElement); + + // Addon prepend + if ($aAddOnPrepend = $oElement->getOption('add-on-prepend')) { + $sMarkup = $this->renderAddOn($aAddOnPrepend) . $sMarkup; + } + + // Addon append + if ($aAddOnAppend = $oElement->getOption('add-on-append')) { + $sMarkup .= $this->renderAddOn($aAddOnAppend); + } + + if ($aAddOnAppend || $aAddOnPrepend) { + $sSpecialClass = ''; + // Input size + if ($sElementClass = $oElement->getAttribute('class')) { + if (preg_match('/(\s|^)input-lg(\s|$)/', $sElementClass)) { + $sSpecialClass .= ' input-group-lg'; + } elseif (preg_match('/(\s|^)input-sm(\s|$)/', $sElementClass)) { + $sSpecialClass .= ' input-group-sm'; + } + } + return sprintf( + static::$inputGroupFormat, + trim($sSpecialClass), + $sMarkup + ); + } + return $sMarkup; + } + + /** + * Render addo-on markup + * @param string $aAddOnOptions + * @throws InvalidArgumentException + * @throws LogicException + * @return string + */ + protected function renderAddOn($aAddOnOptions) + { + if (empty($aAddOnOptions)) { + throw new InvalidArgumentException('Addon options are empty'); + } + if ($aAddOnOptions instanceof ElementInterface) { + $aAddOnOptions = ['element' => $aAddOnOptions]; + } elseif (is_scalar($aAddOnOptions)) { + $aAddOnOptions = ['text' => $aAddOnOptions]; + } elseif (!is_array($aAddOnOptions)) { + throw new InvalidArgumentException(sprintf( + 'Addon options expects an array or a scalar value, "%s" given', + is_object($aAddOnOptions) ? get_class($aAddOnOptions) : gettype($aAddOnOptions) + )); + } + + $sMarkup = ''; + $sAddonTagName = 'span'; + $sAddonClass = ''; + if (!empty($aAddOnOptions['text'])) { + if (!is_scalar($aAddOnOptions['text'])) { + throw new InvalidArgumentException(sprintf( + '"text" option expects a scalar value, "%s" given', + is_object($aAddOnOptions['text']) ? get_class($aAddOnOptions['text']) : gettype($aAddOnOptions['text']) + )); + } elseif (($oTranslator = $this->getTranslator())) { + $sMarkup .= $oTranslator->translate($aAddOnOptions['text'], $this->getTranslatorTextDomain()); + } else { + $sMarkup .= $aAddOnOptions['text']; + } + $sAddonClass .= ' input-group-addon'; + } elseif (!empty($aAddOnOptions['element'])) { + if (is_array($aAddOnOptions['element']) || + ($aAddOnOptions['element'] instanceof Traversable && + !($aAddOnOptions['element'] instanceof ElementInterface)) + ) { + $oFactory = new Factory(); + $aAddOnOptions['element'] = $oFactory->create($aAddOnOptions['element']); + } elseif (!($aAddOnOptions['element'] instanceof ElementInterface)) { + throw new LogicException(sprintf( + '"element" option expects an instanceof Laminas\Form\ElementInterface, "%s" given', + is_object($aAddOnOptions['element']) ? get_class($aAddOnOptions['element']) : gettype($aAddOnOptions['element']) + )); + } + + $aAddOnOptions['element']->setOptions(array_merge( + $aAddOnOptions['element']->getOptions(), + ['disable-twb' => true] + )); + + $sMarkup .= $this->render($aAddOnOptions['element']); + + //Element is a button, so add-on container must be a "div" + if ($aAddOnOptions['element'] instanceof Button) { + $sAddonClass .= ' input-group-btn'; + $sAddonTagName = 'div'; + } else { + $sAddonClass .= ' input-group-addon'; + } + } + + return sprintf(static::$addonFormat, $sAddonTagName, trim($sAddonClass), $sMarkup, $sAddonTagName); + } + + /** + * Sets translator to use in helper + * @see TranslatorAwareInterface::setTranslator() + * @param TranslatorInterface $oTranslator : [optional] translator. Default is null, which sets no translator. + * @param string $sTextDomain : [optional] text domain Default is null, which skips setTranslatorTextDomain + * @return TwbBundleFormElement + */ + public function setTranslator(TranslatorInterface $oTranslator = null, $sTextDomain = null) + { + $this->translator = $oTranslator; + if (null !== $sTextDomain) { + $this->setTranslatorTextDomain($sTextDomain); + } + return $this; + } + + /** + * Returns translator used in helper + * @see TranslatorAwareInterface::getTranslator() + * @return null|TranslatorInterface + */ + public function getTranslator() + { + return $this->isTranslatorEnabled() ? $this->translator : null; + } + + /** + * Checks if the helper has a translator + * @see TranslatorAwareInterface::hasTranslator() + * @return boolean + */ + public function hasTranslator() + { + return !!$this->getTranslator(); + } + + /** + * Sets whether translator is enabled and should be used + * @see TranslatorAwareInterface::setTranslatorEnabled() + * @param boolean $bEnabled + * @return TwbBundleFormElement + */ + public function setTranslatorEnabled($bEnabled = true) + { + $this->translatorEnabled = !!$bEnabled; + return $this; + } + + /** + * Returns whether translator is enabled and should be used + * @see TranslatorAwareInterface::isTranslatorEnabled() + * @return boolean + */ + public function isTranslatorEnabled() + { + return $this->translatorEnabled; + } + + /** + * Set translation text domain + * @see TranslatorAwareInterface::setTranslatorTextDomain() + * @param string $sTextDomain + * @return TwbBundleFormElement + */ + public function setTranslatorTextDomain($sTextDomain = 'default') + { + $this->translatorTextDomain = $sTextDomain; + return $this; + } + + /** + * Return the translation text domain + * @see TranslatorAwareInterface::getTranslatorTextDomain() + * @return string + */ + public function getTranslatorTextDomain() + { + return $this->translatorTextDomain; + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormElementErrors.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormElementErrors.php index b075ac9..4411bfc 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormElementErrors.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormElementErrors.php @@ -1,11 +1,11 @@ - 'help-block' - ); -} + 'help-block' + ]; +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormErrors.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormErrors.php index 1ac5b1b..98c2856 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormErrors.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormErrors.php @@ -1,84 +1,84 @@ -%s'; - protected $messageSeparatorString = '
  • '; - - /** - * Invoke as function - * @param \Laminas\Form\FormInterface $oForm - * @param string $sMessage - * @param string $bDismissable - * @return string|null - */ - public function __invoke(FormInterface $oForm = null, $sMessage = null, $bDismissable = false) - { - if (!$oForm) { - return $this; - } - - if (!$sMessage) { - $sMessage = $this->defaultErrorText; - } - - if ($oForm->hasValidated() && !$oForm->isValid()) { - - return $this->render($oForm, $sMessage, $bDismissable); - } - - return null; - } - - /** - * Renders the error messages. - * @param \Laminas\Form\FormInterface $oForm - * @return string - */ - public function render(FormInterface $oForm, $sMessage, $bDismissable = false) - { - $errorHtml = sprintf($this->messageOpenFormat, $sMessage); - - $sMessagesArray = array(); - - foreach ($oForm->getMessages() as $fieldName => $sMessages) { - foreach ($sMessages as $sMessage) { - if ($oForm->get($fieldName)->getAttribute('id')) { - $sMessagesArray[] = sprintf( - '%s', - $oForm->get($fieldName)->getAttribute('id'), - $oForm->get($fieldName)->getLabel() . ': ' . $sMessage - ); - } else { - $sMessagesArray[] = $oForm->get($fieldName)->getLabel() . ': ' . $sMessage; - } - } - } - - return $this->dangerAlert( - $errorHtml . - implode($this->messageSeparatorString, $sMessagesArray) . - $this->messageCloseString, - $bDismissable - ); - } - - /** - * Creates and returns a "danger" alert. - * @param string $content - * @param boolean $bDismissable - * @return string - */ - public function dangerAlert($content, $bDismissable = false) - { - return $this->getView()->alert($content, array('class' => 'alert-danger'), $bDismissable); - } -} +%s
    • '; + protected $messageCloseString = '
    '; + protected $messageSeparatorString = '
  • '; + + /** + * Invoke as function + * @param \Laminas\Form\FormInterface $oForm + * @param string $sMessage + * @param string $bDismissable + * @return string|null + */ + public function __invoke(FormInterface $oForm = null, $sMessage = null, $bDismissable = false) + { + if (!$oForm) { + return $this; + } + + if (!$sMessage) { + $sMessage = $this->defaultErrorText; + } + + if ($oForm->hasValidated() && !$oForm->isValid()) { + + return $this->render($oForm, $sMessage, $bDismissable); + } + + return null; + } + + /** + * Renders the error messages. + * @param \Laminas\Form\FormInterface $oForm + * @return string + */ + public function render(FormInterface $oForm, $sMessage, $bDismissable = false) + { + $errorHtml = sprintf($this->messageOpenFormat, $sMessage); + + $sMessagesArray = []; + + foreach ($oForm->getMessages() as $fieldName => $sMessages) { + foreach ($sMessages as $sMessage) { + if ($oForm->get($fieldName)->getAttribute('id')) { + $sMessagesArray[] = sprintf( + '%s', + $oForm->get($fieldName)->getAttribute('id'), + $oForm->get($fieldName)->getLabel() . ': ' . $sMessage + ); + } else { + $sMessagesArray[] = $oForm->get($fieldName)->getLabel() . ': ' . $sMessage; + } + } + } + + return $this->dangerAlert( + $errorHtml . + implode($this->messageSeparatorString, $sMessagesArray) . + $this->messageCloseString, + $bDismissable + ); + } + + /** + * Creates and returns a "danger" alert. + * @param string $content + * @param boolean $bDismissable + * @return string + */ + public function dangerAlert($content, $bDismissable = false) + { + return $this->getView()->alert($content, ['class' => 'alert-danger'], $bDismissable); + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormMultiCheckbox.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormMultiCheckbox.php index cf9b975..50acf81 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormMultiCheckbox.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormMultiCheckbox.php @@ -1,32 +1,32 @@ -getOptions(); - - // For inline multi-checkbox - if (isset($aElementOptions['inline']) && $aElementOptions['inline'] == true) { - $this->setSeparator(''); - $oElement->setLabelAttributes(array('class' => 'checkbox-inline')); - - return sprintf('%s', parent::render($oElement)); - } - - $this->setSeparator('
    '); - $oElement->setLabelAttributes(array('class' => 'checkbox')); - - return sprintf('
    %s
    ', parent::render($oElement)); - } -} +getOptions(); + + // For inline multi-checkbox + if (isset($aElementOptions['inline']) && $aElementOptions['inline'] == true) { + $this->setSeparator(''); + $oElement->setLabelAttributes(['class' => 'checkbox-inline']); + + return sprintf('%s', parent::render($oElement)); + } + + $this->setSeparator('
    '); + $oElement->setLabelAttributes(['class' => 'checkbox']); + + return sprintf('
    %s
    ', parent::render($oElement)); + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php index 4fa74f9..458c593 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormRadio.php @@ -1,158 +1,158 @@ -
    '; - - /** - * @var string - */ - protected static $checkboxFormat = '
    %s
    '; - - /** - * @see \Laminas\Form\View\Helper\FormRadio::render() - * @param \Laminas\Form\ElementInterface $oElement - * @return string - */ - public function render(ElementInterface $oElement): string - { - $aElementOptions = $oElement->getOptions(); - - if (isset($aElementOptions['disable-twb']) && $aElementOptions['disable-twb'] == true) { - $sSeparator = $this->getSeparator(); - $this->setSeparator(''); - $sReturn = parent::render($oElement); - $this->setSeparator($sSeparator); - return $sReturn; - } - - if (isset($aElementOptions['inline']) && $aElementOptions['inline'] == true) { - $sSeparator = $this->getSeparator(); - $this->setSeparator(''); - $oElement->setLabelAttributes(array('class' => 'radio-inline')); - $sReturn = sprintf('%s', parent::render($oElement)); - $this->setSeparator($sSeparator); - return $sReturn; - } - - if (isset($aElementOptions['btn-group']) && $aElementOptions['btn-group'] != false) { - - $buttonClass = 'btn btn-primary'; - if (is_array($aElementOptions['btn-group']) && isset($aElementOptions['btn-group']['btn-class'])) { - $buttonClass = $aElementOptions['btn-group']['btn-class']; - } - - $this->setSeparator(''); - $oElement->setLabelAttributes(array('class' => $buttonClass)); - - return sprintf('
    %s
    ', parent::render($oElement)); - } - - return sprintf(static::$checkboxFormat, parent::render($oElement)); - } - - /** - * @see \Laminas\Form\View\Helper\FormMultiCheckbox::renderOptions() - * @param \Laminas\Form\Element\MultiCheckbox $oElement - * @param array $aOptions - * @param array $aSelectedOptions - * @param array $aAttributes - * @return string - */ - protected function renderOptions( - MultiCheckbox $oElement, - array $aOptions, - array $aSelectedOptions, - array $aAttributes - ): string { - $iIterator = 0; - $aGlobalLabelAttributes = $oElement->getLabelAttributes()? : $this->labelAttributes; - $sMarkup = ''; - $oLabelHelper = $this->getLabelHelper(); - $aElementOptions = $oElement->getOptions(); - foreach ($aOptions as $key => $aOptionspec) { - if (is_scalar($aOptionspec)) { - $aOptionspec = array('label' => $aOptionspec, 'value' => $key); - } - - $iIterator++; - if ($iIterator > 1 && array_key_exists('id', $aAttributes)) { - unset($aAttributes['id']); - } - - //Option attributes - $aInputAttributes = $aAttributes; - if (isset($aOptionspec['attributes'])) { - $aInputAttributes = \Laminas\Stdlib\ArrayUtils::merge($aInputAttributes, $aOptionspec['attributes']); - } - - //Option value - $aInputAttributes['value'] = isset($aOptionspec['value']) ? $aOptionspec['value'] : ''; - - //Selected option - if (in_array($aInputAttributes['value'], $aSelectedOptions, true)) { - $aInputAttributes['checked'] = true; - } elseif (isset($aOptionspec['selected'])) { - $aInputAttributes['checked'] = !!$aOptionspec['selected']; - } else { - $aInputAttributes['checked'] = isset($aInputAttributes['selected']) && $aInputAttributes['type'] !== 'radio' && $aInputAttributes['selected'] != false; - } - - //Disabled option - if (isset($aOptionspec['disabled'])) { - $aInputAttributes['disabled'] = !!$aOptionspec['disabled']; - } else { - $aInputAttributes['disabled'] = isset($aInputAttributes['disabled']) && $aInputAttributes['disabled'] != false; - } - - //Render option - $sOptionMarkup = sprintf('createAttributesString($aInputAttributes), $this->getInlineClosingBracket()); - - //Option label - $sLabel = isset($aOptionspec['label']) ? $aOptionspec['label'] : ''; - if ($sLabel) { - $aLabelAttributes = $aGlobalLabelAttributes; - if (isset($aElementOptions['btn-group']) && $aElementOptions['btn-group'] == true) { - if ($aInputAttributes['checked']) { - $aLabelAttributes['class'] = ((isset($aLabelAttributes['class'])) ? $aLabelAttributes['class'] : '') . ' active'; - } - } - - if (isset($aOptionspec['label_attributes'])) { - $aLabelAttributes = isset($aLabelAttributes) ? array_merge($aLabelAttributes, $aOptionspec['label_attributes']) : $aOptionspec['label_attributes']; - } - - if (null !== ($oTranslator = $this->getTranslator())) { - $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); - } - - if (!($oElement instanceof \Laminas\Form\LabelAwareInterface) || !$oElement->getLabelOption('disable_html_escape')) { - $sLabel = $this->getEscapeHtmlHelper()->__invoke($sLabel); - } - - switch ($this->getLabelPosition()) { - case self::LABEL_PREPEND: - $sOptionMarkup = sprintf($oLabelHelper->openTag($aLabelAttributes) . '%s%s' . $oLabelHelper->closeTag(), $sLabel, $sOptionMarkup); - break; - case self::LABEL_APPEND: - default: - $sOptionMarkup = sprintf($oLabelHelper->openTag($aLabelAttributes) . '%s%s' . $oLabelHelper->closeTag(), $sOptionMarkup, $sLabel); - break; - } - } - $sMarkup .= ($sMarkup ? $this->getSeparator() : '') . $sOptionMarkup; - } - return $sMarkup; - } -} +
    '; + + /** + * @var string + */ + protected static $checkboxFormat = '
    %s
    '; + + /** + * @see \Laminas\Form\View\Helper\FormRadio::render() + * @param \Laminas\Form\ElementInterface $oElement + * @return string + */ + public function render(ElementInterface $oElement): string + { + $aElementOptions = $oElement->getOptions(); + + if (isset($aElementOptions['disable-twb']) && $aElementOptions['disable-twb'] == true) { + $sSeparator = $this->getSeparator(); + $this->setSeparator(''); + $sReturn = parent::render($oElement); + $this->setSeparator($sSeparator); + return $sReturn; + } + + if (isset($aElementOptions['inline']) && $aElementOptions['inline'] == true) { + $sSeparator = $this->getSeparator(); + $this->setSeparator(''); + $oElement->setLabelAttributes(['class' => 'radio-inline']); + $sReturn = sprintf('%s', parent::render($oElement)); + $this->setSeparator($sSeparator); + return $sReturn; + } + + if (isset($aElementOptions['btn-group']) && $aElementOptions['btn-group'] != false) { + + $buttonClass = 'btn btn-primary'; + if (is_array($aElementOptions['btn-group']) && isset($aElementOptions['btn-group']['btn-class'])) { + $buttonClass = $aElementOptions['btn-group']['btn-class']; + } + + $this->setSeparator(''); + $oElement->setLabelAttributes(['class' => $buttonClass]); + + return sprintf('
    %s
    ', parent::render($oElement)); + } + + return sprintf(static::$checkboxFormat, parent::render($oElement)); + } + + /** + * @see \Laminas\Form\View\Helper\FormMultiCheckbox::renderOptions() + * @param \Laminas\Form\Element\MultiCheckbox $oElement + * @param array $aOptions + * @param array $aSelectedOptions + * @param array $aAttributes + * @return string + */ + protected function renderOptions( + MultiCheckbox $oElement, + array $aOptions, + array $aSelectedOptions, + array $aAttributes + ): string { + $iIterator = 0; + $aGlobalLabelAttributes = $oElement->getLabelAttributes()? : $this->labelAttributes; + $sMarkup = ''; + $oLabelHelper = $this->getLabelHelper(); + $aElementOptions = $oElement->getOptions(); + foreach ($aOptions as $key => $aOptionspec) { + if (is_scalar($aOptionspec)) { + $aOptionspec = ['label' => $aOptionspec, 'value' => $key]; + } + + $iIterator++; + if ($iIterator > 1 && array_key_exists('id', $aAttributes)) { + unset($aAttributes['id']); + } + + //Option attributes + $aInputAttributes = $aAttributes; + if (isset($aOptionspec['attributes'])) { + $aInputAttributes = \Laminas\Stdlib\ArrayUtils::merge($aInputAttributes, $aOptionspec['attributes']); + } + + //Option value + $aInputAttributes['value'] = isset($aOptionspec['value']) ? $aOptionspec['value'] : ''; + + //Selected option + if (in_array($aInputAttributes['value'], $aSelectedOptions, true)) { + $aInputAttributes['checked'] = true; + } elseif (isset($aOptionspec['selected'])) { + $aInputAttributes['checked'] = !!$aOptionspec['selected']; + } else { + $aInputAttributes['checked'] = isset($aInputAttributes['selected']) && $aInputAttributes['type'] !== 'radio' && $aInputAttributes['selected'] != false; + } + + //Disabled option + if (isset($aOptionspec['disabled'])) { + $aInputAttributes['disabled'] = !!$aOptionspec['disabled']; + } else { + $aInputAttributes['disabled'] = isset($aInputAttributes['disabled']) && $aInputAttributes['disabled'] != false; + } + + //Render option + $sOptionMarkup = sprintf('createAttributesString($aInputAttributes), $this->getInlineClosingBracket()); + + //Option label + $sLabel = isset($aOptionspec['label']) ? $aOptionspec['label'] : ''; + if ($sLabel) { + $aLabelAttributes = $aGlobalLabelAttributes; + if (isset($aElementOptions['btn-group']) && $aElementOptions['btn-group'] == true) { + if ($aInputAttributes['checked']) { + $aLabelAttributes['class'] = ((isset($aLabelAttributes['class'])) ? $aLabelAttributes['class'] : '') . ' active'; + } + } + + if (isset($aOptionspec['label_attributes'])) { + $aLabelAttributes = isset($aLabelAttributes) ? array_merge($aLabelAttributes, $aOptionspec['label_attributes']) : $aOptionspec['label_attributes']; + } + + if (null !== ($oTranslator = $this->getTranslator())) { + $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); + } + + if (!($oElement instanceof \Laminas\Form\LabelAwareInterface) || !$oElement->getLabelOption('disable_html_escape')) { + $sLabel = $this->getEscapeHtmlHelper()->__invoke($sLabel); + } + + switch ($this->getLabelPosition()) { + case self::LABEL_PREPEND: + $sOptionMarkup = sprintf($oLabelHelper->openTag($aLabelAttributes) . '%s%s' . $oLabelHelper->closeTag(), $sLabel, $sOptionMarkup); + break; + case self::LABEL_APPEND: + default: + $sOptionMarkup = sprintf($oLabelHelper->openTag($aLabelAttributes) . '%s%s' . $oLabelHelper->closeTag(), $sOptionMarkup, $sLabel); + break; + } + } + $sMarkup .= ($sMarkup ? $this->getSeparator() : '') . $sOptionMarkup; + } + return $sMarkup; + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php index c7727a9..7c68192 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormRow.php @@ -1,359 +1,365 @@ -%s
    '; - - /** - * @var string - */ - protected static $horizontalLayoutFormat = '
    %s
    '; - - /** - * @var string - */ - protected static $checkboxFormat = '
    %s
    '; - - /** - * @var string - */ - protected static $helpBlockFormat = '

    %s

    '; - - /** - * The class that is added to element that have errors - * @var string - */ - protected $inputErrorClass = ''; - - /** - * @var string - */ - protected $requiredFormat = null; - - /** - * @see FormRow::render() - * @param ElementInterface $oElement - * @return string - */ - public function render(ElementInterface $oElement, ?string $sLabelPosition = null): string - { - // Retrieve element type - $sElementType = $oElement->getAttribute('type'); - - // Nothing to do for hidden elements which have no messages - if ($sElementType === 'hidden' && !$oElement->getMessages()) { - return parent::render($oElement, $sLabelPosition); - } - - // Retrieve expected layout - $sLayout = $oElement->getOption('twb-layout'); - - // Define label position - if ($sLabelPosition === null) { - $sLabelPosition = $this->getLabelPosition(); - } - - // Partial rendering - if ($this->partial) { - return $this->view->render($this->partial, array( - 'element' => $oElement, - 'label' => $this->renderLabel($oElement), - 'labelAttributes' => $this->labelAttributes, - 'labelPosition' => $sLabelPosition, - 'renderErrors' => $this->renderErrors, - )); - } - - // "has-error" validation state case - if ($oElement->getMessages()) { - //Element have errors - if ($sInputErrorClass = $this->getInputErrorClass()) { - if ($sElementClass = $oElement->getAttribute('class')) { - if (!preg_match('/(\s|^)' . preg_quote($sInputErrorClass, '/') . '(\s|$)/', $sElementClass)) { - $oElement->setAttribute('class', trim($sElementClass . ' ' . $sInputErrorClass)); - } - } else { - $oElement->setAttribute('class', $sInputErrorClass); - } - } - } - - // Render element - $sElementContent = $this->renderElement($oElement, $sLabelPosition); - - // Render form row - switch (true) { - // Checkbox element not in horizontal form - case $sElementType === 'checkbox' && $sLayout !== TwbBundleForm::LAYOUT_HORIZONTAL && !$oElement->getOption('form-group'): - // All "button" elements in inline form - case in_array($sElementType, array('submit', 'button', 'reset'), true) && $sLayout === TwbBundleForm::LAYOUT_INLINE: - return $sElementContent . "\n"; - default: - // Render element into form group - return $this->renderElementFormGroup($sElementContent, $this->getRowClassFromElement($oElement), $oElement->getOption('feedback')); - } - } - - /** - * @param ElementInterface $oElement - * @return string - */ - public function getRowClassFromElement(\Laminas\Form\ElementInterface $oElement) - { - $sRowClass = ''; - if ($sFormGroupSize = $oElement->getOption('twb-form-group-size')) { - $sRowClass = $sFormGroupSize; - } - - // Validation state - if (($sValidationState = $oElement->getOption('validation-state'))) { - $sRowClass .= ' has-' . $sValidationState; - } - if ($oElement->getMessages()) { - $sRowClass .= ' has-error'; - } - if( $oElement->getOption('feedback')) { - $sRowClass .= ' has-feedback'; - } - - // Column size - if (($sColumSize = $oElement->getOption('column-size')) && $oElement->getOption('twb-layout') !== TwbBundleForm::LAYOUT_HORIZONTAL - ) { - $sColumSize = (is_array($sColumSize)) ? $sColumSize : array($sColumSize); - $sRowClass .= implode('', array_map(function($item) { return ' col-' . $item; }, $sColumSize)); - } - - //Additional row class - if ($sAddRowClass = $oElement->getOption('twb-row-class')) { - $sRowClass .= ' ' . $sAddRowClass; - } - return $sRowClass; - } - - /** - * @param string $sElementContent - * @param string $sRowClass - * @param string $sFeedbackElement A feedback element that should be rendered within the element, optional - * - * @return string - * @throws \InvalidArgumentException - */ - public function renderElementFormGroup($sElementContent, $sRowClass, $sFeedbackElement = '' ) - { - if (!is_string($sElementContent)) { - throw new \InvalidArgumentException('Argument "$sElementContent" expects a string, "' . (is_object($sElementContent) ? get_class($sElementContent) : gettype($sElementContent)) . '" given'); - } - if (!is_string($sRowClass)) { - throw new \InvalidArgumentException('Argument "$sRowClass" expects a string, "' . (is_object($sRowClass) ? get_class($sRowClass) : gettype($sRowClass)) . '" given'); - } - if ($sFeedbackElement && !is_string($sFeedbackElement)) { - throw new \InvalidArgumentException('Argument "$sFeedbackElement" expects a string, "' . (is_object($sFeedbackElement) ? get_class($sFeedbackElement) : gettype($sFeedbackElement)) . '" given'); - } - if( $sFeedbackElement ){ - $sElementContent .= ''; - } - return sprintf(static::$formGroupFormat, $sRowClass, $sElementContent) . "\n"; - } - - /** - * Render element's label - * @param ElementInterface $oElement - * @return string - */ - protected function renderLabel(ElementInterface $oElement) - { - if (($sLabel = $oElement->getLabel()) && ($oTranslator = $this->getTranslator())) { - $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); - } - return $sLabel; - } - - /** - * Render element - * @param ElementInterface $oElement - * @param string $sLabelPosition - * @return type - * @throws DomainException - */ - protected function renderElement(ElementInterface $oElement, $sLabelPosition = null) - { - //Retrieve expected layout - $sLayout = $oElement->getOption('twb-layout'); - - // Define label position - if ($sLabelPosition === null) { - $sLabelPosition = $this->getLabelPosition(); - } - - //Render label - $sLabelOpen = $sLabelClose = $sLabelContent = $sElementType = ''; - if ($sLabelContent = $this->renderLabel($oElement)) { - /* - * Multicheckbox elements have to be handled differently - * as the HTML standard does not allow nested labels. - * The semantic way is to group them inside a fieldset - */ - $sElementType = $oElement->getAttribute('type'); - - //Button element is a special case, because label is always rendered inside it - if (($oElement instanceof Button) or ( $oElement instanceof Submit)) { - $sLabelContent = ''; - } else { - $aLabelAttributes = $oElement->getLabelAttributes() ? : $this->labelAttributes; - - //Validation state - if ($oElement->getOption('validation-state') || $oElement->getMessages()) { - if (empty($aLabelAttributes['class'])) { - $aLabelAttributes['class'] = 'control-label'; - } elseif (!preg_match('/(\s|^)control-label(\s|$)/', $aLabelAttributes['class']) && $sElementType !== 'checkbox') { - $aLabelAttributes['class'] = trim($aLabelAttributes['class'] . ' control-label'); - } - } - - $oLabelHelper = $this->getLabelHelper(); - switch ($sLayout) { - //Hide label for "inline" layout - case TwbBundleForm::LAYOUT_INLINE: - if ($sElementType !== 'checkbox') { - if ($sElementType !== 'checkbox') { - if (empty($aLabelAttributes['class']) && empty($oElement->getOption('showLabel'))) { - $aLabelAttributes['class'] = 'sr-only'; - } elseif (empty($oElement->getOption('showLabel')) && !preg_match('/(\s|^)sr-only(\s|$)/', $aLabelAttributes['class'])) { - $aLabelAttributes['class'] = trim($aLabelAttributes['class'] . ' sr-only'); - } - } - } - break; - - case TwbBundleForm::LAYOUT_HORIZONTAL: - if ($sElementType !== 'checkbox') { - if (empty($aLabelAttributes['class'])) { - $aLabelAttributes['class'] = 'control-label'; - } else { - if (!preg_match('/(\s|^)control-label(\s|$)/', $aLabelAttributes['class'])) { - $aLabelAttributes['class'] = trim($aLabelAttributes['class'] . ' control-label'); - } - } - } - break; - } - if ($aLabelAttributes) { - $oElement->setLabelAttributes($aLabelAttributes); - } - - $sLabelOpen = $oLabelHelper->openTag($oElement->getAttribute('id') ? $oElement : $aLabelAttributes); - $sLabelClose = $oLabelHelper->closeTag(); - - // Allow label html escape desable - //$sLabelContent = $this->getEscapeHtmlHelper()->__invoke($sLabelContent); - - if (!$oElement instanceof LabelAwareInterface || !$oElement->getLabelOption('disable_html_escape')) { - $sLabelContent = $this->getEscapeHtmlHelper()->__invoke($sLabelContent); - } - } - } - - //Add required string if element is required - if ($this->requiredFormat && - $oElement->getAttribute('required') && - strpos($this->requiredFormat, $sLabelContent) === false - ) { - $sLabelContent .= $this->requiredFormat; - } - - switch ($sLayout) { - case null: - case TwbBundleForm::LAYOUT_INLINE: - - $sElementContent = $this->getElementHelper()->render($oElement); - - // Checkbox elements are a special case, element is already rendered into label - if ($sElementType === 'checkbox') { - $sElementContent = sprintf(static::$checkboxFormat, $sElementContent); - } else { - if ($sLabelPosition === self::LABEL_PREPEND) { - $sElementContent = $sLabelOpen . $sLabelContent . $sLabelClose . $sElementContent; - } else { - $sElementContent = $sElementContent . $sLabelOpen . $sLabelContent . $sLabelClose; - } - } - - //Render help block - $sElementContent .= $this->renderHelpBlock($oElement); - - //Render errors - if ($this->renderErrors) { - $sElementContent .= $this->getElementErrorsHelper()->render($oElement); - } - - return $sElementContent; - - case TwbBundleForm::LAYOUT_HORIZONTAL: - $sElementContent = $this->getElementHelper()->render($oElement) . $this->renderHelpBlock($oElement); - - //Render errors - if ($this->renderErrors) { - $sElementContent .= $this->getElementErrorsHelper()->render($oElement); - } - - $sClass = ''; - - //Column size - if ($sColumSize = $oElement->getOption('column-size')) { - $sClass .= ' col-' . $sColumSize; - } - - // Checkbox elements are a special case, element is rendered into label - if ($sElementType === 'checkbox') { - return sprintf( - static::$horizontalLayoutFormat, $sClass, sprintf(static::$checkboxFormat, $sElementContent) - ); - } - - if ($sLabelPosition === self::LABEL_PREPEND) { - return $sLabelOpen . $sLabelContent . $sLabelClose . sprintf( - static::$horizontalLayoutFormat, $sClass, $sElementContent - ); - } else { - return sprintf( - static::$horizontalLayoutFormat, $sClass, $sElementContent - ) . $sLabelOpen . $sLabelContent . $sLabelClose; - } - } - throw new DomainException('Layout "' . $sLayout . '" is not valid'); - } - - /** - * Render element's help block - * @param ElementInterface $oElement - * @return string - */ - protected function renderHelpBlock(ElementInterface $oElement) - { - if ($sHelpBlock = $oElement->getOption('help-block')) { - if ($oTranslator = $this->getTranslator()) { - $sHelpBlock = $oTranslator->translate($sHelpBlock, $this->getTranslatorTextDomain()); - } - $sHelpBlockString = strip_tags($sHelpBlock); - if ($sHelpBlock === $sHelpBlockString) { - $sHelpBlock = $this->getEscapeHtmlHelper()->__invoke($sHelpBlock); - } - return sprintf(static::$helpBlockFormat, $sHelpBlock); - } else { - return ''; - } - } -} +%s
    '; + + /** + * @var string + */ + protected static $horizontalLayoutFormat = '
    %s
    '; + + /** + * @var string + */ + protected static $checkboxFormat = '
    %s
    '; + + /** + * @var string + */ + protected static $helpBlockFormat = '

    %s

    '; + + /** + * The class that is added to element that have errors + * @var string + */ + protected $inputErrorClass = ''; + + /** + * @var string + */ + protected $requiredFormat = null; + + /** + * @see FormRow::render() + * @param ElementInterface $oElement + * @return string + */ + public function render(ElementInterface $oElement, ?string $sLabelPosition = null): string + { + // Retrieve element type + $sElementType = $oElement->getAttribute('type'); + + // Nothing to do for hidden elements which have no messages + if ($sElementType === 'hidden' && !$oElement->getMessages()) { + return parent::render($oElement, $sLabelPosition); + } + + // Retrieve expected layout + $sLayout = $oElement->getOption('twb-layout'); + + // Define label position + if ($sLabelPosition === null) { + $sLabelPosition = $this->getLabelPosition(); + } + + // Partial rendering + if ($this->partial) { + return $this->view->render($this->partial, [ + 'element' => $oElement, + 'label' => $this->renderLabel($oElement), + 'labelAttributes' => $this->labelAttributes, + 'labelPosition' => $sLabelPosition, + 'renderErrors' => $this->renderErrors, + ]); + } + + // "has-error" validation state case + if ($oElement->getMessages()) { + //Element have errors + if ($sInputErrorClass = $this->getInputErrorClass()) { + if ($sElementClass = $oElement->getAttribute('class')) { + if (!preg_match('/(\s|^)' . preg_quote($sInputErrorClass, '/') . '(\s|$)/', $sElementClass)) { + $oElement->setAttribute('class', trim($sElementClass . ' ' . $sInputErrorClass)); + } + } else { + $oElement->setAttribute('class', $sInputErrorClass); + } + } + } + + // Render element + $sElementContent = $this->renderElement($oElement, $sLabelPosition); + + // Render form row + switch (true) { + // Checkbox element not in horizontal form + case $sElementType === 'checkbox' && $sLayout !== TwbBundleForm::LAYOUT_HORIZONTAL && !$oElement->getOption('form-group'): + // All "button" elements in inline form + case in_array($sElementType, ['submit', 'button', 'reset'], true) && $sLayout === TwbBundleForm::LAYOUT_INLINE: + return $sElementContent . "\n"; + default: + // Render element into form group + return $this->renderElementFormGroup($sElementContent, $this->getRowClassFromElement($oElement), $oElement->getOption('feedback')); + } + } + + /** + * @param ElementInterface $oElement + * @return string + */ + public function getRowClassFromElement(\Laminas\Form\ElementInterface $oElement) + { + $sRowClass = ''; + if ($sFormGroupSize = $oElement->getOption('twb-form-group-size')) { + $sRowClass = $sFormGroupSize; + } + + // Validation state + if (($sValidationState = $oElement->getOption('validation-state'))) { + $sRowClass .= ' has-' . $sValidationState; + } + if ($oElement->getMessages()) { + $sRowClass .= ' has-error'; + } + if($oElement->getOption('feedback')) { + $sRowClass .= ' has-feedback'; + } + + // Column size + if (($sColumSize = $oElement->getOption('column-size')) && $oElement->getOption('twb-layout') !== TwbBundleForm::LAYOUT_HORIZONTAL + ) { + $sColumSize = (is_array($sColumSize)) ? $sColumSize : [$sColumSize]; + $sRowClass .= implode('', array_map(function ($item) { return ' col-' . $item; }, $sColumSize)); + } + + //Additional row class + if ($sAddRowClass = $oElement->getOption('twb-row-class')) { + $sRowClass .= ' ' . $sAddRowClass; + } + return $sRowClass; + } + + /** + * @param string $sElementContent + * @param string $sRowClass + * @param string $sFeedbackElement A feedback element that should be rendered within the element, optional + * + * @return string + * @throws \InvalidArgumentException + */ + public function renderElementFormGroup($sElementContent, $sRowClass, $sFeedbackElement = '') + { + if (!is_string($sElementContent)) { + throw new \InvalidArgumentException('Argument "$sElementContent" expects a string, "' . (is_object($sElementContent) ? get_class($sElementContent) : gettype($sElementContent)) . '" given'); + } + if (!is_string($sRowClass)) { + throw new \InvalidArgumentException('Argument "$sRowClass" expects a string, "' . (is_object($sRowClass) ? get_class($sRowClass) : gettype($sRowClass)) . '" given'); + } + if ($sFeedbackElement && !is_string($sFeedbackElement)) { + throw new \InvalidArgumentException('Argument "$sFeedbackElement" expects a string, "' . (is_object($sFeedbackElement) ? get_class($sFeedbackElement) : gettype($sFeedbackElement)) . '" given'); + } + if($sFeedbackElement) { + $sElementContent .= ''; + } + return sprintf(static::$formGroupFormat, $sRowClass, $sElementContent) . "\n"; + } + + /** + * Render element's label + * @param ElementInterface $oElement + * @return string + */ + protected function renderLabel(ElementInterface $oElement) + { + if (($sLabel = $oElement->getLabel()) && ($oTranslator = $this->getTranslator())) { + $sLabel = $oTranslator->translate($sLabel, $this->getTranslatorTextDomain()); + } + return $sLabel; + } + + /** + * Render element + * @param ElementInterface $oElement + * @param string $sLabelPosition + * @return type + * @throws DomainException + */ + protected function renderElement(ElementInterface $oElement, $sLabelPosition = null) + { + //Retrieve expected layout + $sLayout = $oElement->getOption('twb-layout'); + + // Define label position + if ($sLabelPosition === null) { + $sLabelPosition = $this->getLabelPosition(); + } + + //Render label + $sLabelOpen = $sLabelClose = $sLabelContent = $sElementType = ''; + if ($sLabelContent = $this->renderLabel($oElement)) { + /* + * Multicheckbox elements have to be handled differently + * as the HTML standard does not allow nested labels. + * The semantic way is to group them inside a fieldset + */ + $sElementType = $oElement->getAttribute('type'); + + //Button element is a special case, because label is always rendered inside it + if (($oElement instanceof Button) or ($oElement instanceof Submit)) { + $sLabelContent = ''; + } else { + $aLabelAttributes = $oElement->getLabelAttributes() ? : $this->labelAttributes; + + //Validation state + if ($oElement->getOption('validation-state') || $oElement->getMessages()) { + if (empty($aLabelAttributes['class'])) { + $aLabelAttributes['class'] = 'control-label'; + } elseif (!preg_match('/(\s|^)control-label(\s|$)/', $aLabelAttributes['class']) && $sElementType !== 'checkbox') { + $aLabelAttributes['class'] = trim($aLabelAttributes['class'] . ' control-label'); + } + } + + $oLabelHelper = $this->getLabelHelper(); + switch ($sLayout) { + //Hide label for "inline" layout + case TwbBundleForm::LAYOUT_INLINE: + if ($sElementType !== 'checkbox') { + if ($sElementType !== 'checkbox') { + if (empty($aLabelAttributes['class']) && empty($oElement->getOption('showLabel'))) { + $aLabelAttributes['class'] = 'sr-only'; + } elseif (empty($oElement->getOption('showLabel')) && !preg_match('/(\s|^)sr-only(\s|$)/', $aLabelAttributes['class'])) { + $aLabelAttributes['class'] = trim($aLabelAttributes['class'] . ' sr-only'); + } + } + } + break; + + case TwbBundleForm::LAYOUT_HORIZONTAL: + if ($sElementType !== 'checkbox') { + if (empty($aLabelAttributes['class'])) { + $aLabelAttributes['class'] = 'control-label'; + } else { + if (!preg_match('/(\s|^)control-label(\s|$)/', $aLabelAttributes['class'])) { + $aLabelAttributes['class'] = trim($aLabelAttributes['class'] . ' control-label'); + } + } + } + break; + } + if ($aLabelAttributes) { + $oElement->setLabelAttributes($aLabelAttributes); + } + + $sLabelOpen = $oLabelHelper->openTag($oElement->getAttribute('id') ? $oElement : $aLabelAttributes); + $sLabelClose = $oLabelHelper->closeTag(); + + // Allow label html escape desable + //$sLabelContent = $this->getEscapeHtmlHelper()->__invoke($sLabelContent); + + if (!$oElement instanceof LabelAwareInterface || !$oElement->getLabelOption('disable_html_escape')) { + $sLabelContent = $this->getEscapeHtmlHelper()->__invoke($sLabelContent); + } + } + } + + //Add required string if element is required + if ($this->requiredFormat && + $oElement->getAttribute('required') && + strpos($this->requiredFormat, $sLabelContent) === false + ) { + $sLabelContent .= $this->requiredFormat; + } + + switch ($sLayout) { + case null: + case TwbBundleForm::LAYOUT_INLINE: + + $sElementContent = $this->getElementHelper()->render($oElement); + + // Checkbox elements are a special case, element is already rendered into label + if ($sElementType === 'checkbox') { + $sElementContent = sprintf(static::$checkboxFormat, $sElementContent); + } else { + if ($sLabelPosition === self::LABEL_PREPEND) { + $sElementContent = $sLabelOpen . $sLabelContent . $sLabelClose . $sElementContent; + } else { + $sElementContent = $sElementContent . $sLabelOpen . $sLabelContent . $sLabelClose; + } + } + + //Render help block + $sElementContent .= $this->renderHelpBlock($oElement); + + //Render errors + if ($this->renderErrors) { + $sElementContent .= $this->getElementErrorsHelper()->render($oElement); + } + + return $sElementContent; + + case TwbBundleForm::LAYOUT_HORIZONTAL: + $sElementContent = $this->getElementHelper()->render($oElement) . $this->renderHelpBlock($oElement); + + //Render errors + if ($this->renderErrors) { + $sElementContent .= $this->getElementErrorsHelper()->render($oElement); + } + + $sClass = ''; + + //Column size + if ($sColumSize = $oElement->getOption('column-size')) { + $sClass .= ' col-' . $sColumSize; + } + + // Checkbox elements are a special case, element is rendered into label + if ($sElementType === 'checkbox') { + return sprintf( + static::$horizontalLayoutFormat, + $sClass, + sprintf(static::$checkboxFormat, $sElementContent) + ); + } + + if ($sLabelPosition === self::LABEL_PREPEND) { + return $sLabelOpen . $sLabelContent . $sLabelClose . sprintf( + static::$horizontalLayoutFormat, + $sClass, + $sElementContent + ); + } else { + return sprintf( + static::$horizontalLayoutFormat, + $sClass, + $sElementContent + ) . $sLabelOpen . $sLabelContent . $sLabelClose; + } + } + throw new DomainException('Layout "' . $sLayout . '" is not valid'); + } + + /** + * Render element's help block + * @param ElementInterface $oElement + * @return string + */ + protected function renderHelpBlock(ElementInterface $oElement) + { + if ($sHelpBlock = $oElement->getOption('help-block')) { + if ($oTranslator = $this->getTranslator()) { + $sHelpBlock = $oTranslator->translate($sHelpBlock, $this->getTranslatorTextDomain()); + } + $sHelpBlockString = strip_tags($sHelpBlock); + if ($sHelpBlock === $sHelpBlockString) { + $sHelpBlock = $this->getEscapeHtmlHelper()->__invoke($sHelpBlock); + } + return sprintf(static::$helpBlockFormat, $sHelpBlock); + } else { + return ''; + } + } +} diff --git a/src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php b/src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php index 4433672..12eb7e1 100644 --- a/src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php +++ b/src/TwbBundle/Form/View/Helper/TwbBundleFormStatic.php @@ -1,40 +1,40 @@ -%s

    '; - - /** - * Invoke helper as functor - * - * Proxies to {@link render()}. - * - * @param ElementInterface|null $element - * @return string|TwbBundleFormStatic - */ - public function __invoke(ElementInterface $element = null) - { - if (!$element) { - return $this; - } - - return $this->render($element); - } - - /** - * @see \Laminas\Form\View\Helper\AbstractHelper::render() - * @param ElementInterface $oElement - * @return string - */ - public function render(ElementInterface $oElement) - { - return sprintf(static::$staticFormat, $oElement->getValue()); - } -} +%s

    '; + + /** + * Invoke helper as functor + * + * Proxies to {@link render()}. + * + * @param ElementInterface|null $element + * @return string|TwbBundleFormStatic + */ + public function __invoke(ElementInterface $element = null) + { + if (!$element) { + return $this; + } + + return $this->render($element); + } + + /** + * @see \Laminas\Form\View\Helper\AbstractHelper::render() + * @param ElementInterface $oElement + * @return string + */ + public function render(ElementInterface $oElement) + { + return sprintf(static::$staticFormat, $oElement->getValue()); + } +} diff --git a/src/TwbBundle/Module.php b/src/TwbBundle/Module.php index 8a656a6..e4546c1 100644 --- a/src/TwbBundle/Module.php +++ b/src/TwbBundle/Module.php @@ -1,11 +1,13 @@ getServiceLocator() ?: $container; } -} \ No newline at end of file +} diff --git a/src/TwbBundle/Options/Factory/ModuleOptionsFactory.php b/src/TwbBundle/Options/Factory/ModuleOptionsFactory.php index 8dda7a2..82145a9 100644 --- a/src/TwbBundle/Options/Factory/ModuleOptionsFactory.php +++ b/src/TwbBundle/Options/Factory/ModuleOptionsFactory.php @@ -2,23 +2,14 @@ namespace TwbBundle\Options\Factory; use Laminas\ServiceManager\Factory\FactoryInterface; -use Laminas\ServiceManager\ServiceLocatorInterface; use TwbBundle\Options\ModuleOptions; -use Interop\Container\ContainerInterface; +use Psr\Container\ContainerInterface; class ModuleOptionsFactory implements FactoryInterface { - - public function createService(ServiceLocatorInterface $serviceLocator) - { - $config = $serviceLocator->get('config'); - $options = $config['twbbundle']; - return new ModuleOptions($options); - } - public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $config = $container->get('config'); + $config = $container->get('config'); $options = $config['twbbundle']; return new ModuleOptions($options); } diff --git a/src/TwbBundle/Options/ModuleOptions.php b/src/TwbBundle/Options/ModuleOptions.php index a1e28e3..3fa023d 100644 --- a/src/TwbBundle/Options/ModuleOptions.php +++ b/src/TwbBundle/Options/ModuleOptions.php @@ -1,54 +1,54 @@ -ignoredViewHelpers; - } - public function setIgnoredViewHelpers($ignoredViewHelpers) - { - $this->ignoredViewHelpers = $ignoredViewHelpers; - } - - public function getClassMap() - { - return $this->classMap; - } - public function setClassMap($classMap) - { - $this->classMap = $classMap; - } - - public function getTypeMap() - { - return $this->typeMap; - } - public function setTypeMap($typeMap) - { - $this->typeMap = $typeMap; - } -} +ignoredViewHelpers; + } + public function setIgnoredViewHelpers($ignoredViewHelpers) + { + $this->ignoredViewHelpers = $ignoredViewHelpers; + } + + public function getClassMap() + { + return $this->classMap; + } + public function setClassMap($classMap) + { + $this->classMap = $classMap; + } + + public function getTypeMap() + { + return $this->typeMap; + } + public function setTypeMap($typeMap) + { + $this->typeMap = $typeMap; + } +} diff --git a/src/TwbBundle/View/Helper/Navigation.php b/src/TwbBundle/View/Helper/Navigation.php index e34895f..5413a45 100644 --- a/src/TwbBundle/View/Helper/Navigation.php +++ b/src/TwbBundle/View/Helper/Navigation.php @@ -2,7 +2,6 @@ namespace TwbBundle\View\Helper; - use Laminas\View\Helper\Navigation as ZendNavigationHelper; class Navigation extends ZendNavigationHelper @@ -23,4 +22,4 @@ public function getPluginManager() return $this->plugins; } -} \ No newline at end of file +} diff --git a/src/TwbBundle/View/Helper/Navigation/PluginManager.php b/src/TwbBundle/View/Helper/Navigation/PluginManager.php index a99618a..5e97a0e 100644 --- a/src/TwbBundle/View/Helper/Navigation/PluginManager.php +++ b/src/TwbBundle/View/Helper/Navigation/PluginManager.php @@ -2,7 +2,6 @@ namespace TwbBundle\View\Helper\Navigation; - use Laminas\ServiceManager\Factory\InvokableFactory; class PluginManager extends \Laminas\View\Helper\Navigation\PluginManager @@ -16,4 +15,4 @@ public function __construct($configOrContainerInstance = null, array $v3config = parent::__construct($configOrContainerInstance, $v3config); } -} \ No newline at end of file +} diff --git a/src/TwbBundle/View/Helper/Navigation/TwbBundleMenu.php b/src/TwbBundle/View/Helper/Navigation/TwbBundleMenu.php index 4360019..2c3ba80 100644 --- a/src/TwbBundle/View/Helper/Navigation/TwbBundleMenu.php +++ b/src/TwbBundle/View/Helper/Navigation/TwbBundleMenu.php @@ -144,14 +144,14 @@ protected function renderDeepestMenu( } elseif (!$active['page']->hasPages()) { // found pages has no children; render siblings $active['page'] = $active['page']->getParent(); - } elseif (is_int($maxDepth) && $active['depth'] +1 > $maxDepth) { + } elseif (is_int($maxDepth) && $active['depth'] + 1 > $maxDepth) { // children are below max depth; render siblings $active['page'] = $active['page']->getParent(); } $ulClass = $ulClass ? ' class="' . $ulClass . '"' : ''; - $ulId = ($this->getUlId()) ? ' id="' . $this->getUlId() . '"' : ''; - $html = $indent . '' . PHP_EOL; + $ulId = ($this->getUlId()) ? ' id="' . $this->getUlId() . '"' : ''; + $html = $indent . '' . PHP_EOL; foreach ($active['page'] as $subPage) { if (!$this->accept($subPage)) { @@ -159,7 +159,7 @@ protected function renderDeepestMenu( } // render li tag and page - $liClasses = array(); + $liClasses = []; // Is page active? if ($subPage->isActive(true)) { $liClasses[] = 'active'; @@ -214,12 +214,15 @@ protected function renderNormalMenu( $foundPage = $found['page']; $foundDepth = $found['depth']; } else { - $foundPage = null; + $foundPage = null; + $foundDepth = 0; } // create iterator - $iterator = new RecursiveIteratorIterator($container, - RecursiveIteratorIterator::SELF_FIRST); + $iterator = new RecursiveIteratorIterator( + $container, + RecursiveIteratorIterator::SELF_FIRST + ); if (is_int($maxDepth)) { $iterator->setMaxDepth($maxDepth); } @@ -227,7 +230,7 @@ protected function renderNormalMenu( // iterate container $prevDepth = -1; foreach ($iterator as $page) { - $depth = $iterator->getDepth(); + $depth = $iterator->getDepth(); $isActive = $page->isActive(true); if ($depth < $minDepth || !$this->accept($page)) { // page is below minDepth or not accepted by acl/visibility @@ -261,7 +264,7 @@ protected function renderNormalMenu( if ($depth > $prevDepth) { // start new ul tag - if ($ulClass && $depth == 0) { + if ($ulClass && $depth == 0) { $ulClass = ' class="' . $ulClass . '"'; } elseif ($page->getParent()) { $ulClass = ' class="' . $this->getSubUlClass() . '"'; @@ -291,7 +294,7 @@ protected function renderNormalMenu( } // render li tag and page - $liClasses = array(); + $liClasses = []; $liClasses[] = $this->getLiClass(); // Is page active? if ($isActive) { @@ -299,7 +302,7 @@ protected function renderNormalMenu( } // Is page parent? if ($page->hasPages() && (!isset($maxDepth) || $depth < $maxDepth)) { - $liClasses[] = ($depth == 0) ? 'dropdown': 'dropdown-submenu'; + $liClasses[] = ($depth == 0) ? 'dropdown': 'dropdown-submenu'; $page->isDropdown = true; if ($depth > 0) { @@ -310,7 +313,7 @@ protected function renderNormalMenu( if ($addClassToListItem && $page->getClass()) { $liClasses[] = $page->getClass(); } - $liClass = empty($liClasses) ? '' : ' class="' . implode(' ', $liClasses) . '"'; + $liClass = ' class="' . implode(' ', $liClasses) . '"'; $html .= $myIndent . ' ' . PHP_EOL . $myIndent . ' ' . $this->htmlify($page, $escapeLabels, $addClassToListItem) . PHP_EOL; @@ -321,8 +324,8 @@ protected function renderNormalMenu( if ($html) { // done iterating container; close open ul/li tags - for ($i = $prevDepth+1; $i > 0; $i--) { - $myIndent = $indent . str_repeat(' ', $i-1); + for ($i = $prevDepth + 1; $i > 0; $i--) { + $myIndent = $indent . str_repeat(' ', $i - 1); $html .= $myIndent . '
  • ' . PHP_EOL . $myIndent . '' . PHP_EOL; } @@ -361,21 +364,21 @@ public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToList } // get attribs for element - $element = 'a'; + $element = 'a'; $extended = ''; - $attribs = array( + $attribs = [ 'id' => $page->getId(), 'title' => $title, 'href' => '#', - ); + ]; - $class = array(); + $class = []; if ($addClassToListItem === false) { $class[] = $page->getClass(); } if ($page->isDropdown) { $attribs['data-toggle'] = 'dropdown'; - $class[] = 'dropdown-toggle'; + $class[] = 'dropdown-toggle'; if (!$page->isSubmenu && $this->getUseCaret()) { $extended = ''; @@ -388,7 +391,7 @@ public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToList // does page have a href? $href = $page->getHref(); if ($href) { - $attribs['href'] = $href; + $attribs['href'] = $href; $attribs['target'] = $page->getTarget(); } @@ -406,4 +409,4 @@ public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToList return $html; } -} \ No newline at end of file +} diff --git a/src/TwbBundle/View/Helper/TwbBundleAlert.php b/src/TwbBundle/View/Helper/TwbBundleAlert.php index 12489a7..883d7da 100644 --- a/src/TwbBundle/View/Helper/TwbBundleAlert.php +++ b/src/TwbBundle/View/Helper/TwbBundleAlert.php @@ -1,85 +1,85 @@ -%s'; - - /** - * @var string - */ - protected static $dismissButtonFormat = ''; - - /** - * Invoke helper as functor, proxies to {@link render()}. - * @param string $sAlertMessage - * @param string|array $aAlertAttributes : [optionnal] if string, alert class - * @param boolean $bDismissable - * @return string|TwbBundleAlert - */ - public function __invoke($sAlertMessage = null, $aAlertAttributes = null, $bDismissable = false) - { - if ($sAlertMessage === null) { - return $this; - } - if ($sAlertMessage === '' || $sAlertMessage === false) { - return ''; - } - return $this->render($sAlertMessage, $aAlertAttributes, $bDismissable); - } - - /** - * Retrieve alert markup - * @param string $sAlertMessage - * @param string|array $aAlertAttributes : [optionnal] if string, alert class - * @param boolean $bDismissable - * @throws InvalidArgumentException - * @return string - */ - public function render($sAlertMessage, $aAlertAttributes = null, $bDismissable = false) - { - if (!is_scalar($sAlertMessage)) { - throw new InvalidArgumentException('Alert message expects a scalar value, "' . gettype($sAlertMessage) . '" given'); - } - - if (empty($aAlertAttributes)) { - $aAlertAttributes = array('class' => 'alert'); - } elseif (is_string($aAlertAttributes)) { - $aAlertAttributes = array('class' => $aAlertAttributes); - } elseif (!is_array($aAlertAttributes)) { - throw new InvalidArgumentException('Alert attributes expects a string or an array, "' . gettype($aAlertAttributes) . '" given'); - } elseif (empty($aAlertAttributes['class'])) { - throw new InvalidArgumentException('Alert "class" attribute is empty'); - } elseif (!is_string($aAlertAttributes['class'])) { - throw new InvalidArgumentException('Alert "class" attribute expects string, "' . gettype($aAlertAttributes) . '" given'); - } - - if (!preg_match('/(\s|^)alert(\s|$)/', $aAlertAttributes['class'])) { - $aAlertAttributes['class'] .= ' alert'; - } - - if (null !== ($oTranslator = $this->getTranslator())) { - $sAlertMessage = $oTranslator->translate($sAlertMessage, $this->getTranslatorTextDomain()); - } - - if ($bDismissable) { - $sAlertMessage = static::$dismissButtonFormat . $sAlertMessage; - if (!preg_match('/(\s|^)alert-dismissable(\s|$)/', $aAlertAttributes['class'])) { - $aAlertAttributes['class'] .= ' alert-dismissable'; - } - } - - return sprintf( - static::$alertFormat, - $this->createAttributesString($aAlertAttributes), - $sAlertMessage - ); - } -} +%s'; + + /** + * @var string + */ + protected static $dismissButtonFormat = ''; + + /** + * Invoke helper as functor, proxies to {@link render()}. + * @param string $sAlertMessage + * @param string|array $aAlertAttributes : [optionnal] if string, alert class + * @param boolean $bDismissable + * @return string|TwbBundleAlert + */ + public function __invoke($sAlertMessage = null, $aAlertAttributes = null, $bDismissable = false) + { + if ($sAlertMessage === null) { + return $this; + } + if ($sAlertMessage === '' || $sAlertMessage === false) { + return ''; + } + return $this->render($sAlertMessage, $aAlertAttributes, $bDismissable); + } + + /** + * Retrieve alert markup + * @param string $sAlertMessage + * @param string|array $aAlertAttributes : [optionnal] if string, alert class + * @param boolean $bDismissable + * @throws InvalidArgumentException + * @return string + */ + public function render($sAlertMessage, $aAlertAttributes = null, $bDismissable = false) + { + if (!is_scalar($sAlertMessage)) { + throw new InvalidArgumentException('Alert message expects a scalar value, "' . gettype($sAlertMessage) . '" given'); + } + + if (empty($aAlertAttributes)) { + $aAlertAttributes = ['class' => 'alert']; + } elseif (is_string($aAlertAttributes)) { + $aAlertAttributes = ['class' => $aAlertAttributes]; + } elseif (!is_array($aAlertAttributes)) { + throw new InvalidArgumentException('Alert attributes expects a string or an array, "' . gettype($aAlertAttributes) . '" given'); + } elseif (empty($aAlertAttributes['class'])) { + throw new InvalidArgumentException('Alert "class" attribute is empty'); + } elseif (!is_string($aAlertAttributes['class'])) { + throw new InvalidArgumentException('Alert "class" attribute expects string, "' . gettype($aAlertAttributes) . '" given'); + } + + if (!preg_match('/(\s|^)alert(\s|$)/', $aAlertAttributes['class'])) { + $aAlertAttributes['class'] .= ' alert'; + } + + if (null !== ($oTranslator = $this->getTranslator())) { + $sAlertMessage = $oTranslator->translate($sAlertMessage, $this->getTranslatorTextDomain()); + } + + if ($bDismissable) { + $sAlertMessage = static::$dismissButtonFormat . $sAlertMessage; + if (!preg_match('/(\s|^)alert-dismissable(\s|$)/', $aAlertAttributes['class'])) { + $aAlertAttributes['class'] .= ' alert-dismissable'; + } + } + + return sprintf( + static::$alertFormat, + $this->createAttributesString($aAlertAttributes), + $sAlertMessage + ); + } +} diff --git a/src/TwbBundle/View/Helper/TwbBundleBadge.php b/src/TwbBundle/View/Helper/TwbBundleBadge.php index 7925fa1..31a1005 100644 --- a/src/TwbBundle/View/Helper/TwbBundleBadge.php +++ b/src/TwbBundle/View/Helper/TwbBundleBadge.php @@ -1,65 +1,65 @@ -%s'; - - /** - * Invoke helper as functor, proxies to {@link render()}. - * @param string $sBadgeMessage - * @param array $aBadgeAttributes : [optionnal] - * @return string|TwbBundleBadge - */ - public function __invoke($sBadgeMessage = null, array $aBadgeAttributes = null) - { - if ($sBadgeMessage === null) { - return $this; - } - return $this->render($sBadgeMessage, $aBadgeAttributes); - } - - /** - * Retrieve badge markup - * @param string $sBadgeMessage - * @param array $aBadgeAttributes : [optionnal] - * @throws InvalidArgumentException - * @return string - */ - public function render($sBadgeMessage, array $aBadgeAttributes = null) - { - if (!is_scalar($sBadgeMessage)) { - throw new InvalidArgumentException(sprintf( - 'Badge message expects a scalar value, "%s" given', - is_object($sBadgeMessage) ? get_class($sBadgeMessage) : gettype($sBadgeMessage) - )); - } - - if (empty($aBadgeAttributes)) { - $aBadgeAttributes = array('class' => 'badge'); - } else { - if (empty($aBadgeAttributes['class'])) { - $aBadgeAttributes['class'] = 'badge'; - } elseif (!preg_match('/(\s|^)badge(\s|$)/', $aBadgeAttributes['class'])) { - $aBadgeAttributes['class'] .= ' badge'; - } - } - - if (null !== ($oTranslator = $this->getTranslator())) { - $sBadgeMessage = $oTranslator->translate($sBadgeMessage, $this->getTranslatorTextDomain()); - } - - return sprintf( - static::$badgeFormat, - $this->createAttributesString($aBadgeAttributes), - $sBadgeMessage - ); - } -} +%s'; + + /** + * Invoke helper as functor, proxies to {@link render()}. + * @param string $sBadgeMessage + * @param array $aBadgeAttributes : [optionnal] + * @return string|TwbBundleBadge + */ + public function __invoke($sBadgeMessage = null, array $aBadgeAttributes = null) + { + if ($sBadgeMessage === null) { + return $this; + } + return $this->render($sBadgeMessage, $aBadgeAttributes); + } + + /** + * Retrieve badge markup + * @param string $sBadgeMessage + * @param array $aBadgeAttributes : [optionnal] + * @throws InvalidArgumentException + * @return string + */ + public function render($sBadgeMessage, array $aBadgeAttributes = null) + { + if (!is_scalar($sBadgeMessage)) { + throw new InvalidArgumentException(sprintf( + 'Badge message expects a scalar value, "%s" given', + is_object($sBadgeMessage) ? get_class($sBadgeMessage) : gettype($sBadgeMessage) + )); + } + + if (empty($aBadgeAttributes)) { + $aBadgeAttributes = ['class' => 'badge']; + } else { + if (empty($aBadgeAttributes['class'])) { + $aBadgeAttributes['class'] = 'badge'; + } elseif (!preg_match('/(\s|^)badge(\s|$)/', $aBadgeAttributes['class'])) { + $aBadgeAttributes['class'] .= ' badge'; + } + } + + if (null !== ($oTranslator = $this->getTranslator())) { + $sBadgeMessage = $oTranslator->translate($sBadgeMessage, $this->getTranslatorTextDomain()); + } + + return sprintf( + static::$badgeFormat, + $this->createAttributesString($aBadgeAttributes), + $sBadgeMessage + ); + } +} diff --git a/src/TwbBundle/View/Helper/TwbBundleButtonGroup.php b/src/TwbBundle/View/Helper/TwbBundleButtonGroup.php index e828fba..99f6f9f 100644 --- a/src/TwbBundle/View/Helper/TwbBundleButtonGroup.php +++ b/src/TwbBundle/View/Helper/TwbBundleButtonGroup.php @@ -1,120 +1,122 @@ -%s'; - - /** - * @var string - */ - protected static $buttonGroupJustifiedFormat = '
    %s
    '; - - /** - * @var TwbBundleFormElement - */ - protected $formElementHelper; - - /** - * @param array $aButtons - * @param array $aButtonGroupOptions - * @return TwbBundleButtonGroup|string - */ - public function __invoke(array $aButtons = null, array $aButtonGroupOptions = null) - { - return $aButtons ? $this->render($aButtons, $aButtonGroupOptions) : $this; - } - - /** - * Render button groups markup - * @param array $aButtons - * @param array $aButtonGroupOptions - * @throws LogicException - * @return string - */ - public function render(array $aButtons, array $aButtonGroupOptions = null) - { - /* - * Button group container attributes - */ - if (empty($aButtonGroupOptions['attributes'])) { - $aButtonGroupOptions['attributes'] = array('class' => 'btn-group'); - } else { - if (!is_array($aButtonGroupOptions['attributes'])) { - throw new LogicException('"attributes" option expects an array, "' . gettype($aButtonGroupOptions['attributes']) . '" given'); - } - if (empty($aButtonGroupOptions['attributes']['class'])) { - $aButtonGroupOptions['attributes']['class'] = 'btn-group'; - } elseif (!preg_match('/(\s|^)(?:btn-group|btn-group-vertical)(\s|$)/', $aButtonGroupOptions['attributes']['class'])) { - $aButtonGroupOptions['attributes']['class'] .= ' btn-group'; - } - } - - /* - * Render button group - */ - return sprintf( - static::$buttonGroupContainerFormat, - //Container attributes - $this->createAttributesString($aButtonGroupOptions['attributes']), - //Buttons - $this->renderButtons( - $aButtons, - strpos($aButtonGroupOptions['attributes']['class'], 'btn-group-justified') !== false - ) - ); - } - - /** - * Render buttons markup - * @param array $aButtons - * @return string - */ - protected function renderButtons(array $aButtons, $bJustified = false) - { - $sMarkup = ''; - foreach ($aButtons as $oButton) { - if (is_array($oButton) || - ($oButton instanceof Traversable && - !($oButton instanceof ElementInterface)) - ) { - $oFactory = new Factory(); - $oButton = $oFactory->create($oButton); - } elseif (!($oButton instanceof ElementInterface)) { - throw new LogicException(sprintf( - 'Button expects an instanceof Laminas\Form\ElementInterface or an array / Traversable, "%s" given', is_object($oButton) ? get_class($oButton) : gettype($oButton) - )); - } - - $sButtonMarkup = $this->getFormElementHelper()->__invoke($oButton); - - $sMarkup .= $bJustified ? sprintf(static::$buttonGroupJustifiedFormat, $sButtonMarkup) : $sButtonMarkup; - } - return $sMarkup; - } - - /** - * @return TwbBundleFormElement - */ - public function getFormElementHelper() - { - if ($this->formElementHelper instanceof TwbBundleFormElement) { - return $this->formElementHelper; - } - if (method_exists($this->view, 'plugin')) { - return $this->formElementHelper = $this->view->plugin('form_element'); - } - - return $this->formElementHelper = new TwbBundleFormElement(); - } -} +%s'; + + /** + * @var string + */ + protected static $buttonGroupJustifiedFormat = '
    %s
    '; + + /** + * @var TwbBundleFormElement + */ + protected $formElementHelper; + + /** + * @param array $aButtons + * @param array $aButtonGroupOptions + * @return TwbBundleButtonGroup|string + */ + public function __invoke(array $aButtons = null, array $aButtonGroupOptions = null) + { + return $aButtons ? $this->render($aButtons, $aButtonGroupOptions) : $this; + } + + /** + * Render button groups markup + * @param array $aButtons + * @param array $aButtonGroupOptions + * @throws LogicException + * @return string + */ + public function render(array $aButtons, array $aButtonGroupOptions = null) + { + /* + * Button group container attributes + */ + if (empty($aButtonGroupOptions['attributes'])) { + $aButtonGroupOptions['attributes'] = ['class' => 'btn-group']; + } else { + if (!is_array($aButtonGroupOptions['attributes'])) { + throw new LogicException('"attributes" option expects an array, "' . gettype($aButtonGroupOptions['attributes']) . '" given'); + } + if (empty($aButtonGroupOptions['attributes']['class'])) { + $aButtonGroupOptions['attributes']['class'] = 'btn-group'; + } elseif (!preg_match('/(\s|^)(?:btn-group|btn-group-vertical)(\s|$)/', $aButtonGroupOptions['attributes']['class'])) { + $aButtonGroupOptions['attributes']['class'] .= ' btn-group'; + } + } + + /* + * Render button group + */ + return sprintf( + static::$buttonGroupContainerFormat, + //Container attributes + $this->createAttributesString($aButtonGroupOptions['attributes']), + //Buttons + $this->renderButtons( + $aButtons, + strpos($aButtonGroupOptions['attributes']['class'], 'btn-group-justified') !== false + ) + ); + } + + /** + * Render buttons markup + * @param array $aButtons + * @return string + */ + protected function renderButtons(array $aButtons, $bJustified = false) + { + $sMarkup = ''; + foreach ($aButtons as $oButton) { + if (is_array($oButton) || + ($oButton instanceof Traversable && + !($oButton instanceof ElementInterface)) + ) { + $oFactory = new Factory(); + $oButton = $oFactory->create($oButton); + } elseif (!($oButton instanceof ElementInterface)) { + throw new LogicException(sprintf( + 'Button expects an instanceof Laminas\Form\ElementInterface or an array / Traversable, "%s" given', + is_object($oButton) ? get_class($oButton) : gettype($oButton) + )); + } + + $sButtonMarkup = $this->getFormElementHelper()->__invoke($oButton); + + $sMarkup .= $bJustified ? sprintf(static::$buttonGroupJustifiedFormat, $sButtonMarkup) : $sButtonMarkup; + } + return $sMarkup; + } + + /** + * @return TwbBundleFormElement + */ + public function getFormElementHelper() + { + if ($this->formElementHelper instanceof TwbBundleFormElement) { + return $this->formElementHelper; + } + if (method_exists($this->view, 'plugin')) { + return $this->formElementHelper = $this->view->plugin('form_element'); + } + + return $this->formElementHelper = new TwbBundleFormElement(); + } +} diff --git a/src/TwbBundle/View/Helper/TwbBundleDropDown.php b/src/TwbBundle/View/Helper/TwbBundleDropDown.php index 1886384..b4caf7d 100644 --- a/src/TwbBundle/View/Helper/TwbBundleDropDown.php +++ b/src/TwbBundle/View/Helper/TwbBundleDropDown.php @@ -47,9 +47,9 @@ class TwbBundleDropDown extends AbstractHelper /** * @var string */ - protected static $dropdownItemFormats = array( + protected static $dropdownItemFormats = [ self::TYPE_ITEM_LINK => '%s', - ); + ]; /** * @param array $aDropdownOptions @@ -71,7 +71,7 @@ public function render(array $aDropdownOptions) // Dropdown container attributes if (empty($aDropdownOptions['attributes'])) { - $aDropdownOptions['attributes'] = array('class' => 'dropdown'); + $aDropdownOptions['attributes'] = ['class' => 'dropdown']; } else { if (!is_array($aDropdownOptions['attributes'])) { throw new LogicException('"attributes" option expects an array, "' . gettype($aDropdownOptions['attributes']) . '" given'); @@ -88,9 +88,10 @@ public function render(array $aDropdownOptions) // Render dropdown return sprintf( - static::$dropdownContainerFormat, $this->createAttributesString($aDropdownOptions['attributes']), //Container attributes - $this->renderToggle($aDropdownOptions) . //Toggle - $this->renderListItems($aDropdownOptions) //List items + static::$dropdownContainerFormat, + $this->createAttributesString($aDropdownOptions['attributes']), //Container attributes + $this->renderToggle($aDropdownOptions) . //Toggle + $this->renderListItems($aDropdownOptions) //List items ); } @@ -113,7 +114,7 @@ public function renderToggle(array $aDropdownOptions) // Dropdown toggle attributes (class) if (empty($aDropdownOptions['toggle_attributes'])) { - $aDropdownOptions['toggle_attributes'] = array('class' => 'sr-only dropdown-toggle'); + $aDropdownOptions['toggle_attributes'] = ['class' => 'sr-only dropdown-toggle']; } else { if (!is_array($aDropdownOptions['toggle_attributes'])) { throw new InvalidArgumentException('"toggle_attributes" option expects an array, "' . gettype($aDropdownOptions['toggle_attributes']) . '" given'); @@ -151,14 +152,15 @@ public function renderToggle(array $aDropdownOptions) $aDropdownOptions['toggle_attributes']['id'] = $aDropdownOptions['name']; } - $aValidTagAttributes = $this->validTagAttributes; - $this->validTagAttributes = array('href' => true); - $sAttributeString = $this->createAttributesString($aDropdownOptions['toggle_attributes']); + $aValidTagAttributes = $this->validTagAttributes; + $this->validTagAttributes = ['href' => true]; + $sAttributeString = $this->createAttributesString($aDropdownOptions['toggle_attributes']); $this->validTagAttributes = $aValidTagAttributes; return sprintf( - static::$dropdownToggleFormat, $sAttributeString, // Toggle attributes - $this->getEscapeHtmlHelper()->__invoke($aDropdownOptions['label']) // Toggle label + static::$dropdownToggleFormat, + $sAttributeString, // Toggle attributes + $this->getEscapeHtmlHelper()->__invoke($aDropdownOptions['label']) // Toggle label ); } @@ -180,7 +182,7 @@ public function renderListItems(array $aDropdownOptions) // Dropdown list attributes (class) if (empty($aDropdownOptions['list_attributes'])) { - $aDropdownOptions['list_attributes'] = array('class' => 'dropdown-menu'); + $aDropdownOptions['list_attributes'] = ['class' => 'dropdown-menu']; } else { if (!is_array($aDropdownOptions['list_attributes'])) { throw new \LogicException('"list_attributes" option expects an array, "' . gettype($aDropdownOptions['list_attributes']) . '" given'); @@ -212,13 +214,13 @@ public function renderListItems(array $aDropdownOptions) } $aItemOptions = $aItemOptions === self::TYPE_ITEM_DIVIDER // Divider - ? array('type' => self::TYPE_ITEM_DIVIDER) + ? ['type' => self::TYPE_ITEM_DIVIDER] // Link - : array( - 'label' => $aItemOptions, - 'type' => self::TYPE_ITEM_LINK, - 'item_attributes' => array('href' => is_string($sKey) ? $sKey : null) - ); + : [ + 'label' => $aItemOptions, + 'type' => self::TYPE_ITEM_LINK, + 'item_attributes' => ['href' => is_string($sKey) ? $sKey : null] + ]; } else { if (!isset($aItemOptions['label'])) { $aItemOptions['label'] = is_string($sKey) ? $sKey : null; @@ -232,8 +234,9 @@ public function renderListItems(array $aDropdownOptions) } return sprintf( - static::$dropdownListFormat, $this->createAttributesString($aDropdownOptions['list_attributes']), // List attributes - $sItems // Items + static::$dropdownListFormat, + $this->createAttributesString($aDropdownOptions['list_attributes']), // List attributes + $sItems // Items ); } @@ -251,7 +254,7 @@ protected function renderItem($aItemOptions) // Item container attributes if (empty($aItemOptions['attributes'])) { - $aItemOptions['attributes'] = array(); + $aItemOptions['attributes'] = []; } elseif (!is_array($aItemOptions['attributes'])) { throw new \LogicException('"attributes" option expects an array, "' . gettype($aItemOptions['attributes']) . '" given'); } @@ -320,9 +323,9 @@ protected function renderItem($aItemOptions) $aItemOptions['item_attributes']['href'] = '#'; } - $aValidTagAttributes = $this->validTagAttributes; - $this->validTagAttributes = array('href' => true); - $sAttributeString = $this->createAttributesString($aItemOptions['item_attributes']); + $aValidTagAttributes = $this->validTagAttributes; + $this->validTagAttributes = ['href' => true]; + $sAttributeString = $this->createAttributesString($aItemOptions['item_attributes']); $this->validTagAttributes = $aValidTagAttributes; $sItemContent = sprintf(static::$dropdownItemFormats[self::TYPE_ITEM_LINK], $sAttributeString, $this->getEscapeHtmlHelper()->__invoke($aItemOptions['label'])); diff --git a/src/TwbBundle/View/Helper/TwbBundleFontAwesome.php b/src/TwbBundle/View/Helper/TwbBundleFontAwesome.php index 8fbb004..33226eb 100644 --- a/src/TwbBundle/View/Helper/TwbBundleFontAwesome.php +++ b/src/TwbBundle/View/Helper/TwbBundleFontAwesome.php @@ -1,74 +1,74 @@ -'; - - /** - * Invoke helper as functor, proxies to {@link render()}. - * @param string $sFontAwesome - * @param array $aFontAwesomeAttributes : [optionnal] - * @return string|TwbBundleFontAwesome - */ - public function __invoke($sFontAwesome = null, array $aFontAwesomeAttributes = null) - { - if (!$sFontAwesome) { - return $this; - } - return $this->render($sFontAwesome, $aFontAwesomeAttributes); - } - - /** - * Retrieve fontAwesome markup - * @param string $sFontAwesome - * @param array $aFontAwesomeAttributes : [optionnal] - * @throws InvalidArgumentException - * @return string - */ - public function render($sFontAwesome, array $aFontAwesomeAttributes = null) - { - if (!is_scalar($sFontAwesome)) { - throw new \InvalidArgumentException( - sprintf( - 'FontAwesome expects a scalar value, "%s" given', - gettype($sFontAwesome) - ) - ); - } - - if (empty($aFontAwesomeAttributes)) { - $aFontAwesomeAttributes = array('class' => 'fa'); - } else { - - if (empty($aFontAwesomeAttributes['class'])) { - $aFontAwesomeAttributes['class'] = 'fa'; - } elseif (!preg_match('/(\s|^)fa(\s|$)/', $aFontAwesomeAttributes['class'])) { - $aFontAwesomeAttributes['class'] .= ' fa'; - } - } - - if (strpos('fa-', $sFontAwesome) !== 0) { - $sFontAwesome = 'fa-' . $sFontAwesome; - } - - if (!preg_match('/(\s|^)' . preg_quote($sFontAwesome, '/') . '(\s|$)/', $aFontAwesomeAttributes['class'])) { - $aFontAwesomeAttributes['class'] .= ' ' . $sFontAwesome; - } - - return sprintf( - static::$faFormat, - $this->createAttributesString($aFontAwesomeAttributes) - ); - } -} +'; + + /** + * Invoke helper as functor, proxies to {@link render()}. + * @param string $sFontAwesome + * @param array $aFontAwesomeAttributes : [optionnal] + * @return string|TwbBundleFontAwesome + */ + public function __invoke($sFontAwesome = null, array $aFontAwesomeAttributes = null) + { + if (!$sFontAwesome) { + return $this; + } + return $this->render($sFontAwesome, $aFontAwesomeAttributes); + } + + /** + * Retrieve fontAwesome markup + * @param string $sFontAwesome + * @param array $aFontAwesomeAttributes : [optionnal] + * @throws InvalidArgumentException + * @return string + */ + public function render($sFontAwesome, array $aFontAwesomeAttributes = null) + { + if (!is_scalar($sFontAwesome)) { + throw new \InvalidArgumentException( + sprintf( + 'FontAwesome expects a scalar value, "%s" given', + gettype($sFontAwesome) + ) + ); + } + + if (empty($aFontAwesomeAttributes)) { + $aFontAwesomeAttributes = ['class' => 'fa']; + } else { + + if (empty($aFontAwesomeAttributes['class'])) { + $aFontAwesomeAttributes['class'] = 'fa'; + } elseif (!preg_match('/(\s|^)fa(\s|$)/', $aFontAwesomeAttributes['class'])) { + $aFontAwesomeAttributes['class'] .= ' fa'; + } + } + + if (strpos('fa-', $sFontAwesome) !== 0) { + $sFontAwesome = 'fa-' . $sFontAwesome; + } + + if (!preg_match('/(\s|^)' . preg_quote($sFontAwesome, '/') . '(\s|$)/', $aFontAwesomeAttributes['class'])) { + $aFontAwesomeAttributes['class'] .= ' ' . $sFontAwesome; + } + + return sprintf( + static::$faFormat, + $this->createAttributesString($aFontAwesomeAttributes) + ); + } +} diff --git a/src/TwbBundle/View/Helper/TwbBundleGlyphicon.php b/src/TwbBundle/View/Helper/TwbBundleGlyphicon.php index 2ebb74c..8286134 100644 --- a/src/TwbBundle/View/Helper/TwbBundleGlyphicon.php +++ b/src/TwbBundle/View/Helper/TwbBundleGlyphicon.php @@ -1,66 +1,66 @@ -'; - - /** - * Invoke helper as functor, proxies to {@link render()}. - * @param string $sGlyphicon - * @param array $aGlyphiconAttributes : [optionnal] - * @return string|TwbBundleGlyphicon - */ - public function __invoke($sGlyphicon = null, array $aGlyphiconAttributes = null) - { - if (!$sGlyphicon) { - return $this; - } - return $this->render($sGlyphicon, $aGlyphiconAttributes); - } - - /** - * Retrieve glyphicon markup - * @param string $sGlyphicon - * @param array $aGlyphiconAttributes : [optionnal] - * @throws InvalidArgumentException - * @return string - */ - public function render($sGlyphicon, array $aGlyphiconAttributes = null) - { - if (!is_scalar($sGlyphicon)) { - throw new InvalidArgumentException('Glyphicon expects a scalar value, "' . gettype($sGlyphicon) . '" given'); - } - - if (empty($aGlyphiconAttributes)) { - $aGlyphiconAttributes = array('class' => 'glyphicon'); - } else { - - if (empty($aGlyphiconAttributes['class'])) { - $aGlyphiconAttributes['class'] = 'glyphicon'; - } elseif (!preg_match('/(\s|^)glyphicon(\s|$)/', $aGlyphiconAttributes['class'])) { - $aGlyphiconAttributes['class'] .= ' glyphicon'; - } - } - - if (strpos('glyphicon-', $sGlyphicon) !== 0) { - $sGlyphicon = 'glyphicon-' . $sGlyphicon; - } - - if (!preg_match('/(\s|^)' . preg_quote($sGlyphicon, '/') . '(\s|$)/', $aGlyphiconAttributes['class'])) { - $aGlyphiconAttributes['class'] .= ' ' . $sGlyphicon; - } - - return sprintf( - static::$glyphiconFormat, - $this->createAttributesString($aGlyphiconAttributes) - ); - } -} +'; + + /** + * Invoke helper as functor, proxies to {@link render()}. + * @param string $sGlyphicon + * @param array $aGlyphiconAttributes : [optionnal] + * @return string|TwbBundleGlyphicon + */ + public function __invoke($sGlyphicon = null, array $aGlyphiconAttributes = null) + { + if (!$sGlyphicon) { + return $this; + } + return $this->render($sGlyphicon, $aGlyphiconAttributes); + } + + /** + * Retrieve glyphicon markup + * @param string $sGlyphicon + * @param array $aGlyphiconAttributes : [optionnal] + * @throws InvalidArgumentException + * @return string + */ + public function render($sGlyphicon, array $aGlyphiconAttributes = null) + { + if (!is_scalar($sGlyphicon)) { + throw new InvalidArgumentException('Glyphicon expects a scalar value, "' . gettype($sGlyphicon) . '" given'); + } + + if (empty($aGlyphiconAttributes)) { + $aGlyphiconAttributes = ['class' => 'glyphicon']; + } else { + + if (empty($aGlyphiconAttributes['class'])) { + $aGlyphiconAttributes['class'] = 'glyphicon'; + } elseif (!preg_match('/(\s|^)glyphicon(\s|$)/', $aGlyphiconAttributes['class'])) { + $aGlyphiconAttributes['class'] .= ' glyphicon'; + } + } + + if (strpos('glyphicon-', $sGlyphicon) !== 0) { + $sGlyphicon = 'glyphicon-' . $sGlyphicon; + } + + if (!preg_match('/(\s|^)' . preg_quote($sGlyphicon, '/') . '(\s|$)/', $aGlyphiconAttributes['class'])) { + $aGlyphiconAttributes['class'] .= ' ' . $sGlyphicon; + } + + return sprintf( + static::$glyphiconFormat, + $this->createAttributesString($aGlyphiconAttributes) + ); + } +} diff --git a/src/TwbBundle/View/Helper/TwbBundleLabel.php b/src/TwbBundle/View/Helper/TwbBundleLabel.php index b7b7ad6..3aee4c7 100644 --- a/src/TwbBundle/View/Helper/TwbBundleLabel.php +++ b/src/TwbBundle/View/Helper/TwbBundleLabel.php @@ -1,87 +1,87 @@ -%s'; - - /** - * @var string - */ - protected $tagName = 'span'; - - /** - * @var array - */ - protected $validTagAttributes = array( - 'href' => true, - ); - - /** - * Invoke helper as functor, proxies to {@link render()}. - * @param string $sLabelMessage - * @param string|array $aLabelAttributes : [optionnal] if string, label class - * @return string|\TwbBundle\View\Helper\TwbBundleAlert - */ - public function __invoke($sLabelMessage = null, $aLabelAttributes = 'label-default') - { - if (!$sLabelMessage) { - return $this; - } - - return $this->render($sLabelMessage, $aLabelAttributes); - } - - /** - * Retrieve label markup - * @param string $sLabelMessage - * @param string|array $aLabelAttributes : [optionnal] if string, label class - * @throws InvalidArgumentException - * @return string - */ - public function render($sLabelMessage, $aLabelAttributes = 'label-default') - { - if (!is_scalar($sLabelMessage)) { - throw new InvalidArgumentException('Label message expects a scalar value, "' . gettype($sLabelMessage) . '" given'); - } - - if (empty($aLabelAttributes)) { - throw new InvalidArgumentException('Label attributes are empty'); - } - - if (is_string($aLabelAttributes)) { - $aLabelAttributes = array('class' => $aLabelAttributes); - } elseif (!is_array($aLabelAttributes)) { - throw new InvalidArgumentException('Label attributes expects a string or an array, "' . gettype($aLabelAttributes) . '" given'); - } elseif (empty($aLabelAttributes['class'])) { - throw new \InvalidArgumentException('Label "class" attribute is empty'); - } elseif (!is_string($aLabelAttributes['class'])) { - throw new InvalidArgumentException('Label "class" attribute expects string, "' . gettype($aLabelAttributes) . '" given'); - } - - if (!preg_match('/(\s|^)label(\s|$)/', $aLabelAttributes['class'])) { - $aLabelAttributes['class'] .= ' label'; - } - - if (null !== ($oTranslator = $this->getTranslator())) { - $sLabelMessage = $oTranslator->translate($sLabelMessage, $this->getTranslatorTextDomain()); - } - - return sprintf( - static::$labelFormat, - isset($aLabelAttributes['tagName']) ? $aLabelAttributes['tagName'] : $this->tagName, - $this->createAttributesString($aLabelAttributes), - $sLabelMessage - ); - } -} +%s'; + + /** + * @var string + */ + protected $tagName = 'span'; + + /** + * @var array + */ + protected $validTagAttributes = [ + 'href' => true, + ]; + + /** + * Invoke helper as functor, proxies to {@link render()}. + * @param string $sLabelMessage + * @param string|array $aLabelAttributes : [optionnal] if string, label class + * @return string|\TwbBundle\View\Helper\TwbBundleAlert + */ + public function __invoke($sLabelMessage = null, $aLabelAttributes = 'label-default') + { + if (!$sLabelMessage) { + return $this; + } + + return $this->render($sLabelMessage, $aLabelAttributes); + } + + /** + * Retrieve label markup + * @param string $sLabelMessage + * @param string|array $aLabelAttributes : [optionnal] if string, label class + * @throws InvalidArgumentException + * @return string + */ + public function render($sLabelMessage, $aLabelAttributes = 'label-default') + { + if (!is_scalar($sLabelMessage)) { + throw new InvalidArgumentException('Label message expects a scalar value, "' . gettype($sLabelMessage) . '" given'); + } + + if (empty($aLabelAttributes)) { + throw new InvalidArgumentException('Label attributes are empty'); + } + + if (is_string($aLabelAttributes)) { + $aLabelAttributes = ['class' => $aLabelAttributes]; + } elseif (!is_array($aLabelAttributes)) { + throw new InvalidArgumentException('Label attributes expects a string or an array, "' . gettype($aLabelAttributes) . '" given'); + } elseif (empty($aLabelAttributes['class'])) { + throw new \InvalidArgumentException('Label "class" attribute is empty'); + } elseif (!is_string($aLabelAttributes['class'])) { + throw new InvalidArgumentException('Label "class" attribute expects string, "' . gettype($aLabelAttributes) . '" given'); + } + + if (!preg_match('/(\s|^)label(\s|$)/', $aLabelAttributes['class'])) { + $aLabelAttributes['class'] .= ' label'; + } + + if (null !== ($oTranslator = $this->getTranslator())) { + $sLabelMessage = $oTranslator->translate($sLabelMessage, $this->getTranslatorTextDomain()); + } + + return sprintf( + static::$labelFormat, + isset($aLabelAttributes['tagName']) ? $aLabelAttributes['tagName'] : $this->tagName, + $this->createAttributesString($aLabelAttributes), + $sLabelMessage + ); + } +} diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 4172706..ea83fe2 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -1,123 +1,130 @@ - array( - 'module_paths' => array_merge( - $aZf2ModulePaths, explode(PATH_SEPARATOR, (getenv('ZF2_MODULES_TEST_PATHS')? : (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : ''))) - ) - ) - ), $aTestConfig); - - $configuration = static::$config; - // Prepare the service manager - $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array(); - $smConfig = new Service\ServiceManagerConfig($smConfig); - - $serviceManager = new ServiceManager(); - $smConfig->configureServiceManager($serviceManager); - $serviceManager->setService('ApplicationConfig', $configuration); - - // Load modules - $serviceManager->get('ModuleManager')->loadModules(); - - static::$serviceManager = $serviceManager; - } - - /** - * @return \Laminas\ServiceManager\ServiceManager - */ - public static function getServiceManager() { - return static::$serviceManager; - } - - /** - * @return array - */ - public static function getConfig() { - return static::$config; - } - - /** - * Initialize Autoloader - * @throws \RuntimeException - */ - protected static function initAutoloader() { - $sVendorPath = static::findParentPath('vendor'); - - if (is_readable($sVendorPath . '/autoload.php')) { - include $sVendorPath . '/autoload.php'; - } else { - $sZf2Path = getenv('ZF2_PATH')? : (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($sVendorPath . '/ZF2/library') ? $sVendorPath . '/ZF2/library' : false)); - if (!$sZf2Path) { - throw new \RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.'); - } - include $sZf2Path . '/Zend/Loader/AutoloaderFactory.php'; - } - \Laminas\Loader\AutoloaderFactory::factory(array( - 'Laminas\Loader\StandardAutoloader' => array( - 'autoregister_zf' => true, - 'namespaces' => array( - __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__, - ), - ), - )); - } - - /** - * Retrieve parent for a given path - * @param string $sPath - * @return boolean|string - */ - protected static function findParentPath($sPath) { - $sCurrentDir = __DIR__; - $sPreviousDir = '.'; - while (!is_dir($sPreviousDir . '/' . $sPath)) { - $sCurrentDir = dirname($sCurrentDir); - if ($sPreviousDir === $sCurrentDir) { - return false; - } - $sPreviousDir = $sCurrentDir; - } - return $sCurrentDir . '/' . $sPath; - } - -} - -Bootstrap::init(); + [ + 'module_paths' => array_merge( + $aZf2ModulePaths, + explode(PATH_SEPARATOR, (getenv('ZF2_MODULES_TEST_PATHS')? : (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : ''))) + ) + ] + ], $aTestConfig); + + $configuration = static::$config; + // Prepare the service manager + $smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : []; + $smConfig = new Service\ServiceManagerConfig($smConfig); + + $serviceManager = new ServiceManager(); + $smConfig->configureServiceManager($serviceManager); + $serviceManager->setService('ApplicationConfig', $configuration); + + // Load modules + $serviceManager->get('ModuleManager')->loadModules(); + + static::$serviceManager = $serviceManager; + } + + /** + * @return \Laminas\ServiceManager\ServiceManager + */ + public static function getServiceManager() + { + return static::$serviceManager; + } + + /** + * @return array + */ + public static function getConfig() + { + return static::$config; + } + + /** + * Initialize Autoloader + * @throws \RuntimeException + */ + protected static function initAutoloader() + { + $sVendorPath = static::findParentPath('vendor'); + + if (is_readable($sVendorPath . '/autoload.php')) { + include $sVendorPath . '/autoload.php'; + } else { + $sZf2Path = getenv('ZF2_PATH')? : (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($sVendorPath . '/ZF2/library') ? $sVendorPath . '/ZF2/library' : false)); + if (!$sZf2Path) { + throw new \RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.'); + } + include $sZf2Path . '/Zend/Loader/AutoloaderFactory.php'; + } + \Laminas\Loader\AutoloaderFactory::factory([ + 'Laminas\Loader\StandardAutoloader' => [ + 'autoregister_zf' => true, + 'namespaces' => [ + __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__, + ], + ], + ]); + } + + /** + * Retrieve parent for a given path + * @param string $sPath + * @return boolean|string + */ + protected static function findParentPath($sPath) + { + $sCurrentDir = __DIR__; + $sPreviousDir = '.'; + while (!is_dir($sPreviousDir . '/' . $sPath)) { + $sCurrentDir = dirname($sCurrentDir); + if ($sPreviousDir === $sCurrentDir) { + return false; + } + $sPreviousDir = $sCurrentDir; + } + return $sCurrentDir . '/' . $sPath; + } + +} + +Bootstrap::init(); diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleAlertsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleAlertsTest.php index edc3b61..9209f89 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleAlertsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleAlertsTest.php @@ -1,58 +1,63 @@ -expectedPath = __DIR__.DIRECTORY_SEPARATOR.'../../_files/expected-alerts'.DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->alertHelper = $oViewHelperPluginManager->get('alert')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - /** - * Test http://getbootstrap.com/components/#alerts-examples - */ - public function testExamples(){ - $sContent = ''; - - //Success - $sContent .= $this->alertHelper->__invoke('Well done! You successfully read this important alert message.','alert-success')."\n"; - - //Info - $sContent .= $this->alertHelper->__invoke('Heads up! This alert needs your attention, but it\'s not super important.','alert-info')."\n"; - - //Warning - $sContent .= $this->alertHelper->__invoke('Warning! Best check yo self, you\'re not looking too good.','alert-warning')."\n"; - - //Danger - $sContent .= $this->alertHelper->__invoke('Oh snap! Change a few things up and try submitting again.','alert-danger')."\n"; - - $this->assertStringEqualsFile($this->expectedPath.'alerts-examples.phtml',$sContent); - } - - /** - * Test http://getbootstrap.com/components/#alerts-dismissable - */ - public function testDismissableAlerts(){ - - $sContent = $this->alertHelper->__invoke('Warning! Best check yo self, you\'re not looking too good.',null,true)."\n"; - - $this->assertStringEqualsFile($this->expectedPath.'alerts-dismissable.phtml',$sContent); - } -} \ No newline at end of file +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-alerts' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->alertHelper = $oViewHelperPluginManager->get('alert')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + /** + * Test http://getbootstrap.com/components/#alerts-examples + */ + public function testExamples() + { + $sContent = ''; + + //Success + $sContent .= $this->alertHelper->__invoke('Well done! You successfully read this important alert message.', 'alert-success') . "\n"; + + //Info + $sContent .= $this->alertHelper->__invoke('Heads up! This alert needs your attention, but it\'s not super important.', 'alert-info') . "\n"; + + //Warning + $sContent .= $this->alertHelper->__invoke('Warning! Best check yo self, you\'re not looking too good.', 'alert-warning') . "\n"; + + //Danger + $sContent .= $this->alertHelper->__invoke('Oh snap! Change a few things up and try submitting again.', 'alert-danger') . "\n"; + + $this->assertStringEqualsFile($this->expectedPath . 'alerts-examples.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#alerts-dismissable + */ + public function testDismissableAlerts() + { + + $sContent = $this->alertHelper->__invoke('Warning! Best check yo self, you\'re not looking too good.', null, true) . "\n"; + + $this->assertStringEqualsFile($this->expectedPath . 'alerts-dismissable.phtml', $sContent); + } +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleBadgesTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleBadgesTest.php index 211aff7..8cde2e8 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleBadgesTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleBadgesTest.php @@ -1,39 +1,43 @@ -expectedPath = __DIR__.DIRECTORY_SEPARATOR.'../../_files/expected-badges'.DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->badgeHelper = $oViewHelperPluginManager->get('badge')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testBadges(){ - $sContent = ''; - - //Default - $sContent .= $this->badgeHelper->__invoke('42')."\n"; - - //Pull-right - $sContent .= $this->badgeHelper->__invoke('3',array('class' => 'pull-right'))."\n"; - - $this->assertStringEqualsFile($this->expectedPath.'badges.phtml',$sContent); - } -} \ No newline at end of file +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-badges' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->badgeHelper = $oViewHelperPluginManager->get('badge')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testBadges() + { + $sContent = ''; + + //Default + $sContent .= $this->badgeHelper->__invoke('42') . "\n"; + + //Pull-right + $sContent .= $this->badgeHelper->__invoke('3', ['class' => 'pull-right']) . "\n"; + + $this->assertStringEqualsFile($this->expectedPath . 'badges.phtml', $sContent); + } +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonGroupsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonGroupsTest.php index 02b41e5..8e0e7bd 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonGroupsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonGroupsTest.php @@ -1,168 +1,177 @@ -expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-button-groups' . DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->buttonGroupHelper = $oViewHelperPluginManager->get('buttonGroup')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - /** - * Test http://getbootstrap.com/components/#btn-groups-single - */ - public function testBasicExemple() { - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'single.phtml', $this->buttonGroupHelper->__invoke(array( - new \Laminas\Form\Element\Button('left', array('label' => 'Left')), - new \Laminas\Form\Element\Button('middle', array('label' => 'Middle')), - new \Laminas\Form\Element\Button('right', array('label' => 'Right')), - ))); - } - - /** - * Test http://getbootstrap.com/components/#btn-groups-toolbar - */ - public function testButtonToolbar() { - - $sContent = ''; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'toolbar.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#btn-groups-sizing - */ - public function testSizing() { - - $sContent = ''; - - //Large - $sContent .= ''; - - //Normal - $sContent .= ''; - - //Small - $sContent .= ''; - - //Extra small - $sContent .= ''; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'sizing.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#btn-groups-nested - */ - public function testNesting() { - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'nested.phtml', $this->buttonGroupHelper->__invoke(array( - new \Laminas\Form\Element\Button('1', array('label' => '1')), - new \Laminas\Form\Element\Button('2', array('label' => '2')), - new \Laminas\Form\Element\Button('dropdown', array('label' => 'Dropdown', 'dropdown' => array('items' => array('Dropdown link', 'Dropdown link')))) - ))); - } - - /** - * Test http://getbootstrap.com/components/#btn-groups-vertical - */ - public function testVerticalVariation() { - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'vertical.phtml', $this->buttonGroupHelper->__invoke(array( - new \Laminas\Form\Element\Button('button', array('label' => 'Button')), - new \Laminas\Form\Element\Button('button', array('label' => 'Button')), - new \Laminas\Form\Element\Button('dropdown', array('label' => 'Dropdown', 'dropdown' => array('items' => array('Dropdown link', 'Dropdown link')))), - new \Laminas\Form\Element\Button('button', array('label' => 'Button')), - new \Laminas\Form\Element\Button('button', array('label' => 'Button')), - new \Laminas\Form\Element\Button('dropdown', array('label' => 'Dropdown', 'dropdown' => array('items' => array('Dropdown link', 'Dropdown link')))), - new \Laminas\Form\Element\Button('dropdown', array('label' => 'Dropdown', 'dropdown' => array('items' => array('Dropdown link', 'Dropdown link')))), - new \Laminas\Form\Element\Button('dropdown', array('label' => 'Dropdown', 'dropdown' => array('items' => array('Dropdown link', 'Dropdown link')))), - ), array('attributes' => array('class' => 'btn-group-vertical')))); - } - - /** - * Test http://getbootstrap.com/components/#btn-groups-justified - */ - public function testJustifiedButtonGroups() { - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'justified.phtml', $this->buttonGroupHelper->__invoke(array( - new \Laminas\Form\Element\Button('left', array('label' => 'Left')), - new \Laminas\Form\Element\Button('middle', array('label' => 'Middle')), - new \Laminas\Form\Element\Button('right', array('label' => 'Right')), - ), array('attributes' => array('class' => 'btn-group-justified')))); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) { - file_put_contents($sExpectedFile, $sActualString); - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } - -} +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-button-groups' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->buttonGroupHelper = $oViewHelperPluginManager->get('buttonGroup')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + /** + * Test http://getbootstrap.com/components/#btn-groups-single + */ + public function testBasicExemple() + { + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'single.phtml', $this->buttonGroupHelper->__invoke([ + new \Laminas\Form\Element\Button('left', ['label' => 'Left']), + new \Laminas\Form\Element\Button('middle', ['label' => 'Middle']), + new \Laminas\Form\Element\Button('right', ['label' => 'Right']), + ])); + } + + /** + * Test http://getbootstrap.com/components/#btn-groups-toolbar + */ + public function testButtonToolbar() + { + + $sContent = ''; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'toolbar.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#btn-groups-sizing + */ + public function testSizing() + { + + $sContent = ''; + + //Large + $sContent .= ''; + + //Normal + $sContent .= ''; + + //Small + $sContent .= ''; + + //Extra small + $sContent .= ''; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'sizing.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#btn-groups-nested + */ + public function testNesting() + { + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'nested.phtml', $this->buttonGroupHelper->__invoke([ + new \Laminas\Form\Element\Button('1', ['label' => '1']), + new \Laminas\Form\Element\Button('2', ['label' => '2']), + new \Laminas\Form\Element\Button('dropdown', ['label' => 'Dropdown', 'dropdown' => ['items' => ['Dropdown link', 'Dropdown link']]]) + ])); + } + + /** + * Test http://getbootstrap.com/components/#btn-groups-vertical + */ + public function testVerticalVariation() + { + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'vertical.phtml', $this->buttonGroupHelper->__invoke([ + new \Laminas\Form\Element\Button('button', ['label' => 'Button']), + new \Laminas\Form\Element\Button('button', ['label' => 'Button']), + new \Laminas\Form\Element\Button('dropdown', ['label' => 'Dropdown', 'dropdown' => ['items' => ['Dropdown link', 'Dropdown link']]]), + new \Laminas\Form\Element\Button('button', ['label' => 'Button']), + new \Laminas\Form\Element\Button('button', ['label' => 'Button']), + new \Laminas\Form\Element\Button('dropdown', ['label' => 'Dropdown', 'dropdown' => ['items' => ['Dropdown link', 'Dropdown link']]]), + new \Laminas\Form\Element\Button('dropdown', ['label' => 'Dropdown', 'dropdown' => ['items' => ['Dropdown link', 'Dropdown link']]]), + new \Laminas\Form\Element\Button('dropdown', ['label' => 'Dropdown', 'dropdown' => ['items' => ['Dropdown link', 'Dropdown link']]]), + ], ['attributes' => ['class' => 'btn-group-vertical']])); + } + + /** + * Test http://getbootstrap.com/components/#btn-groups-justified + */ + public function testJustifiedButtonGroups() + { + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'justified.phtml', $this->buttonGroupHelper->__invoke([ + new \Laminas\Form\Element\Button('left', ['label' => 'Left']), + new \Laminas\Form\Element\Button('middle', ['label' => 'Middle']), + new \Laminas\Form\Element\Button('right', ['label' => 'Right']), + ], ['attributes' => ['class' => 'btn-group-justified']])); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + file_put_contents($sExpectedFile, $sActualString); + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } + +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsDropdownsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsDropdownsTest.php index 83a8e1a..36662b1 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsDropdownsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsDropdownsTest.php @@ -1,169 +1,176 @@ -expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-buttons-dropdowns' . DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formButtonHelper = $oViewHelperPluginManager->get('formButton')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - /** - * Test http://getbootstrap.com/components/#btn-dropdowns-single - */ - public function testSingleButtonDropdowns() { - $aDropDownOptions = array( - 'items' => array('Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link') - ); - - $sContent = ''; - $oButton = new \Laminas\Form\Element\Button('default', array('label' => 'Default', 'dropdown' => $aDropDownOptions)); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('primary', array('label' => 'Primary', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-primary'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('success', array('label' => 'Success', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-success'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('info', array('label' => 'Info', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-info'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('warning', array('label' => 'Warning', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-warning'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('danger', array('label' => 'Danger', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-danger'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'dropdowns-single.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#btn-dropdowns-split - */ - public function testSplitButtonDropdowns() { - $aDropDownOptions = array( - 'split' => true, - 'items' => array('Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link') - ); - - $sContent = ''; - - $oButton = new \Laminas\Form\Element\Button('default', array('label' => 'Default', 'dropdown' => $aDropDownOptions)); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('primary', array('label' => 'Primary', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-primary'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('success', array('label' => 'Success', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-success'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('info', array('label' => 'Info', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-info'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('warning', array('label' => 'Warning', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-warning'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('danger', array('label' => 'Danger', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-danger'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'dropdowns-split.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#btn-dropdowns-sizing - */ - public function testDropdownsSizing() { - $aDropDownOptions = array( - 'items' => array('Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link') - ); - - $sContent = ''; - - //Large - $oButton = new \Laminas\Form\Element\Button('large-button-default', array('label' => 'Large button', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-lg'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Small - $oButton = new \Laminas\Form\Element\Button('small-button-default', array('label' => 'Small button', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-sm'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Extra small - $oButton = new \Laminas\Form\Element\Button('extra-small-button-default', array('label' => 'Extra small button', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-xs'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'dropdowns-sizing.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#btn-dropdowns-dropup - */ - public function testDropup() { - $aDropDownOptions = array( - 'dropup' => true, - 'split' => true, - 'items' => array('Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link') - ); - - $sContent = ''; - - $oButton = new \Laminas\Form\Element\Button('default', array('label' => 'Dropup', 'dropdown' => $aDropDownOptions)); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $aDropDownOptions['list_attributes'] = array('class' => 'pull-right'); - $oButton = new \Laminas\Form\Element\Button('primary', array('label' => 'Right dropup', 'dropdown' => $aDropDownOptions)); - $oButton->setAttribute('class', 'btn-primary'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'dropup.phtml', $sContent); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) { - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } - -} +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-buttons-dropdowns' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formButtonHelper = $oViewHelperPluginManager->get('formButton')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + /** + * Test http://getbootstrap.com/components/#btn-dropdowns-single + */ + public function testSingleButtonDropdowns() + { + $aDropDownOptions = [ + 'items' => ['Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link'] + ]; + + $sContent = ''; + $oButton = new \Laminas\Form\Element\Button('default', ['label' => 'Default', 'dropdown' => $aDropDownOptions]); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('primary', ['label' => 'Primary', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-primary'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('success', ['label' => 'Success', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-success'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('info', ['label' => 'Info', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-info'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('warning', ['label' => 'Warning', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-warning'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('danger', ['label' => 'Danger', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-danger'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'dropdowns-single.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#btn-dropdowns-split + */ + public function testSplitButtonDropdowns() + { + $aDropDownOptions = [ + 'split' => true, + 'items' => ['Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link'] + ]; + + $sContent = ''; + + $oButton = new \Laminas\Form\Element\Button('default', ['label' => 'Default', 'dropdown' => $aDropDownOptions]); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('primary', ['label' => 'Primary', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-primary'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('success', ['label' => 'Success', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-success'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('info', ['label' => 'Info', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-info'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('warning', ['label' => 'Warning', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-warning'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('danger', ['label' => 'Danger', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-danger'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'dropdowns-split.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#btn-dropdowns-sizing + */ + public function testDropdownsSizing() + { + $aDropDownOptions = [ + 'items' => ['Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link'] + ]; + + $sContent = ''; + + //Large + $oButton = new \Laminas\Form\Element\Button('large-button-default', ['label' => 'Large button', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-lg'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Small + $oButton = new \Laminas\Form\Element\Button('small-button-default', ['label' => 'Small button', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-sm'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Extra small + $oButton = new \Laminas\Form\Element\Button('extra-small-button-default', ['label' => 'Extra small button', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-xs'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'dropdowns-sizing.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#btn-dropdowns-dropup + */ + public function testDropup() + { + $aDropDownOptions = [ + 'dropup' => true, + 'split' => true, + 'items' => ['Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link'] + ]; + + $sContent = ''; + + $oButton = new \Laminas\Form\Element\Button('default', ['label' => 'Dropup', 'dropdown' => $aDropDownOptions]); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $aDropDownOptions['list_attributes'] = ['class' => 'pull-right']; + $oButton = new \Laminas\Form\Element\Button('primary', ['label' => 'Right dropup', 'dropdown' => $aDropDownOptions]); + $oButton->setAttribute('class', 'btn-primary'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'dropup.phtml', $sContent); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } + +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsTest.php index 1cb0e21..4e31cc9 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleButtonsTest.php @@ -1,178 +1,185 @@ -expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-buttons' . DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formButtonHelper = $oViewHelperPluginManager->get('formButton')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - /** - * Test http://getbootstrap.com/css/#buttons-options - */ - public function testButtonsOptions() { - $sContent = ''; - $oButton = new \Laminas\Form\Element\Button('default', array('label' => 'Default')); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('primary', array('label' => 'Primary')); - $oButton->setAttribute('class', 'btn-primary'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('success', array('label' => 'Success')); - $oButton->setAttribute('class', 'btn-success'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('info', array('label' => 'Info')); - $oButton->setAttribute('class', 'btn-info'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('warning', array('label' => 'Warning')); - $oButton->setAttribute('class', 'btn-warning'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('danger', array('label' => 'Danger')); - $oButton->setAttribute('class', 'btn-danger'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('link', array('label' => 'Link')); - $oButton->setAttribute('class', 'btn-link'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'options.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/css/#buttons-sizes - */ - public function testButtonsSizes() { - $sContent = ''; - - //Large - $oButton = new \Laminas\Form\Element\Button('large-button-primary', array('label' => 'Large button')); - $oButton->setAttribute('class', 'btn-primary btn-lg'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('large-button-default', array('label' => 'Large button')); - $oButton->setAttribute('class', 'btn-lg'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Default - $oButton = new \Laminas\Form\Element\Button('button-primary', array('label' => 'Default button')); - $oButton->setAttribute('class', 'btn-primary'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('button-default', array('label' => 'Default button')); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Small - $oButton = new \Laminas\Form\Element\Button('small-button-primary', array('label' => 'Small button')); - $oButton->setAttribute('class', 'btn-primary btn-sm'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('small-button-default', array('label' => 'Small button')); - $oButton->setAttribute('class', 'btn-sm'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Extra small - $oButton = new \Laminas\Form\Element\Button('extra-small-button-primary', array('label' => 'Extra small button')); - $oButton->setAttribute('class', 'btn-primary btn-xs'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('extra-small-button-default', array('label' => 'Extra small button')); - $oButton->setAttribute('class', 'btn-xs'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Block level - $oButton = new \Laminas\Form\Element\Button('block-level-button-primary', array('label' => 'Block level button')); - $oButton->setAttribute('class', 'btn-primary btn-block'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('block-level-button-default', array('label' => 'Block level button')); - $oButton->setAttribute('class', 'btn-block'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'sizes.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/css/#buttons-active - */ - public function testButtonsActive() { - $sContent = ''; - - $oButton = new \Laminas\Form\Element\Button('large-button-primary-active', array('label' => 'Primary button')); - $oButton->setAttributes(array( - 'class' => 'btn-primary btn-lg active', - )); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('large-button-default-active', array('label' => 'Button')); - $oButton->setAttributes(array( - 'class' => 'btn-lg active', - )); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'active.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/css/#buttons-disabled - */ - public function testButtonsDisabled() { - $sContent = ''; - - $oButton = new \Laminas\Form\Element\Button('large-button-primary-disabled', array('label' => 'Primary button')); - $oButton->setAttributes(array( - 'class' => 'btn-primary btn-lg', - 'disabled' => true - )); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $oButton = new \Laminas\Form\Element\Button('large-button-default-disabled', array('label' => 'Button')); - $oButton->setAttributes(array( - 'class' => 'btn-lg', - 'disabled' => true - )); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'disabled.phtml', $sContent); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) { - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } - -} +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-buttons' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formButtonHelper = $oViewHelperPluginManager->get('formButton')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + /** + * Test http://getbootstrap.com/css/#buttons-options + */ + public function testButtonsOptions() + { + $sContent = ''; + $oButton = new \Laminas\Form\Element\Button('default', ['label' => 'Default']); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('primary', ['label' => 'Primary']); + $oButton->setAttribute('class', 'btn-primary'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('success', ['label' => 'Success']); + $oButton->setAttribute('class', 'btn-success'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('info', ['label' => 'Info']); + $oButton->setAttribute('class', 'btn-info'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('warning', ['label' => 'Warning']); + $oButton->setAttribute('class', 'btn-warning'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('danger', ['label' => 'Danger']); + $oButton->setAttribute('class', 'btn-danger'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('link', ['label' => 'Link']); + $oButton->setAttribute('class', 'btn-link'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'options.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/css/#buttons-sizes + */ + public function testButtonsSizes() + { + $sContent = ''; + + //Large + $oButton = new \Laminas\Form\Element\Button('large-button-primary', ['label' => 'Large button']); + $oButton->setAttribute('class', 'btn-primary btn-lg'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('large-button-default', ['label' => 'Large button']); + $oButton->setAttribute('class', 'btn-lg'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Default + $oButton = new \Laminas\Form\Element\Button('button-primary', ['label' => 'Default button']); + $oButton->setAttribute('class', 'btn-primary'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('button-default', ['label' => 'Default button']); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Small + $oButton = new \Laminas\Form\Element\Button('small-button-primary', ['label' => 'Small button']); + $oButton->setAttribute('class', 'btn-primary btn-sm'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('small-button-default', ['label' => 'Small button']); + $oButton->setAttribute('class', 'btn-sm'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Extra small + $oButton = new \Laminas\Form\Element\Button('extra-small-button-primary', ['label' => 'Extra small button']); + $oButton->setAttribute('class', 'btn-primary btn-xs'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('extra-small-button-default', ['label' => 'Extra small button']); + $oButton->setAttribute('class', 'btn-xs'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Block level + $oButton = new \Laminas\Form\Element\Button('block-level-button-primary', ['label' => 'Block level button']); + $oButton->setAttribute('class', 'btn-primary btn-block'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('block-level-button-default', ['label' => 'Block level button']); + $oButton->setAttribute('class', 'btn-block'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'sizes.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/css/#buttons-active + */ + public function testButtonsActive() + { + $sContent = ''; + + $oButton = new \Laminas\Form\Element\Button('large-button-primary-active', ['label' => 'Primary button']); + $oButton->setAttributes([ + 'class' => 'btn-primary btn-lg active', + ]); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('large-button-default-active', ['label' => 'Button']); + $oButton->setAttributes([ + 'class' => 'btn-lg active', + ]); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'active.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/css/#buttons-disabled + */ + public function testButtonsDisabled() + { + $sContent = ''; + + $oButton = new \Laminas\Form\Element\Button('large-button-primary-disabled', ['label' => 'Primary button']); + $oButton->setAttributes([ + 'class' => 'btn-primary btn-lg', + 'disabled' => true + ]); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $oButton = new \Laminas\Form\Element\Button('large-button-default-disabled', ['label' => 'Button']); + $oButton->setAttributes([ + 'class' => 'btn-lg', + 'disabled' => true + ]); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'disabled.phtml', $sContent); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } + +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleDropdownsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleDropdownsTest.php index 1636284..7738ec0 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleDropdownsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleDropdownsTest.php @@ -1,122 +1,122 @@ -expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-dropdowns' . DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->dropdownHelper = $oViewHelperPluginManager->get('dropDown')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - /** - * Test http://getbootstrap.com/components/#dropdowns-example - */ - public function testExample() - { - $aDropDownOptions = array( - 'label' => 'Dropdown', - 'name' => 'dropdownMenu1', - 'attributes' => array('class' => 'clearfix'), - 'list_attributes' => array('aria-labelledby' => 'dropdownMenu1'), - 'items' => array('Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link') - ); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'exemple.phtml', $this->dropdownHelper->__invoke($aDropDownOptions)); - } - - /** - * Test http://getbootstrap.com/components/#dropdowns-alignment - */ - public function testAlignment() - { - $aDropDownOptions = array( - 'label' => 'Dropdown', - 'name' => 'dropdownMenu1', - 'attributes' => array('class' => 'clearfix'), - 'list_attributes' => array('aria-labelledby' => 'dropdownMenu1', 'class' => 'pull-right'), - 'items' => array('Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link') - ); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'alignment.phtml', $this->dropdownHelper->__invoke($aDropDownOptions)); - } - - /** - * Test http://getbootstrap.com/components/#dropdowns-headers - */ - public function testHeaders() - { - $aDropDownOptions = array( - 'label' => 'Dropdown', - 'name' => 'dropdownMenu1', - 'attributes' => array('class' => 'clearfix'), - 'list_attributes' => array('aria-labelledby' => 'dropdownMenu1'), - 'items' => array( - array('type' => \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_HEADER, 'label' => 'Dropdown header'), - 'Action', 'Another action', 'Something else here', - \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, - array('type' => \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_HEADER, 'label' => 'Dropdown header'), - 'Separated link' - ) - ); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'headers.phtml', $this->dropdownHelper->__invoke($aDropDownOptions)); - } - - /** - * Test http://getbootstrap.com/components/#dropdowns-disabled - */ - public function testDisabled() - { - $aDropDownOptions = array( - 'label' => 'Dropdown', - 'name' => 'dropdownMenu1', - 'attributes' => array('class' => 'clearfix'), - 'list_attributes' => array('aria-labelledby' => 'dropdownMenu1'), - 'items' => array( - 'Regular link', - 'Disabled link' => array('attributes' => array('class' => 'disabled')), - 'Another link' - ) - ); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'disabled.phtml', $this->dropdownHelper->__invoke($aDropDownOptions)); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) - { - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } -} +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-dropdowns' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->dropdownHelper = $oViewHelperPluginManager->get('dropDown')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + /** + * Test http://getbootstrap.com/components/#dropdowns-example + */ + public function testExample() + { + $aDropDownOptions = [ + 'label' => 'Dropdown', + 'name' => 'dropdownMenu1', + 'attributes' => ['class' => 'clearfix'], + 'list_attributes' => ['aria-labelledby' => 'dropdownMenu1'], + 'items' => ['Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link'] + ]; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'exemple.phtml', $this->dropdownHelper->__invoke($aDropDownOptions)); + } + + /** + * Test http://getbootstrap.com/components/#dropdowns-alignment + */ + public function testAlignment() + { + $aDropDownOptions = [ + 'label' => 'Dropdown', + 'name' => 'dropdownMenu1', + 'attributes' => ['class' => 'clearfix'], + 'list_attributes' => ['aria-labelledby' => 'dropdownMenu1', 'class' => 'pull-right'], + 'items' => ['Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link'] + ]; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'alignment.phtml', $this->dropdownHelper->__invoke($aDropDownOptions)); + } + + /** + * Test http://getbootstrap.com/components/#dropdowns-headers + */ + public function testHeaders() + { + $aDropDownOptions = [ + 'label' => 'Dropdown', + 'name' => 'dropdownMenu1', + 'attributes' => ['class' => 'clearfix'], + 'list_attributes' => ['aria-labelledby' => 'dropdownMenu1'], + 'items' => [ + ['type' => \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_HEADER, 'label' => 'Dropdown header'], + 'Action', 'Another action', 'Something else here', + \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, + ['type' => \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_HEADER, 'label' => 'Dropdown header'], + 'Separated link' + ] + ]; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'headers.phtml', $this->dropdownHelper->__invoke($aDropDownOptions)); + } + + /** + * Test http://getbootstrap.com/components/#dropdowns-disabled + */ + public function testDisabled() + { + $aDropDownOptions = [ + 'label' => 'Dropdown', + 'name' => 'dropdownMenu1', + 'attributes' => ['class' => 'clearfix'], + 'list_attributes' => ['aria-labelledby' => 'dropdownMenu1'], + 'items' => [ + 'Regular link', + 'Disabled link' => ['attributes' => ['class' => 'disabled']], + 'Another link' + ] + ]; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'disabled.phtml', $this->dropdownHelper->__invoke($aDropDownOptions)); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleFormsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleFormsTest.php index b1a22ec..c1dfe0d 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleFormsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleFormsTest.php @@ -1,565 +1,565 @@ -expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-forms' . DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formHelper = $oViewHelperPluginManager->get('form')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - /** - * Test http://getbootstrap.com/css/#forms-example - */ - public function testBasicExample() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-email', - 'attributes' => array( - 'type' => 'email', - 'placeholder' => 'Enter email', - 'id' => 'exampleInputEmail1' - ), - 'options' => array('label' => 'Email address') - ))->add(array( - 'name' => 'input-password', - 'attributes' => array( - 'type' => 'password', - 'placeholder' => 'Password', - 'id' => 'exampleInputPassword1' - ), - 'options' => array('label' => 'Password',) - ))->add(array( - 'name' => 'input-file', - 'attributes' => array( - 'type' => 'file', - 'id' => 'exampleInputFile' - ), - 'options' => array( - 'label' => 'File input', - 'help-block' => 'Example block-level help text here.' - ) - ))->add(array( - 'name' => 'input-checkbox', - 'type' => 'checkbox', - 'options' => array('label' => 'Check me out') - ))->add(array( - 'name' => 'button-submit', - 'type' => 'button', - 'attributes' => array('type' => 'submit'), - 'options' => array('label' => 'Submit') - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'basic-example.phtml', $this->formHelper->__invoke($oForm, null)); - } - - /** - * Test http://getbootstrap.com/css/#forms-inline - */ - public function testInlineForm() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-email', - 'attributes' => array( - 'type' => 'email', - 'placeholder' => 'Enter email', - 'id' => 'exampleInputEmail2' - ), - 'options' => array('label' => 'Email address', 'showLabel' => false) - ))->add(array( - 'name' => 'input-email2', - 'attributes' => array( - 'type' => 'email2', - 'placeholder' => 'Enter email2', - 'id' => 'exampleInputEmail2a' - ), - 'options' => array('label' => 'Email address2', 'showLabel' => true) - ))->add(array( - 'name' => 'input-password', - 'attributes' => array( - 'type' => 'password', - 'placeholder' => 'Password', - 'id' => 'exampleInputPassword2' - ), - 'options' => array('label' => 'Password') - ))->add(array( - 'name' => 'input-checkbox', - 'type' => 'checkbox', - 'options' => array('label' => 'Remember me') - ))->add(array( - 'name' => 'button-submit', - 'type' => 'button', - 'attributes' => array('type' => 'submit'), - 'options' => array('label' => 'Sign in') - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'inline-form.phtml', $this->formHelper->__invoke($oForm, \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE)); - } - - /** - * Test http://getbootstrap.com/css/#forms-horizontal - */ - public function testHorizontalform() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-email', - 'attributes' => array( - 'type' => 'email', - 'placeholder' => 'Enter email', - 'id' => 'inputEmail1' - ), - 'options' => array( - 'label' => 'Email', - 'column-size' => 'sm-10', - 'label_attributes' => array('class' => 'col-sm-2') - ) - ))->add(array( - 'name' => 'input-password', - 'attributes' => array( - 'type' => 'password', - 'placeholder' => 'Password', - 'id' => 'inputPassword1' - ), - 'options' => array('label' => 'Password', 'column-size' => 'sm-10', 'label_attributes' => array('class' => 'col-sm-2')) - ))->add(array( - 'name' => 'input-checkbox', - 'type' => 'checkbox', - 'options' => array('label' => 'Remember me', 'column-size' => 'sm-10 col-sm-offset-2') - ))->add(array( - 'name' => 'button-submit', - 'type' => 'button', - 'attributes' => array('type' => 'submit'), - 'options' => array('label' => 'Sign in', 'column-size' => 'sm-10 col-sm-offset-2') - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'horizontal-form.phtml', $this->formHelper->__invoke($oForm)); - } - - /** - * Test http://getbootstrap.com/css/#forms-horizontal - */ - public function testHorizontalformButtonGroup() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-email', - 'attributes' => array( - 'type' => 'email', - 'placeholder' => 'Enter email', - 'id' => 'inputEmail1' - ), - 'options' => array( - 'label' => 'Email', - 'column-size' => 'sm-10', - 'label_attributes' => array('class' => 'col-sm-2') - ) - ))->add(array( - 'name' => 'input-password', - 'attributes' => array( - 'type' => 'password', - 'placeholder' => 'Password', - 'id' => 'inputPassword1' - ), - 'options' => array('label' => 'Password', 'column-size' => 'sm-10', 'label_attributes' => array('class' => 'col-sm-2')) - ))->add(array( - 'name' => 'input-checkbox', - 'type' => 'checkbox', - 'options' => array('label' => 'Remember me', 'column-size' => 'sm-10 col-sm-offset-2') - ))->add(array( - 'name' => 'button-submit', - 'type' => 'button', - 'attributes' => array('type' => 'submit'), - 'options' => array('label' => 'Sign in', 'column-size' => 'sm-10 col-sm-offset-2', 'button-group' => 'group-1') - ))->add(array( - 'name' => 'button-reset', - 'type' => 'button', - 'attributes' => array('type' => 'reset'), - 'options' => array('label' => 'Reset form', 'column-size' => 'sm-8 col-sm-offset-4', 'button-group' => 'group-1') - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'horizontal-form-button-group.phtml', $this->formHelper->__invoke($oForm)); - } - - /** - * Test http://getbootstrap.com/css/#forms-controls - */ - public function testSupportedControlsform() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-text', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => 'Text input', - ) - ))->add(array( - 'name' => 'input-text-area', - 'type' => 'textarea', - 'attributes' => array( - 'row' => 3 - ) - ))->add(array( - 'name' => 'input-checkbox', - 'type' => 'checkbox', - 'options' => array('label' => 'Option one is this and that-be sure to include why it\'s great') - ))->add(array( - 'name' => 'optionsRadios', - 'type' => 'radio', - 'options' => array( - 'value_options' => array( - 'option1' => 'Option one is this and that-be sure to include why it\'s great', - 'optionsRadios2' => 'Option two can be something else and selecting it will deselect option one' - ) - ) - ))->add(array( - 'name' => 'optionsRadiosNoInline', - 'type' => 'MultiCheckbox', - 'options' => array( - 'value_options' => array( - array('label' => '1', 'value' => 'option1', 'attributes' => array('id' => 'noInlineCheckbox1')), - array('label' => '2', 'value' => 'option2', 'attributes' => array('id' => 'noInlineCheckbox2')), - array('label' => '3', 'value' => 'option3', 'attributes' => array('id' => 'noInlineCheckbox3')) - ) - ) - ))->add(array( - 'name' => 'optionsRadios', - 'type' => 'MultiCheckbox', - 'options' => array( - 'value_options' => array( - array('label' => '1', 'value' => 'option1', 'attributes' => array('id' => 'inlineCheckbox1')), - array('label' => '2', 'value' => 'option2', 'attributes' => array('id' => 'inlineCheckbox2')), - array('label' => '3', 'value' => 'option3', 'attributes' => array('id' => 'inlineCheckbox3')) - ), - 'inline' => true - ) - ))->add(array( - 'name' => 'select', - 'type' => 'select', - 'options' => array('value_options' => array(1, 2, 3, 4, 5)) - ))->add(array( - 'name' => 'multiple-select', - 'type' => 'select', - 'options' => array('value_options' => array(1, 2, 3, 4, 5)), - 'attributes' => array('multiple' => true) - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'supported-controls-form.phtml', $this->formHelper->__invoke($oForm, null)); - } - - public function testRenderMultiCheckboxInlineWithLabel() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'optionsRadios', - 'type' => 'MultiCheckbox', - 'options' => array( - 'label' => 'Test label', - 'column-size' => 'sm-10', - 'label_attributes' => array('class' => 'col-sm-2'), - 'value_options' => array( - array('label' => '1', 'value' => 'option1', 'attributes' => array('id' => 'inlineCheckbox1')), - array('label' => '2', 'value' => 'option2', 'attributes' => array('id' => 'inlineCheckbox2')), - array('label' => '3', 'value' => 'option3', 'attributes' => array('id' => 'inlineCheckbox3')) - ), - 'inline' => true - ) - )); - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'multi-checkbox-inline.phtml', $this->formHelper->__invoke($oForm)); - } - - /** - * Test http://getbootstrap.com/css/#forms-controls-static - */ - public function testStaticControlform() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'static-element', - 'type' => '\TwbBundle\Form\Element\StaticElement', - 'attributes' => array('value' => 'email@example.com'), - 'options' => array('label' => 'Email', 'column-size' => 'lg-10', 'label_attributes' => array('class' => 'col-lg-2')) - ))->add(array( - 'name' => 'input-password', - 'attributes' => array( - 'type' => 'password', - 'placeholder' => 'Password', - 'id' => 'inputPassword' - ), - 'options' => array('label' => 'Password', 'column-size' => 'lg-10', 'label_attributes' => array('class' => 'col-lg-2')) - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'static-control-form.phtml', $this->formHelper->__invoke($oForm)); - } - - /** - * Test http://getbootstrap.com/css/#forms-control-states - */ - public function testControlStatesform() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-text-disabled', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => 'Disabled input here...', - 'id' => 'disabledInput' - ) - )); - - $oFieldset = new \Laminas\Form\Fieldset('fieldset-disabled'); - $oForm->add($oFieldset->setAttributes(array('disabled' => true))->add(array( - 'name' => 'input-text-disabled', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => 'Disabled input', - 'id' => 'disabledTextInput' - ), - 'options' => array('label' => 'Disabled input') - ))->add(array( - 'name' => 'disabled-select', - 'type' => 'select', - 'options' => array( - 'label' => 'Disabled select menu', - 'value_options' => array('' => 'Disabled select') - ), - 'attributes' => array('id' => 'disabled-select') - ))->add(array( - 'name' => 'input-checkbox', - 'type' => 'checkbox', - 'options' => array('label' => 'Can\'t check this') - ))->add(array( - 'name' => 'button-submit', - 'type' => 'button', - 'attributes' => array('type' => 'submit', 'class' => 'btn-primary'), - 'options' => array('label' => 'Submit') - ))); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'control-states-form.phtml', $this->formHelper->__invoke($oForm, null)); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'control-states-form-horizontal.phtml', $this->formHelper->__invoke($oForm)); - } - - /** - * Test http://getbootstrap.com/css/#forms-validation - */ - public function testFormsValidation() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-text-success', - 'attributes' => array( - 'type' => 'text', - 'id' => 'inputSuccess' - ), - 'options' => array( - 'label' => 'Input with success', - 'validation-state' => 'success' - ) - ))->add(array( - 'name' => 'input-text-warning', - 'attributes' => array( - 'type' => 'text', - 'id' => 'inputWarning' - ), - 'options' => array( - 'label' => 'Input with warning', - 'validation-state' => 'warning' - ) - ))->add(array( - 'name' => 'input-text-error', - 'attributes' => array( - 'type' => 'text', - 'id' => 'inputError' - ), - 'options' => array( - 'label' => 'Input with error', - 'validation-state' => 'error' - ) - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-validation.phtml', $this->formHelper->__invoke($oForm, null)); - } - - /** - * Test http://getbootstrap.com/css/#forms-control-sizes - */ - public function testFormsControlSizes() - { - - //Height sizing - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-text-lg', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => '.input-lg', - 'class' => 'input-lg' - ) - ))->add(array( - 'name' => 'input-text-default', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => 'Default input' - ) - ))->add(array( - 'name' => 'input-text-sm', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => '.input-sm', - 'class' => 'input-sm' - ) - ))->add(array( - 'name' => 'lg-select', - 'type' => 'select', - 'options' => array('value_options' => array('' => '.input-lg')), - 'attributes' => array('class' => 'input-lg') - ))->add(array( - 'name' => 'default-select', - 'type' => 'select', - 'options' => array('value_options' => array('' => 'Default select')) - ))->add(array( - 'name' => 'sm-select', - 'type' => 'select', - 'options' => array('value_options' => array('' => '.input-sm')), - 'attributes' => array('class' => 'input-sm') - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-control-sizes-height.phtml', $this->formHelper->__invoke($oForm, null)); - - //Column sizing - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-text-col-lg-2', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => '.col-lg-2' - ), - 'options' => array('column-size' => 'lg-2') - ))->add(array( - 'name' => 'input-text-col-lg-3', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => '.col-lg-3' - ), - 'options' => array('column-size' => 'lg-3') - ))->add(array( - 'name' => 'input-text-col-lg-4', - 'attributes' => array( - 'type' => 'text', - 'placeholder' => '.col-lg-4' - ), - 'options' => array('column-size' => 'lg-4') - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-control-sizes-column.phtml', $this->formHelper->__invoke($oForm, \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE)); - } - - /** - * Test http://getbootstrap.com/css/#forms-help-text - */ - public function testFormsHelpText() - { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'input-text', - 'attributes' => array('type' => 'text'), - 'options' => array( - 'help-block' => 'A block of help text that breaks onto a new line and may extend beyond one line.' - ) - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-help-text.phtml', $this->formHelper->__invoke($oForm, null)); - } - - /** - * Test errored input rendering - */ - public function testFormsErroredInput() - { - $oForm = new \Laminas\Form\Form(); - $oElement = new \Laminas\Form\Element\Text('input-text'); - $oForm->add($oElement - ->setMessages(array( - 'This is an error message', - 'This is an another one error message' - ))); - - //No form layout - $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-no-layout-errored-input.phtml', $this->formHelper->__invoke($oForm, null)); - - //Horizontal form - $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-horizontal-errored-input.phtml', $this->formHelper->__invoke($oForm)); - - //Horizontal form / input with label - $oElement - ->setOptions(array('column-size' => 'lg-10')) - ->setLabel('Input label') - ->setLabelAttributes(array('class' => 'col-lg-2')); - $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-horizontal-errored-input-with-label.phtml', $this->formHelper->__invoke($oForm)); - } - - public function testFormWithButtonGroups() - { - $oForm = new \Laminas\Form\Form(); - $oForm - ->add(new \Laminas\Form\Element\Text('input-text-1')) - ->add(new \Laminas\Form\Element\Button('input-button-1', array('label' => 'Left', 'button-group' => 'group-1'))) - ->add(new \Laminas\Form\Element\Button('input-button-2', array('label' => 'Right', 'button-group' => 'group-1'))) - ->add(new \Laminas\Form\Element\Button('input-button-3', array('label' => 'Left', 'button-group' => 'group-2'))) - ->add(new \Laminas\Form\Element\Button('input-button-4', array('label' => 'Right', 'button-group' => 'group-2'))) - ->add(new \Laminas\Form\Element\Text('input-text-3')); - - // Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-button-groups.phtml', $this->formHelper->__invoke($oForm)); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) - { - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } -} +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-forms' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formHelper = $oViewHelperPluginManager->get('form')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + /** + * Test http://getbootstrap.com/css/#forms-example + */ + public function testBasicExample() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-email', + 'attributes' => [ + 'type' => 'email', + 'placeholder' => 'Enter email', + 'id' => 'exampleInputEmail1' + ], + 'options' => ['label' => 'Email address'] + ])->add([ + 'name' => 'input-password', + 'attributes' => [ + 'type' => 'password', + 'placeholder' => 'Password', + 'id' => 'exampleInputPassword1' + ], + 'options' => ['label' => 'Password',] + ])->add([ + 'name' => 'input-file', + 'attributes' => [ + 'type' => 'file', + 'id' => 'exampleInputFile' + ], + 'options' => [ + 'label' => 'File input', + 'help-block' => 'Example block-level help text here.' + ] + ])->add([ + 'name' => 'input-checkbox', + 'type' => 'checkbox', + 'options' => ['label' => 'Check me out'] + ])->add([ + 'name' => 'button-submit', + 'type' => 'button', + 'attributes' => ['type' => 'submit'], + 'options' => ['label' => 'Submit'] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'basic-example.phtml', $this->formHelper->__invoke($oForm, null)); + } + + /** + * Test http://getbootstrap.com/css/#forms-inline + */ + public function testInlineForm() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-email', + 'attributes' => [ + 'type' => 'email', + 'placeholder' => 'Enter email', + 'id' => 'exampleInputEmail2' + ], + 'options' => ['label' => 'Email address', 'showLabel' => false] + ])->add([ + 'name' => 'input-email2', + 'attributes' => [ + 'type' => 'email2', + 'placeholder' => 'Enter email2', + 'id' => 'exampleInputEmail2a' + ], + 'options' => ['label' => 'Email address2', 'showLabel' => true] + ])->add([ + 'name' => 'input-password', + 'attributes' => [ + 'type' => 'password', + 'placeholder' => 'Password', + 'id' => 'exampleInputPassword2' + ], + 'options' => ['label' => 'Password'] + ])->add([ + 'name' => 'input-checkbox', + 'type' => 'checkbox', + 'options' => ['label' => 'Remember me'] + ])->add([ + 'name' => 'button-submit', + 'type' => 'button', + 'attributes' => ['type' => 'submit'], + 'options' => ['label' => 'Sign in'] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'inline-form.phtml', $this->formHelper->__invoke($oForm, \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE)); + } + + /** + * Test http://getbootstrap.com/css/#forms-horizontal + */ + public function testHorizontalform() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-email', + 'attributes' => [ + 'type' => 'email', + 'placeholder' => 'Enter email', + 'id' => 'inputEmail1' + ], + 'options' => [ + 'label' => 'Email', + 'column-size' => 'sm-10', + 'label_attributes' => ['class' => 'col-sm-2'] + ] + ])->add([ + 'name' => 'input-password', + 'attributes' => [ + 'type' => 'password', + 'placeholder' => 'Password', + 'id' => 'inputPassword1' + ], + 'options' => ['label' => 'Password', 'column-size' => 'sm-10', 'label_attributes' => ['class' => 'col-sm-2']] + ])->add([ + 'name' => 'input-checkbox', + 'type' => 'checkbox', + 'options' => ['label' => 'Remember me', 'column-size' => 'sm-10 col-sm-offset-2'] + ])->add([ + 'name' => 'button-submit', + 'type' => 'button', + 'attributes' => ['type' => 'submit'], + 'options' => ['label' => 'Sign in', 'column-size' => 'sm-10 col-sm-offset-2'] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'horizontal-form.phtml', $this->formHelper->__invoke($oForm)); + } + + /** + * Test http://getbootstrap.com/css/#forms-horizontal + */ + public function testHorizontalformButtonGroup() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-email', + 'attributes' => [ + 'type' => 'email', + 'placeholder' => 'Enter email', + 'id' => 'inputEmail1' + ], + 'options' => [ + 'label' => 'Email', + 'column-size' => 'sm-10', + 'label_attributes' => ['class' => 'col-sm-2'] + ] + ])->add([ + 'name' => 'input-password', + 'attributes' => [ + 'type' => 'password', + 'placeholder' => 'Password', + 'id' => 'inputPassword1' + ], + 'options' => ['label' => 'Password', 'column-size' => 'sm-10', 'label_attributes' => ['class' => 'col-sm-2']] + ])->add([ + 'name' => 'input-checkbox', + 'type' => 'checkbox', + 'options' => ['label' => 'Remember me', 'column-size' => 'sm-10 col-sm-offset-2'] + ])->add([ + 'name' => 'button-submit', + 'type' => 'button', + 'attributes' => ['type' => 'submit'], + 'options' => ['label' => 'Sign in', 'column-size' => 'sm-10 col-sm-offset-2', 'button-group' => 'group-1'] + ])->add([ + 'name' => 'button-reset', + 'type' => 'button', + 'attributes' => ['type' => 'reset'], + 'options' => ['label' => 'Reset form', 'column-size' => 'sm-8 col-sm-offset-4', 'button-group' => 'group-1'] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'horizontal-form-button-group.phtml', $this->formHelper->__invoke($oForm)); + } + + /** + * Test http://getbootstrap.com/css/#forms-controls + */ + public function testSupportedControlsform() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-text', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => 'Text input', + ] + ])->add([ + 'name' => 'input-text-area', + 'type' => 'textarea', + 'attributes' => [ + 'row' => 3 + ] + ])->add([ + 'name' => 'input-checkbox', + 'type' => 'checkbox', + 'options' => ['label' => 'Option one is this and that-be sure to include why it\'s great'] + ])->add([ + 'name' => 'optionsRadios', + 'type' => 'radio', + 'options' => [ + 'value_options' => [ + 'option1' => 'Option one is this and that-be sure to include why it\'s great', + 'optionsRadios2' => 'Option two can be something else and selecting it will deselect option one' + ] + ] + ])->add([ + 'name' => 'optionsRadiosNoInline', + 'type' => 'MultiCheckbox', + 'options' => [ + 'value_options' => [ + ['label' => '1', 'value' => 'option1', 'attributes' => ['id' => 'noInlineCheckbox1']], + ['label' => '2', 'value' => 'option2', 'attributes' => ['id' => 'noInlineCheckbox2']], + ['label' => '3', 'value' => 'option3', 'attributes' => ['id' => 'noInlineCheckbox3']] + ] + ] + ])->add([ + 'name' => 'optionsRadios', + 'type' => 'MultiCheckbox', + 'options' => [ + 'value_options' => [ + ['label' => '1', 'value' => 'option1', 'attributes' => ['id' => 'inlineCheckbox1']], + ['label' => '2', 'value' => 'option2', 'attributes' => ['id' => 'inlineCheckbox2']], + ['label' => '3', 'value' => 'option3', 'attributes' => ['id' => 'inlineCheckbox3']] + ], + 'inline' => true + ] + ])->add([ + 'name' => 'select', + 'type' => 'select', + 'options' => ['value_options' => [1, 2, 3, 4, 5]] + ])->add([ + 'name' => 'multiple-select', + 'type' => 'select', + 'options' => ['value_options' => [1, 2, 3, 4, 5]], + 'attributes' => ['multiple' => true] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'supported-controls-form.phtml', $this->formHelper->__invoke($oForm, null)); + } + + public function testRenderMultiCheckboxInlineWithLabel() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'optionsRadios', + 'type' => 'MultiCheckbox', + 'options' => [ + 'label' => 'Test label', + 'column-size' => 'sm-10', + 'label_attributes' => ['class' => 'col-sm-2'], + 'value_options' => [ + ['label' => '1', 'value' => 'option1', 'attributes' => ['id' => 'inlineCheckbox1']], + ['label' => '2', 'value' => 'option2', 'attributes' => ['id' => 'inlineCheckbox2']], + ['label' => '3', 'value' => 'option3', 'attributes' => ['id' => 'inlineCheckbox3']] + ], + 'inline' => true + ] + ]); + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'multi-checkbox-inline.phtml', $this->formHelper->__invoke($oForm)); + } + + /** + * Test http://getbootstrap.com/css/#forms-controls-static + */ + public function testStaticControlform() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'static-element', + 'type' => '\TwbBundle\Form\Element\StaticElement', + 'attributes' => ['value' => 'email@example.com'], + 'options' => ['label' => 'Email', 'column-size' => 'lg-10', 'label_attributes' => ['class' => 'col-lg-2']] + ])->add([ + 'name' => 'input-password', + 'attributes' => [ + 'type' => 'password', + 'placeholder' => 'Password', + 'id' => 'inputPassword' + ], + 'options' => ['label' => 'Password', 'column-size' => 'lg-10', 'label_attributes' => ['class' => 'col-lg-2']] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'static-control-form.phtml', $this->formHelper->__invoke($oForm)); + } + + /** + * Test http://getbootstrap.com/css/#forms-control-states + */ + public function testControlStatesform() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-text-disabled', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => 'Disabled input here...', + 'id' => 'disabledInput' + ] + ]); + + $oFieldset = new \Laminas\Form\Fieldset('fieldset-disabled'); + $oForm->add($oFieldset->setAttributes(['disabled' => true])->add([ + 'name' => 'input-text-disabled', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => 'Disabled input', + 'id' => 'disabledTextInput' + ], + 'options' => ['label' => 'Disabled input'] + ])->add([ + 'name' => 'disabled-select', + 'type' => 'select', + 'options' => [ + 'label' => 'Disabled select menu', + 'value_options' => ['' => 'Disabled select'] + ], + 'attributes' => ['id' => 'disabled-select'] + ])->add([ + 'name' => 'input-checkbox', + 'type' => 'checkbox', + 'options' => ['label' => 'Can\'t check this'] + ])->add([ + 'name' => 'button-submit', + 'type' => 'button', + 'attributes' => ['type' => 'submit', 'class' => 'btn-primary'], + 'options' => ['label' => 'Submit'] + ])); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'control-states-form.phtml', $this->formHelper->__invoke($oForm, null)); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'control-states-form-horizontal.phtml', $this->formHelper->__invoke($oForm)); + } + + /** + * Test http://getbootstrap.com/css/#forms-validation + */ + public function testFormsValidation() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-text-success', + 'attributes' => [ + 'type' => 'text', + 'id' => 'inputSuccess' + ], + 'options' => [ + 'label' => 'Input with success', + 'validation-state' => 'success' + ] + ])->add([ + 'name' => 'input-text-warning', + 'attributes' => [ + 'type' => 'text', + 'id' => 'inputWarning' + ], + 'options' => [ + 'label' => 'Input with warning', + 'validation-state' => 'warning' + ] + ])->add([ + 'name' => 'input-text-error', + 'attributes' => [ + 'type' => 'text', + 'id' => 'inputError' + ], + 'options' => [ + 'label' => 'Input with error', + 'validation-state' => 'error' + ] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-validation.phtml', $this->formHelper->__invoke($oForm, null)); + } + + /** + * Test http://getbootstrap.com/css/#forms-control-sizes + */ + public function testFormsControlSizes() + { + + //Height sizing + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-text-lg', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => '.input-lg', + 'class' => 'input-lg' + ] + ])->add([ + 'name' => 'input-text-default', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => 'Default input' + ] + ])->add([ + 'name' => 'input-text-sm', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => '.input-sm', + 'class' => 'input-sm' + ] + ])->add([ + 'name' => 'lg-select', + 'type' => 'select', + 'options' => ['value_options' => ['' => '.input-lg']], + 'attributes' => ['class' => 'input-lg'] + ])->add([ + 'name' => 'default-select', + 'type' => 'select', + 'options' => ['value_options' => ['' => 'Default select']] + ])->add([ + 'name' => 'sm-select', + 'type' => 'select', + 'options' => ['value_options' => ['' => '.input-sm']], + 'attributes' => ['class' => 'input-sm'] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-control-sizes-height.phtml', $this->formHelper->__invoke($oForm, null)); + + //Column sizing + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-text-col-lg-2', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => '.col-lg-2' + ], + 'options' => ['column-size' => 'lg-2'] + ])->add([ + 'name' => 'input-text-col-lg-3', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => '.col-lg-3' + ], + 'options' => ['column-size' => 'lg-3'] + ])->add([ + 'name' => 'input-text-col-lg-4', + 'attributes' => [ + 'type' => 'text', + 'placeholder' => '.col-lg-4' + ], + 'options' => ['column-size' => 'lg-4'] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-control-sizes-column.phtml', $this->formHelper->__invoke($oForm, \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE)); + } + + /** + * Test http://getbootstrap.com/css/#forms-help-text + */ + public function testFormsHelpText() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'input-text', + 'attributes' => ['type' => 'text'], + 'options' => [ + 'help-block' => 'A block of help text that breaks onto a new line and may extend beyond one line.' + ] + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-help-text.phtml', $this->formHelper->__invoke($oForm, null)); + } + + /** + * Test errored input rendering + */ + public function testFormsErroredInput() + { + $oForm = new \Laminas\Form\Form(); + $oElement = new \Laminas\Form\Element\Text('input-text'); + $oForm->add($oElement + ->setMessages([ + 'This is an error message', + 'This is an another one error message' + ])); + + //No form layout + $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-no-layout-errored-input.phtml', $this->formHelper->__invoke($oForm, null)); + + //Horizontal form + $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-horizontal-errored-input.phtml', $this->formHelper->__invoke($oForm)); + + //Horizontal form / input with label + $oElement + ->setOptions(['column-size' => 'lg-10']) + ->setLabel('Input label') + ->setLabelAttributes(['class' => 'col-lg-2']); + $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-horizontal-errored-input-with-label.phtml', $this->formHelper->__invoke($oForm)); + } + + public function testFormWithButtonGroups() + { + $oForm = new \Laminas\Form\Form(); + $oForm + ->add(new \Laminas\Form\Element\Text('input-text-1')) + ->add(new \Laminas\Form\Element\Button('input-button-1', ['label' => 'Left', 'button-group' => 'group-1'])) + ->add(new \Laminas\Form\Element\Button('input-button-2', ['label' => 'Right', 'button-group' => 'group-1'])) + ->add(new \Laminas\Form\Element\Button('input-button-3', ['label' => 'Left', 'button-group' => 'group-2'])) + ->add(new \Laminas\Form\Element\Button('input-button-4', ['label' => 'Right', 'button-group' => 'group-2'])) + ->add(new \Laminas\Form\Element\Text('input-text-3')); + + // Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'forms-button-groups.phtml', $this->formHelper->__invoke($oForm)); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleGlyphiconsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleGlyphiconsTest.php index af40f9c..fdbfab3 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleGlyphiconsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleGlyphiconsTest.php @@ -1,96 +1,101 @@ -expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-glyphicons' . DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - - //Initialize glyphicon helper - $this->glyphiconHelper = $oViewHelperPluginManager->get('glyphicon')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - - //Initialize form button helper - $this->formButtonHelper = $oViewHelperPluginManager->get('formButton')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - /** - * Test http://getbootstrap.com/components/#glyphicons-how-to-use - */ - public function testHowToUse() { - $this->twbAssertStringEqualsFile($this->expectedPath . 'how-to-use.phtml', $this->glyphiconHelper->__invoke('search')); - } - - /** - * Test http://getbootstrap.com/components/#glyphicons-examples - */ - public function testExamples() { - $sContent = ''; - - //Align left - $sContent .= $this->formButtonHelper->__invoke(new \Laminas\Form\Element\Button('align-left', array('glyphicon' => 'align-left'))) . "\n"; - - //Align center - $sContent .= $this->formButtonHelper->__invoke(new \Laminas\Form\Element\Button('align-left', array('glyphicon' => 'align-center'))) . "\n"; - - //Align right - $sContent .= $this->formButtonHelper->__invoke(new \Laminas\Form\Element\Button('align-left', array('glyphicon' => 'align-right'))) . "\n"; - - //Large - $oButton = new \Laminas\Form\Element\Button('large-button-default', array('label' => 'Star', 'glyphicon' => 'star')); - $oButton->setAttribute('class', 'btn-lg'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Default - $oButton = new \Laminas\Form\Element\Button('button-default', array('label' => 'Star', 'glyphicon' => 'star')); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Small - $oButton = new \Laminas\Form\Element\Button('small-button-default', array('label' => 'Star', 'glyphicon' => 'star')); - $oButton->setAttribute('class', 'btn-sm'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - //Extra small - $oButton = new \Laminas\Form\Element\Button('extra-small-button-default', array('label' => 'Star', 'glyphicon' => 'star')); - $oButton->setAttribute('class', 'btn-xs'); - $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; - - $this->twbAssertStringEqualsFile($this->expectedPath . 'examples.phtml', $sContent); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) { - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } - -} +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-glyphicons' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + + //Initialize glyphicon helper + $this->glyphiconHelper = $oViewHelperPluginManager->get('glyphicon')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + + //Initialize form button helper + $this->formButtonHelper = $oViewHelperPluginManager->get('formButton')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + /** + * Test http://getbootstrap.com/components/#glyphicons-how-to-use + */ + public function testHowToUse() + { + $this->twbAssertStringEqualsFile($this->expectedPath . 'how-to-use.phtml', $this->glyphiconHelper->__invoke('search')); + } + + /** + * Test http://getbootstrap.com/components/#glyphicons-examples + */ + public function testExamples() + { + $sContent = ''; + + //Align left + $sContent .= $this->formButtonHelper->__invoke(new \Laminas\Form\Element\Button('align-left', ['glyphicon' => 'align-left'])) . "\n"; + + //Align center + $sContent .= $this->formButtonHelper->__invoke(new \Laminas\Form\Element\Button('align-left', ['glyphicon' => 'align-center'])) . "\n"; + + //Align right + $sContent .= $this->formButtonHelper->__invoke(new \Laminas\Form\Element\Button('align-left', ['glyphicon' => 'align-right'])) . "\n"; + + //Large + $oButton = new \Laminas\Form\Element\Button('large-button-default', ['label' => 'Star', 'glyphicon' => 'star']); + $oButton->setAttribute('class', 'btn-lg'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Default + $oButton = new \Laminas\Form\Element\Button('button-default', ['label' => 'Star', 'glyphicon' => 'star']); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Small + $oButton = new \Laminas\Form\Element\Button('small-button-default', ['label' => 'Star', 'glyphicon' => 'star']); + $oButton->setAttribute('class', 'btn-sm'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + //Extra small + $oButton = new \Laminas\Form\Element\Button('extra-small-button-default', ['label' => 'Star', 'glyphicon' => 'star']); + $oButton->setAttribute('class', 'btn-xs'); + $sContent .= $this->formButtonHelper->__invoke($oButton) . "\n"; + + $this->twbAssertStringEqualsFile($this->expectedPath . 'examples.phtml', $sContent); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } + +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleInputGroupsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleInputGroupsTest.php index 4d7f996..916198d 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleInputGroupsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleInputGroupsTest.php @@ -1,176 +1,185 @@ -expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-input-groups' . DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formElementHelper = $oViewHelperPluginManager->get('formElement')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - /** - * Test http://getbootstrap.com/components/#input-groups-basic - */ - public function testBasicExample() { - $sContent = ''; - - $oInput = new \Laminas\Form\Element\Text('input-prepend', array('add-on-prepend' => '@')); - $oInput->setAttribute('placeholder', 'Username'); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - $oInput = new \Laminas\Form\Element\Text('input-append', array('add-on-append' => '.00')); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - $oInput = new \Laminas\Form\Element\Text('input-append-prepend', array('add-on-prepend' => '$', 'add-on-append' => '.00')); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-basic.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#input-groups-sizing - */ - public function testSizing() { - $sContent = ''; - - //Large - $oInput = new \Laminas\Form\Element\Text('input-prepend', array('add-on-prepend' => '@')); - $oInput->setAttributes(array('placeholder' => 'Username', 'class' => 'input-lg')); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Default - $oInput = new \Laminas\Form\Element\Text('input-prepend', array('add-on-prepend' => '@')); - $oInput->setAttribute('placeholder', 'Username'); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Small - $oInput = new \Laminas\Form\Element\Text('input-prepend', array('add-on-prepend' => '@')); - $oInput->setAttributes(array('placeholder' => 'Username', 'class' => 'input-sm')); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-sizing.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#input-groups-checkboxes-radios - */ - public function testCheckboxesAndRadioAddons() { - $sContent = ''; - - //Checkbox - $oInput = new \Laminas\Form\Element\Text('input-username', array('add-on-prepend' => new \Laminas\Form\Element\Checkbox('checkbox'))); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Radio - $oInput = new \Laminas\Form\Element\Text('input-username', array('add-on-prepend' => new \Laminas\Form\Element\Radio('radio', array('value_options' => array(1 => ''))))); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-checkboxes-radios.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#input-groups-buttons - */ - public function testButtonAddons() { - $sContent = ''; - - //Prepend - $oInput = new \Laminas\Form\Element\Text('input-username', array('add-on-prepend' => new \Laminas\Form\Element\Button('prepend-button', array('label' => 'Go!')))); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Append - $oInput = new \Laminas\Form\Element\Text('input-username', array('add-on-append' => new \Laminas\Form\Element\Button('append-button', array('label' => 'Go!')))); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-buttons.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#input-groups-buttons-dropdowns - */ - public function testButtonsWithDropdowns() { - $aButtonOptions = array('label' => 'Action', 'dropdown' => array( - 'label' => 'Dropdown', - 'name' => 'dropdownMenu1', - 'attributes' => array('class' => 'clearfix'), - 'list_attributes' => array('aria-labelledby' => 'dropdownMenu1'), - 'items' => array('Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link') - )); - - $sContent = ''; - - //Prepend - $oInput = new \Laminas\Form\Element\Text('input-username', array('add-on-prepend' => new \Laminas\Form\Element\Button('prepend-button', $aButtonOptions))); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Append - $oInput = new \Laminas\Form\Element\Text('input-username', array('add-on-append' => new \Laminas\Form\Element\Button('append-button', $aButtonOptions))); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-buttons-dropdowns.phtml', $sContent); - } - - /** - * Test http://getbootstrap.com/components/#input-groups-buttons-segmented - */ - public function testSegmentedButtons() { - $aButtonOptions = array('label' => 'Action', 'dropdown' => array( - 'label' => 'Dropdown', - 'name' => 'dropdownMenu1', - 'split' => true, - 'attributes' => array('class' => 'clearfix'), - 'list_attributes' => array('aria-labelledby' => 'dropdownMenu1'), - 'items' => array('Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link') - )); - - $sContent = ''; - - //Prepend - $oInput = new \Laminas\Form\Element\Text('input-username', array('add-on-prepend' => new \Laminas\Form\Element\Button('prepend-button', $aButtonOptions))); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Append - $oInput = new \Laminas\Form\Element\Text('input-username', array('add-on-append' => new \Laminas\Form\Element\Button('append-button', $aButtonOptions))); - $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-buttons-segmented.phtml', $sContent); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) { - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } - -} +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-input-groups' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formElementHelper = $oViewHelperPluginManager->get('formElement')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + /** + * Test http://getbootstrap.com/components/#input-groups-basic + */ + public function testBasicExample() + { + $sContent = ''; + + $oInput = new \Laminas\Form\Element\Text('input-prepend', ['add-on-prepend' => '@']); + $oInput->setAttribute('placeholder', 'Username'); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + $oInput = new \Laminas\Form\Element\Text('input-append', ['add-on-append' => '.00']); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + $oInput = new \Laminas\Form\Element\Text('input-append-prepend', ['add-on-prepend' => '$', 'add-on-append' => '.00']); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-basic.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#input-groups-sizing + */ + public function testSizing() + { + $sContent = ''; + + //Large + $oInput = new \Laminas\Form\Element\Text('input-prepend', ['add-on-prepend' => '@']); + $oInput->setAttributes(['placeholder' => 'Username', 'class' => 'input-lg']); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Default + $oInput = new \Laminas\Form\Element\Text('input-prepend', ['add-on-prepend' => '@']); + $oInput->setAttribute('placeholder', 'Username'); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Small + $oInput = new \Laminas\Form\Element\Text('input-prepend', ['add-on-prepend' => '@']); + $oInput->setAttributes(['placeholder' => 'Username', 'class' => 'input-sm']); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-sizing.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#input-groups-checkboxes-radios + */ + public function testCheckboxesAndRadioAddons() + { + $sContent = ''; + + //Checkbox + $oInput = new \Laminas\Form\Element\Text('input-username', ['add-on-prepend' => new \Laminas\Form\Element\Checkbox('checkbox')]); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Radio + $oInput = new \Laminas\Form\Element\Text('input-username', ['add-on-prepend' => new \Laminas\Form\Element\Radio('radio', ['value_options' => [1 => '']])]); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-checkboxes-radios.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#input-groups-buttons + */ + public function testButtonAddons() + { + $sContent = ''; + + //Prepend + $oInput = new \Laminas\Form\Element\Text('input-username', ['add-on-prepend' => new \Laminas\Form\Element\Button('prepend-button', ['label' => 'Go!'])]); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Append + $oInput = new \Laminas\Form\Element\Text('input-username', ['add-on-append' => new \Laminas\Form\Element\Button('append-button', ['label' => 'Go!'])]); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-buttons.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#input-groups-buttons-dropdowns + */ + public function testButtonsWithDropdowns() + { + $aButtonOptions = ['label' => 'Action', 'dropdown' => [ + 'label' => 'Dropdown', + 'name' => 'dropdownMenu1', + 'attributes' => ['class' => 'clearfix'], + 'list_attributes' => ['aria-labelledby' => 'dropdownMenu1'], + 'items' => ['Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link'] + ]]; + + $sContent = ''; + + //Prepend + $oInput = new \Laminas\Form\Element\Text('input-username', ['add-on-prepend' => new \Laminas\Form\Element\Button('prepend-button', $aButtonOptions)]); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Append + $oInput = new \Laminas\Form\Element\Text('input-username', ['add-on-append' => new \Laminas\Form\Element\Button('append-button', $aButtonOptions)]); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-buttons-dropdowns.phtml', $sContent); + } + + /** + * Test http://getbootstrap.com/components/#input-groups-buttons-segmented + */ + public function testSegmentedButtons() + { + $aButtonOptions = ['label' => 'Action', 'dropdown' => [ + 'label' => 'Dropdown', + 'name' => 'dropdownMenu1', + 'split' => true, + 'attributes' => ['class' => 'clearfix'], + 'list_attributes' => ['aria-labelledby' => 'dropdownMenu1'], + 'items' => ['Action', 'Another action', 'Something else here', \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, 'Separated link'] + ]]; + + $sContent = ''; + + //Prepend + $oInput = new \Laminas\Form\Element\Text('input-username', ['add-on-prepend' => new \Laminas\Form\Element\Button('prepend-button', $aButtonOptions)]); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Append + $oInput = new \Laminas\Form\Element\Text('input-username', ['add-on-append' => new \Laminas\Form\Element\Button('append-button', $aButtonOptions)]); + $sContent .= $this->formElementHelper->__invoke($oInput) . "\n"; + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'input-groups-buttons-segmented.phtml', $sContent); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } + +} diff --git a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleLabelsTest.php b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleLabelsTest.php index 0225060..2926e2c 100644 --- a/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleLabelsTest.php +++ b/tests/TwbBundleTest/BootstrapBasedTests/TwbBundleLabelsTest.php @@ -1,53 +1,57 @@ -expectedPath = __DIR__.DIRECTORY_SEPARATOR.'../../_files/expected-labels'.DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->labelHelper = $oViewHelperPluginManager->get('label')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testAvailableVariations(){ - $sContent = ''; - - //Default - $sContent .= $this->labelHelper->__invoke('Default','label-default')."\n"; - - //Primary - $sContent .= $this->labelHelper->__invoke('Primary','label-primary')."\n"; - - //Success - $sContent .= $this->labelHelper->__invoke('Success','label-success')."\n"; - - //Info - $sContent .= $this->labelHelper->__invoke('Info','label-info')."\n"; - - //Warning - $sContent .= $this->labelHelper->__invoke('Warning','label-warning')."\n"; - - //Danger - $sContent .= $this->labelHelper->__invoke('Danger','label-danger')."\n"; - - //Test content - file_put_contents($this->expectedPath.'available-variations.phtml',$sContent); - $this->assertStringEqualsFile($this->expectedPath.'available-variations.phtml',$sContent); - } -} \ No newline at end of file +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../_files/expected-labels' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->labelHelper = $oViewHelperPluginManager->get('label')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testAvailableVariations() + { + $sContent = ''; + + //Default + $sContent .= $this->labelHelper->__invoke('Default', 'label-default') . "\n"; + + //Primary + $sContent .= $this->labelHelper->__invoke('Primary', 'label-primary') . "\n"; + + //Success + $sContent .= $this->labelHelper->__invoke('Success', 'label-success') . "\n"; + + //Info + $sContent .= $this->labelHelper->__invoke('Info', 'label-info') . "\n"; + + //Warning + $sContent .= $this->labelHelper->__invoke('Warning', 'label-warning') . "\n"; + + //Danger + $sContent .= $this->labelHelper->__invoke('Danger', 'label-danger') . "\n"; + + //Test content + file_put_contents($this->expectedPath . 'available-variations.phtml', $sContent); + $this->assertStringEqualsFile($this->expectedPath . 'available-variations.phtml', $sContent); + } +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormButtonTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormButtonTest.php index babe890..8ec320d 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormButtonTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormButtonTest.php @@ -1,91 +1,94 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formButtonHelper = $oViewHelperPluginManager->get('formButton')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderElementWithEmptyButtonContentandLabel() - { - $this->expectException(\DomainException::class); - - $this->formButtonHelper->render(new \Laminas\Form\Element(null, array('dropdown' => array('test')))); - } - - public function testRenderWithUndefinedButtonClass() - { - $oElement = new \Laminas\Form\Element('test', array('label' => 'test')); - $oElement->setAttribute('class', 'test'); - $this->assertEquals('', $this->formButtonHelper->render($oElement)); - } - - public function testRenderWithWrongTypeGlyphiconOption() - { - $this->expectException(\LogicException::class); - - $this->formButtonHelper->render(new \Laminas\Form\Element('test', array('glyphicon' => new \stdClass()))); - } - - public function testRenderWithWrongTypeGlyphiconIconOption() - { - $this->expectException(\LogicException::class); - $this->formButtonHelper->render(new \Laminas\Form\Element('test', array('glyphicon' => array('icon' => new \stdClass())))); - } - - public function testRenderWithEmptyGlyphiconPositionOption() - { - $this->assertEquals( - '', $this->formButtonHelper->render(new \Laminas\Form\Element('test', array('glyphicon' => array('icon' => 'test')))) - ); - } - - public function testRenderWithEmptyFontAwesomePositionOption() - { - $this->assertEquals( - '', $this->formButtonHelper->render(new \Laminas\Form\Element('test', array('fontAwesome' => array('icon' => 'test')))) - ); - } - - public function testRenderWithWrongTypeGlyphiconPositionOption() - { - $this->expectException(\LogicException::class); - $this->formButtonHelper->render(new \Laminas\Form\Element('test', array('glyphicon' => array('icon' => 'test', 'position' => new \stdClass())))); - } - - public function testRenderWithWrongGlyphiconPositionOption() - { - $this->expectException(\LogicException::class); - $this->formButtonHelper->render(new \Laminas\Form\Element('test', array('glyphicon' => array('icon' => 'test', 'position' => 'wrong')))); - } - - public function testRenderWithAppendGlyphiconPositionOption() - { - $this->assertEquals( - '', $this->formButtonHelper->render(new \Laminas\Form\Element('test', array( - 'label' => 'test', - 'glyphicon' => array('icon' => 'test', 'position' => \TwbBundle\Form\View\Helper\TwbBundleFormButton::ICON_APPEND,) - ))) - ); - } - - public function testRenderWithWrongTypeDropdownOption() - { - $this->expectException(\LogicException::class); - $this->formButtonHelper->render(new \Laminas\Form\Element('test', array('label' => 'test', 'dropdown' => new \stdClass()))); - } -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formButtonHelper = $oViewHelperPluginManager->get('formButton')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderElementWithEmptyButtonContentandLabel() + { + $this->expectException(\DomainException::class); + + $this->formButtonHelper->render(new \Laminas\Form\Element(null, ['dropdown' => ['test']])); + } + + public function testRenderWithUndefinedButtonClass() + { + $oElement = new \Laminas\Form\Element('test', ['label' => 'test']); + $oElement->setAttribute('class', 'test'); + $this->assertEquals('', $this->formButtonHelper->render($oElement)); + } + + public function testRenderWithWrongTypeGlyphiconOption() + { + $this->expectException(\LogicException::class); + + $this->formButtonHelper->render(new \Laminas\Form\Element('test', ['glyphicon' => new \stdClass()])); + } + + public function testRenderWithWrongTypeGlyphiconIconOption() + { + $this->expectException(\LogicException::class); + $this->formButtonHelper->render(new \Laminas\Form\Element('test', ['glyphicon' => ['icon' => new \stdClass()]])); + } + + public function testRenderWithEmptyGlyphiconPositionOption() + { + $this->assertEquals( + '', + $this->formButtonHelper->render(new \Laminas\Form\Element('test', ['glyphicon' => ['icon' => 'test']])) + ); + } + + public function testRenderWithEmptyFontAwesomePositionOption() + { + $this->assertEquals( + '', + $this->formButtonHelper->render(new \Laminas\Form\Element('test', ['fontAwesome' => ['icon' => 'test']])) + ); + } + + public function testRenderWithWrongTypeGlyphiconPositionOption() + { + $this->expectException(\LogicException::class); + $this->formButtonHelper->render(new \Laminas\Form\Element('test', ['glyphicon' => ['icon' => 'test', 'position' => new \stdClass()]])); + } + + public function testRenderWithWrongGlyphiconPositionOption() + { + $this->expectException(\LogicException::class); + $this->formButtonHelper->render(new \Laminas\Form\Element('test', ['glyphicon' => ['icon' => 'test', 'position' => 'wrong']])); + } + + public function testRenderWithAppendGlyphiconPositionOption() + { + $this->assertEquals( + '', + $this->formButtonHelper->render(new \Laminas\Form\Element('test', [ + 'label' => 'test', + 'glyphicon' => ['icon' => 'test', 'position' => \TwbBundle\Form\View\Helper\TwbBundleFormButton::ICON_APPEND,] + ])) + ); + } + + public function testRenderWithWrongTypeDropdownOption() + { + $this->expectException(\LogicException::class); + $this->formButtonHelper->render(new \Laminas\Form\Element('test', ['label' => 'test', 'dropdown' => new \stdClass()])); + } +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCheckboxTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCheckboxTest.php index a83adf3..1fec5d4 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCheckboxTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCheckboxTest.php @@ -1,46 +1,50 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formCheckboxHelper = $oViewHelperPluginManager->get('formCheckbox')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderElementWithWrongElement() - { - $this->expectException(\InvalidArgumentException::class); - $this->formCheckboxHelper->render(new \Laminas\Form\Element()); - } - - public function testRenderElementWithEmptyName() - { - $this->expectException(\LogicException::class); - $this->formCheckboxHelper->render(new \Laminas\Form\Element\Checkbox('')); - } - - public function testRenderWithLabelPrepend() { - $this->assertEquals('', $this->formCheckboxHelper->render(new \Laminas\Form\Element\Checkbox('prepend', array( - 'label' => 'Prepend label', - 'label_options' => array('position' => \Laminas\Form\View\Helper\FormRow::LABEL_PREPEND) - )))); - } - - public function testRenderWithCheckedElement() { - $oCheckbox = new \Laminas\Form\Element\Checkbox('checked'); - $oCheckbox->setChecked(true); - $this->assertEquals('', $this->formCheckboxHelper->render($oCheckbox)); - } - -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formCheckboxHelper = $oViewHelperPluginManager->get('formCheckbox')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderElementWithWrongElement() + { + $this->expectException(\InvalidArgumentException::class); + $this->formCheckboxHelper->render(new \Laminas\Form\Element()); + } + + public function testRenderElementWithEmptyName() + { + $this->expectException(\LogicException::class); + $this->formCheckboxHelper->render(new \Laminas\Form\Element\Checkbox('')); + } + + public function testRenderWithLabelPrepend() + { + $this->assertEquals('', $this->formCheckboxHelper->render(new \Laminas\Form\Element\Checkbox('prepend', [ + 'label' => 'Prepend label', + 'label_options' => ['position' => \Laminas\Form\View\Helper\FormRow::LABEL_PREPEND] + ]))); + } + + public function testRenderWithCheckedElement() + { + $oCheckbox = new \Laminas\Form\Element\Checkbox('checked'); + $oCheckbox->setChecked(true); + $this->assertEquals('', $this->formCheckboxHelper->render($oCheckbox)); + } + +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCollectionTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCollectionTest.php index b33a264..d88bd1c 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCollectionTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormCollectionTest.php @@ -1,87 +1,97 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formCollectionHelper = $oViewHelperPluginManager->get('formCollection')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderWithPluginFunctionUnavailable() { - $this->formCollectionHelper->setView(new \Laminas\View\Renderer\FeedRenderer()); - $this->assertEquals('', $this->formCollectionHelper->render(new \Laminas\Form\Element\Collection(null, array('label' => 'test-element')))); - } - - public function testRenderWithShouldWrap() { - $this->formCollectionHelper->setShouldWrap(true); - $this->assertEquals( - '
    test-element
    ', $this->formCollectionHelper->render(new \Laminas\Form\Element\Collection(null, array('label' => 'test-element'))) - ); - } - - public function testRenderWithShouldCreateTemplate() { - $oElement = new \Laminas\Form\Element('test'); - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'test-collection', - 'type' => 'Laminas\Form\Element\Collection', - 'options' => array( - 'should_create_template' => true, - 'target_element' => $oElement - ) - )); - $this->assertEquals( - '
    ', preg_replace('/<\/span>/', '', $this->formCollectionHelper->render($oForm->get('test-collection'))) - ); - } - - public function testRenderInlineFieldsetWithAlreadyDefinedClass() { - $oFieldset = new \Laminas\Form\Fieldset('inline-fieldset', array('twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE)); - $oFieldset->setAttributes(array('id' => 'inline-fieldset', 'class' => 'test-class')); - - $oFieldset->add(array( - 'name' => 'input-one', - 'attributes' => array('placeholder' => 'input-one'), - 'options' => array('label' => '') - ))->add(array( - 'name' => 'input-two', - 'attributes' => array('placeholder' => 'input-two'), - 'options' => array('label' => '') - )); - - $oCollection = new \Laminas\Form\Element\Collection('inline-collection', array( - 'twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE - )); - $oCollection->add($oFieldset)->setAttributes(array('id' => 'inline-collection')); - - $oForm = new \Laminas\Form\Form(); - $oForm->add($oCollection); - - $this->twbAssertStringEqualsFile( - __DIR__ . DIRECTORY_SEPARATOR . '../../../../_files/expected-fieldsets/inline-fieldset.html', $this->formCollectionHelper->__invoke($oForm->get('inline-collection'), false) - ); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) { - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } - -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formCollectionHelper = $oViewHelperPluginManager->get('formCollection')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderWithPluginFunctionUnavailable() + { + $this->formCollectionHelper->setView(new \Laminas\View\Renderer\FeedRenderer()); + $this->assertEquals('', $this->formCollectionHelper->render(new \Laminas\Form\Element\Collection(null, ['label' => 'test-element']))); + } + + public function testRenderWithShouldWrap() + { + $this->formCollectionHelper->setShouldWrap(true); + $this->assertEquals( + '
    test-element
    ', + $this->formCollectionHelper->render(new \Laminas\Form\Element\Collection(null, ['label' => 'test-element'])) + ); + } + + public function testRenderWithShouldCreateTemplate() + { + $oElement = new \Laminas\Form\Element('test'); + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'test-collection', + 'type' => 'Laminas\Form\Element\Collection', + 'options' => [ + 'should_create_template' => true, + 'target_element' => $oElement + ] + ]); + $this->assertEquals( + '
    ', + preg_replace('/<\/span>/', '', $this->formCollectionHelper->render($oForm->get('test-collection'))) + ); + } + + public function testRenderInlineFieldsetWithAlreadyDefinedClass() + { + $oFieldset = new \Laminas\Form\Fieldset('inline-fieldset', ['twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE]); + $oFieldset->setAttributes(['id' => 'inline-fieldset', 'class' => 'test-class']); + + $oFieldset->add([ + 'name' => 'input-one', + 'attributes' => ['placeholder' => 'input-one'], + 'options' => ['label' => ''] + ])->add([ + 'name' => 'input-two', + 'attributes' => ['placeholder' => 'input-two'], + 'options' => ['label' => ''] + ]); + + $oCollection = new \Laminas\Form\Element\Collection('inline-collection', [ + 'twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE + ]); + $oCollection->add($oFieldset)->setAttributes(['id' => 'inline-collection']); + + $oForm = new \Laminas\Form\Form(); + $oForm->add($oCollection); + + $this->twbAssertStringEqualsFile( + __DIR__ . DIRECTORY_SEPARATOR . '../../../../_files/expected-fieldsets/inline-fieldset.html', + $this->formCollectionHelper->__invoke($oForm->get('inline-collection'), false) + ); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } + +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormElementTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormElementTest.php index b11ba63..b9a0425 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormElementTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormElementTest.php @@ -1,107 +1,115 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formElementHelper = $oViewHelperPluginManager->get('formElement')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderAddOnWithEmptuOption() - { - $this->expectException(\InvalidArgumentException::class); - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); - $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); - $oReflectionMethod->setAccessible(true); - $oReflectionMethod->invoke($this->formElementHelper, ''); - } - - public function testRenderAddOnWithWrongTypeOption() - { - $this->expectException(\InvalidArgumentException::class); - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); - $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); - $oReflectionMethod->setAccessible(true); - $oReflectionMethod->invoke($this->formElementHelper, new \stdClass()); - } - - public function testRenderAddOnWithoutTranslator() { - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); - $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); - $oReflectionMethod->setAccessible(true); - - //Unset tranlator - $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslator(null)); - $this->assertFalse($this->formElementHelper->hasTranslator()); - - $this->assertEquals('test', $oReflectionMethod->invoke($this->formElementHelper, 'test')); - - //Set translator - $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslator(\TwbBundleTest\Bootstrap::getServiceManager()->get('MVCTranslator'))); - $this->assertTrue($this->formElementHelper->hasTranslator()); - } - - public function testRenderAddOnWithElementAsArray() { - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); - $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); - $oReflectionMethod->setAccessible(true); - $this->assertEquals( - '', $oReflectionMethod->invoke($this->formElementHelper, array('element' => array('name' => 'test-element'))) - ); - } - - public function testRenderAddOnWithWrongTypeElement() - { - $this->expectException(\LogicException::class); - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); - $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); - $oReflectionMethod->setAccessible(true); - $oReflectionMethod->invoke($this->formElementHelper, array('element' => new \stdClass())); - } - - public function testRenderAddOnWithWrongTypeText() - { - $this->expectException(\LogicException::class); - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); - $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); - $oReflectionMethod->setAccessible(true); - $oReflectionMethod->invoke($this->formElementHelper, array('text' => new \stdClass())); - } - - public function testSetTranslatorEnabled() { - $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslatorEnabled(false)); - $this->assertFalse($this->formElementHelper->isTranslatorEnabled()); - - $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslatorEnabled(true)); - $this->assertTrue($this->formElementHelper->isTranslatorEnabled()); - } - - public function testSetTranslatorWithTextDomain() { - $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslator($this->formElementHelper->getTranslator(), 'test')); - $this->assertEquals('test', $this->formElementHelper->getTranslatorTextDomain()); - } - - public function testSetTranslatorTextDomain() { - $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslatorTextDomain('test')); - $this->assertEquals('test', $this->formElementHelper->getTranslatorTextDomain()); - - $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslatorTextDomain()); - $this->assertEquals('default', $this->formElementHelper->getTranslatorTextDomain()); - } - -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formElementHelper = $oViewHelperPluginManager->get('formElement')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderAddOnWithEmptuOption() + { + $this->expectException(\InvalidArgumentException::class); + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); + $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); + $oReflectionMethod->setAccessible(true); + $oReflectionMethod->invoke($this->formElementHelper, ''); + } + + public function testRenderAddOnWithWrongTypeOption() + { + $this->expectException(\InvalidArgumentException::class); + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); + $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); + $oReflectionMethod->setAccessible(true); + $oReflectionMethod->invoke($this->formElementHelper, new \stdClass()); + } + + public function testRenderAddOnWithoutTranslator() + { + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); + $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); + $oReflectionMethod->setAccessible(true); + + //Unset tranlator + $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslator(null)); + $this->assertFalse($this->formElementHelper->hasTranslator()); + + $this->assertEquals('test', $oReflectionMethod->invoke($this->formElementHelper, 'test')); + + //Set translator + $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslator(\TwbBundleTest\Bootstrap::getServiceManager()->get('MVCTranslator'))); + $this->assertTrue($this->formElementHelper->hasTranslator()); + } + + public function testRenderAddOnWithElementAsArray() + { + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); + $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); + $oReflectionMethod->setAccessible(true); + $this->assertEquals( + '', + $oReflectionMethod->invoke($this->formElementHelper, ['element' => ['name' => 'test-element']]) + ); + } + + public function testRenderAddOnWithWrongTypeElement() + { + $this->expectException(\LogicException::class); + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); + $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); + $oReflectionMethod->setAccessible(true); + $oReflectionMethod->invoke($this->formElementHelper, ['element' => new \stdClass()]); + } + + public function testRenderAddOnWithWrongTypeText() + { + $this->expectException(\LogicException::class); + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormElement'); + $oReflectionMethod = $oReflectionClass->getMethod('renderAddOn'); + $oReflectionMethod->setAccessible(true); + $oReflectionMethod->invoke($this->formElementHelper, ['text' => new \stdClass()]); + } + + public function testSetTranslatorEnabled() + { + $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslatorEnabled(false)); + $this->assertFalse($this->formElementHelper->isTranslatorEnabled()); + + $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslatorEnabled(true)); + $this->assertTrue($this->formElementHelper->isTranslatorEnabled()); + } + + public function testSetTranslatorWithTextDomain() + { + $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslator($this->formElementHelper->getTranslator(), 'test')); + $this->assertEquals('test', $this->formElementHelper->getTranslatorTextDomain()); + } + + public function testSetTranslatorTextDomain() + { + $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslatorTextDomain('test')); + $this->assertEquals('test', $this->formElementHelper->getTranslatorTextDomain()); + + $this->assertSame($this->formElementHelper, $this->formElementHelper->setTranslatorTextDomain()); + $this->assertEquals('default', $this->formElementHelper->getTranslatorTextDomain()); + } + +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormErrorsTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormErrorsTest.php index 0c96890..5def4ae 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormErrorsTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormErrorsTest.php @@ -1,182 +1,190 @@ -getFormErrorsHelper(); - } - - /** - * Enforces that the correct helpers is being initialised. - * @param \TwbBundle\Form\View\Helper\TwbBundleFormErrors $oFormErrorsHelper - * @return \TwbBundleTest\Form\View\Helper\TwbBundleFormErrorsTest - */ - public function setFormErrorsHelper(\TwbBundle\Form\View\Helper\TwbBundleFormErrors $oFormErrorsHelper = null) { - $this->formErrorsHelper = $oFormErrorsHelper; - return $this; - } - - /** - * Gets or initialises the correct helper for this test. - * @return \TwbBundle\Form\View\Helper\TwbBundleFormErrors - */ - public function getFormErrorsHelper() { - if (null === $this->formErrorsHelper) { - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $oRenderer->setResolver(\TwbBundleTest\Bootstrap::getServiceManager()->get('ViewResolver')); - $helper = $oViewHelperPluginManager->get('formErrors') - ->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - - $this->setFormErrorsHelper($helper); - } - - return $this->formErrorsHelper; - } - - public function testInvokeWithoutFormReturnsObject() { - $oHelper = $this->getFormErrorsHelper(); - $this->assertInstanceOf('TwbBundle\Form\View\Helper\TwbBundleFormErrors', $oHelper()); - } - - public function testInvokeWithFormCallsRender() { - $form = $this->getMockBuilder('\Laminas\Form\Form') - ->setMethods(array('hasValidated', 'isValid')) - ->disableOriginalConstructor() - ->getMock(); - $form->expects($this->exactly(1)) - ->method('hasValidated') - ->will($this->returnValue(true)); - $form->expects($this->atLeastOnce()) - ->method('isValid') - ->will($this->returnValue(false)); - - $this->assertInstanceOf('\Laminas\Form\Form', $form); - - $helper = $this->getMockBuilder('TwbBundle\Form\View\Helper\TwbBundleFormErrors') - ->setMethods(array('render')) - ->getMock(); - $helper->expects($this->atLeastOnce()) - ->method('render') - ->with($this->identicalTo($form), 'There were errors in the form submission', false /* default */) - ->will($this->returnValue('return value')); - - $this->assertInstanceOf('TwbBundle\Form\View\Helper\TwbBundleFormErrors', $helper()); - - $this->assertEquals('return value', $helper($form)); - } - - public function testInvokeWithFormNoErrorsReturnsNull() { - $form = $this->getMockBuilder('\Laminas\Form\Form') - ->setMethods(array('hasValidated', 'isValid')) - ->disableOriginalConstructor() - ->getMock(); - $form->expects($this->exactly(1)) - ->method('hasValidated') - ->will($this->returnValue(true)); - $form->expects($this->atLeastOnce()) - ->method('isValid') - ->will($this->returnValue(true)); - - $this->assertInstanceOf('\Laminas\Form\Form', $form); - - $helper = $this->getFormErrorsHelper(); - $this->assertInstanceOf('TwbBundle\Form\View\Helper\TwbBundleFormErrors', $helper()); - - $this->assertEquals(null, $helper($form)); - } - - public function testCorrectHtmlMarkupBasedOnErrorMessagesArray() { - $helper = $this->getFormErrorsHelper(); - - /** - * Tes that we haventhe corect helper. Ensures that our test is setup correctly. - */ - $this->assertInstanceOf('\TwbBundle\Form\View\Helper\TwbBundleFormErrors', $helper); - - $messagesArray = array( - 'firstName' => array( - 'isEmpty' => 'Value is required and can\'t be empty', - ), - 'lastName' => array( - 'isEmpty' => 'Value is required and can\'t be empty', - ), - 'category' => array( - 'isEmpty' => 'Value is required and can\'t be empty', - ), - 'dob' => array( - 'dateInvalidDate' => 'The input does not appear to be a valid date', - ), - ); - - $element = $this->getMockBuilder('\Laminas\Form\Element') - ->setMethods(array('getAttribute', 'getLabel')) - ->disableOriginalConstructor() - ->getMock(); - - $element->expects($this->atLeastOnce()) - ->method('getAttribute') - ->with($this->equalTo('id')) - ->will($this->returnValue('someId')); - $element->expects($this->atLeastOnce()) - ->method('getLabel') - ->will($this->onConsecutiveCalls('First Name', 'Last Name', 'Category')); - - $this->assertInstanceOf('\Laminas\Form\Element', $element); - - $element2 = $this->getMockBuilder('\Laminas\Form\Element') - ->setMethods(array('getAttribute', 'getLabel')) - ->disableOriginalConstructor() - ->getMock(); - $element2->expects($this->atLeastOnce()) - ->method('getAttribute') - ->with($this->equalTo('id')) - ->will($this->returnValue(null)); - $element2->expects($this->atLeastOnce()) - ->method('getLabel') - ->will($this->returnValue('Date of Birth')); - - $this->assertInstanceOf('\Laminas\Form\Element', $element2); - - $map = array( - array('firstName', $element), - array('lastName', $element), - array('category', $element), - array('dob', $element2), - ); - - $form = $this->getMockBuilder('\Laminas\Form\Form') - ->setMethods(array('getMessages', 'get')) - ->disableOriginalConstructor() - ->getMock(); - $form->expects($this->exactly(1)) - ->method('getMessages') - ->will($this->returnValue($messagesArray)); - $form->expects($this->atLeastOnce()) - ->method('get') - ->will($this->returnValueMap($map)); - - $this->assertInstanceOf('\Laminas\Form\Form', $form); - - $output = $helper->render($form, 'Errors below', false); - - $ex = '
    ' - . '

    Errors below

    '; - - $this->assertEquals($ex, $output); - } - -} +getFormErrorsHelper(); + } + + /** + * Enforces that the correct helpers is being initialised. + * @param \TwbBundle\Form\View\Helper\TwbBundleFormErrors $oFormErrorsHelper + * @return \TwbBundleTest\Form\View\Helper\TwbBundleFormErrorsTest + */ + public function setFormErrorsHelper(\TwbBundle\Form\View\Helper\TwbBundleFormErrors $oFormErrorsHelper = null) + { + $this->formErrorsHelper = $oFormErrorsHelper; + return $this; + } + + /** + * Gets or initialises the correct helper for this test. + * @return \TwbBundle\Form\View\Helper\TwbBundleFormErrors + */ + public function getFormErrorsHelper() + { + if (null === $this->formErrorsHelper) { + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $oRenderer->setResolver(\TwbBundleTest\Bootstrap::getServiceManager()->get('ViewResolver')); + $helper = $oViewHelperPluginManager->get('formErrors') + ->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + + $this->setFormErrorsHelper($helper); + } + + return $this->formErrorsHelper; + } + + public function testInvokeWithoutFormReturnsObject() + { + $oHelper = $this->getFormErrorsHelper(); + $this->assertInstanceOf('TwbBundle\Form\View\Helper\TwbBundleFormErrors', $oHelper()); + } + + public function testInvokeWithFormCallsRender() + { + $form = $this->getMockBuilder('\Laminas\Form\Form') + ->onlyMethods(['hasValidated', 'isValid']) + ->disableOriginalConstructor() + ->getMock(); + $form->expects($this->exactly(1)) + ->method('hasValidated') + ->will($this->returnValue(true)); + $form->expects($this->atLeastOnce()) + ->method('isValid') + ->will($this->returnValue(false)); + + $this->assertInstanceOf('\Laminas\Form\Form', $form); + + $helper = $this->getMockBuilder('TwbBundle\Form\View\Helper\TwbBundleFormErrors') + ->onlyMethods(['render']) + ->getMock(); + $helper->expects($this->atLeastOnce()) + ->method('render') + ->with($this->identicalTo($form), 'There were errors in the form submission', false /* default */) + ->will($this->returnValue('return value')); + + $this->assertInstanceOf('TwbBundle\Form\View\Helper\TwbBundleFormErrors', $helper()); + + $this->assertEquals('return value', $helper($form)); + } + + public function testInvokeWithFormNoErrorsReturnsNull() + { + $form = $this->getMockBuilder('\Laminas\Form\Form') + ->onlyMethods(['hasValidated', 'isValid']) + ->disableOriginalConstructor() + ->getMock(); + $form->expects($this->exactly(1)) + ->method('hasValidated') + ->will($this->returnValue(true)); + $form->expects($this->atLeastOnce()) + ->method('isValid') + ->will($this->returnValue(true)); + + $this->assertInstanceOf('\Laminas\Form\Form', $form); + + $helper = $this->getFormErrorsHelper(); + $this->assertInstanceOf('TwbBundle\Form\View\Helper\TwbBundleFormErrors', $helper()); + + $this->assertEquals(null, $helper($form)); + } + + public function testCorrectHtmlMarkupBasedOnErrorMessagesArray() + { + $helper = $this->getFormErrorsHelper(); + + /** + * Tes that we haventhe corect helper. Ensures that our test is setup correctly. + */ + $this->assertInstanceOf('\TwbBundle\Form\View\Helper\TwbBundleFormErrors', $helper); + + $messagesArray = [ + 'firstName' => [ + 'isEmpty' => 'Value is required and can\'t be empty', + ], + 'lastName' => [ + 'isEmpty' => 'Value is required and can\'t be empty', + ], + 'category' => [ + 'isEmpty' => 'Value is required and can\'t be empty', + ], + 'dob' => [ + 'dateInvalidDate' => 'The input does not appear to be a valid date', + ], + ]; + + $element = $this->getMockBuilder('\Laminas\Form\Element') + ->onlyMethods(['getAttribute', 'getLabel']) + ->disableOriginalConstructor() + ->getMock(); + + $element->expects($this->atLeastOnce()) + ->method('getAttribute') + ->with($this->equalTo('id')) + ->will($this->returnValue('someId')); + $element->expects($this->atLeastOnce()) + ->method('getLabel') + ->will($this->onConsecutiveCalls('First Name', 'Last Name', 'Category')); + + $this->assertInstanceOf('\Laminas\Form\Element', $element); + + $element2 = $this->getMockBuilder('\Laminas\Form\Element') + ->onlyMethods(['getAttribute', 'getLabel']) + ->disableOriginalConstructor() + ->getMock(); + $element2->expects($this->atLeastOnce()) + ->method('getAttribute') + ->with($this->equalTo('id')) + ->will($this->returnValue(null)); + $element2->expects($this->atLeastOnce()) + ->method('getLabel') + ->will($this->returnValue('Date of Birth')); + + $this->assertInstanceOf('\Laminas\Form\Element', $element2); + + $map = [ + ['firstName', $element], + ['lastName', $element], + ['category', $element], + ['dob', $element2], + ]; + + $form = $this->getMockBuilder('\Laminas\Form\Form') + ->onlyMethods(['getMessages', 'get']) + ->disableOriginalConstructor() + ->getMock(); + $form->expects($this->exactly(1)) + ->method('getMessages') + ->will($this->returnValue($messagesArray)); + $form->expects($this->atLeastOnce()) + ->method('get') + ->will($this->returnValueMap($map)); + + $this->assertInstanceOf('\Laminas\Form\Form', $form); + + $output = $helper->render($form, 'Errors below', false); + + $ex = '
    ' + . '

    Errors below

    '; + + $this->assertEquals($ex, $output); + } + +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormMultiCheckboxTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormMultiCheckboxTest.php index 40ed1aa..0f00261 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormMultiCheckboxTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormMultiCheckboxTest.php @@ -1,27 +1,30 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formMultiCheckboxHelper = $oViewHelperPluginManager->get('formMultiCheckbox')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderWithNoInline() { - $oElement = new \Laminas\Form\Element\MultiCheckbox('test-element', array('inline' => false, 'value_options' => array('test-option'))); - $this->formMultiCheckboxHelper->render($oElement); - $this->assertEquals(array('class' => 'checkbox'), $oElement->getLabelAttributes()); - } - -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formMultiCheckboxHelper = $oViewHelperPluginManager->get('formMultiCheckbox')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderWithNoInline() + { + $oElement = new \Laminas\Form\Element\MultiCheckbox('test-element', ['inline' => false, 'value_options' => ['test-option']]); + $this->formMultiCheckboxHelper->render($oElement); + $this->assertEquals(['class' => 'checkbox'], $oElement->getLabelAttributes()); + } + +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRadioTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRadioTest.php index f29c517..6f82b0e 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRadioTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRadioTest.php @@ -1,54 +1,68 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formRadioHelper = $oViewHelperPluginManager->get('formRadio')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderOptionsWithPrependingLabel() { - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRadio'); - $oReflectionMethod = $oReflectionClass->getMethod('renderOptions'); - $oReflectionMethod->setAccessible(true); - - $this->formRadioHelper->setLabelPosition(\TwbBundle\Form\View\Helper\TwbBundleFormRadio::LABEL_PREPEND); - $this->assertEquals( - '', $oReflectionMethod->invoke($this->formRadioHelper, new \Laminas\Form\Element\Radio(), array(0 => 'test'), array(0), array()) - ); - } - - public function testRenderOptionsWithDefineAttributesId() { - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRadio'); - $oReflectionMethod = $oReflectionClass->getMethod('renderOptions'); - $oReflectionMethod->setAccessible(true); - - $this->formRadioHelper->setLabelPosition(\TwbBundle\Form\View\Helper\TwbBundleFormRadio::LABEL_PREPEND); - $this->assertEquals( - '
    ', $oReflectionMethod->invoke($this->formRadioHelper, new \Laminas\Form\Element\Radio(), array(0 => 'test1', 1 => 'test2'), array(0), array('id' => 'test_id')) - ); - } - - public function testRenderOptionsWithOptionsSpecs() { - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRadio'); - $oReflectionMethod = $oReflectionClass->getMethod('renderOptions'); - $oReflectionMethod->setAccessible(true); - - $this->formRadioHelper->setLabelPosition(\TwbBundle\Form\View\Helper\TwbBundleFormRadio::LABEL_PREPEND); - $this->assertEquals( - '
    ', $oReflectionMethod->invoke($this->formRadioHelper, new \Laminas\Form\Element\Radio(), array(0 => 'test1', 1 => array('label' => 'test2', 'selected' => true, 'disabled' => true, 'label_attributes' => array('class' => 'test-label-class'), 'attributes' => array('class' => 'test-class'))), array(0), array('id' => 'test_id', 'type' => 'radio')) - ); - } - -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formRadioHelper = $oViewHelperPluginManager->get('formRadio')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderOptionsWithPrependingLabel() + { + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRadio'); + $oReflectionMethod = $oReflectionClass->getMethod('renderOptions'); + $oReflectionMethod->setAccessible(true); + + $this->formRadioHelper->setLabelPosition(\TwbBundle\Form\View\Helper\TwbBundleFormRadio::LABEL_PREPEND); + $this->assertEquals( + '', + $oReflectionMethod->invoke($this->formRadioHelper, new \Laminas\Form\Element\Radio(), [0 => 'test'], [0], []) + ); + } + + public function testRenderOptionsWithDefineAttributesId() + { + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRadio'); + $oReflectionMethod = $oReflectionClass->getMethod('renderOptions'); + $oReflectionMethod->setAccessible(true); + + $this->formRadioHelper->setLabelPosition(\TwbBundle\Form\View\Helper\TwbBundleFormRadio::LABEL_PREPEND); + $this->assertEquals( + '
    ', + $oReflectionMethod->invoke($this->formRadioHelper, new \Laminas\Form\Element\Radio(), [0 => 'test1', 1 => 'test2'], [0], ['id' => 'test_id']) + ); + } + + public function testRenderOptionsWithOptionsSpecs() + { + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRadio'); + $oReflectionMethod = $oReflectionClass->getMethod('renderOptions'); + $oReflectionMethod->setAccessible(true); + + $this->formRadioHelper->setLabelPosition(\TwbBundle\Form\View\Helper\TwbBundleFormRadio::LABEL_PREPEND); + $this->assertEquals( + '
    ', + $oReflectionMethod->invoke( + $this->formRadioHelper, + new \Laminas\Form\Element\Radio(), + [0 => 'test1', 1 => ['label' => 'test2', 'selected' => true, 'disabled' => true, 'label_attributes' => ['class' => 'test-label-class'], 'attributes' => ['class' => 'test-class']]], + [0], + ['id' => 'test_id', 'type' => 'radio'] + ) + ); + } + +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRowTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRowTest.php index 56ed11c..7a3288e 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRowTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormRowTest.php @@ -1,236 +1,239 @@ -expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../../../_files/expected-rows' . DIRECTORY_SEPARATOR; - $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $oRenderer->setResolver(\TwbBundleTest\Bootstrap::getServiceManager()->get('ViewResolver')); - $this->formRowHelper = $oViewHelperPluginManager->get('formRow')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - $this->formRowHelper->setPartial(null); - } - - public function testRenderPartial() - { - $this->formRowHelper->setPartial('partial-row'); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'partial.phtml', $this->formRowHelper->render(new \Laminas\Form\Element('test-element'))); - } - - public function testRenderAddOnWithValidationStateAndDefinedLabelClass() - { - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRow'); - $oReflectionMethod = $oReflectionClass->getMethod('renderElement'); - $oReflectionMethod->setAccessible(true); - - $oElement = new \Laminas\Form\Element('test-element', array('validation-state' => 'warning')); - $oElement - ->setLabel('test-label') - ->setLabelAttributes(array('class' => 'test-label-class')); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'add-on-validation-states.phtml', $oReflectionMethod->invoke($this->formRowHelper, $oElement)); - } - - public function testRenderAddOnWithInlineLayoutAndDefinedLabelClass() - { - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRow'); - $oReflectionMethod = $oReflectionClass->getMethod('renderElement'); - $oReflectionMethod->setAccessible(true); - - $oElement = new \Laminas\Form\Element('test-element', array('twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE)); - $oElement - ->setLabel('test-label') - ->setLabelAttributes(array('class' => 'test-label-class')); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'add-on-inline-layout.phtml', $oReflectionMethod->invoke($this->formRowHelper, $oElement)); - } - - public function testRenderAddOnWithHorizontalLayoutAndDefinedLabelClass() - { - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRow'); - $oReflectionMethod = $oReflectionClass->getMethod('renderElement'); - $oReflectionMethod->setAccessible(true); - - $oElement = new \Laminas\Form\Element('test-element', array('twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_HORIZONTAL)); - $oElement - ->setLabel('test-label') - ->setLabelAttributes(array('class' => 'test-label-class')); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'add-on-horizontal-layout.phtml', $oReflectionMethod->invoke($this->formRowHelper, $oElement)); - } - - public function testRenderAddOnWithWrongLayout() - { - $this->expectException(\DomainException::class); - $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRow'); - $oReflectionMethod = $oReflectionClass->getMethod('renderElement'); - $oReflectionMethod->setAccessible(true); - $oReflectionMethod->invoke($this->formRowHelper, new \Laminas\Form\Element('test-element', array('label' => 'test-label', 'twb-layout' => 'wrong'))); - } - - public function testRenderErrorsWithInputErrorClass() - { - $this->formRowHelper->setInputErrorClass('input-error'); - $oElement = new \Laminas\Form\Element\Text('input-text'); - $oElement->setAttribute('class', 'test-class'); - $oElement->setMessages(array( - 'This is an error message', - 'This is an another one error message' - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'errors-input-errors-class.phtml', $this->formRowHelper->__invoke($oElement)); - } - - public function testRenderErrorsWithoutInputErrorClass() - { - $this->formRowHelper->setInputErrorClass('input-error'); - $oElement = new \Laminas\Form\Element\Text('input-text'); - $oElement->setMessages(array( - 'This is an error message', - 'This is an another one error message' - )); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'errors-without-input-errors-class.phtml', $this->formRowHelper->__invoke($oElement)); - } - - public function testRenderHiddenElement() - { - $this->formRowHelper->setInputErrorClass('input-error'); - $oElement = new \Laminas\Form\Element\Hidden('input-hidden'); - //Test content - $this->assertEquals( - '', $this->formRowHelper->__invoke($oElement) - ); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'hidden-element.phtml', $this->formRowHelper->__invoke($oElement)); - } - - public function testRendeCheckboxWithDefinedLabelAttributes() - { - $oElement = new \Laminas\Form\Element\Checkbox('test-checkbox'); - $oElement->setLabel('Test checkbox'); - $aLabelAttributes = $this->formRowHelper->getLabelAttributes(); - $this->formRowHelper->setLabelAttributes(array('class' => 'test-class')); - - //Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'checkbox-defined-label-attributes.phtml', $this->formRowHelper->__invoke($oElement)); - - // Restore original label attributes - $this->formRowHelper->setLabelAttributes($aLabelAttributes); - } - - public function testRenderRadiosWithHorizontalLayout() - { - $oElement = new \Laminas\Form\Element\Radio('test-radio', array( - 'twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_HORIZONTAL, - 'label' => 'Test radio', - 'column-size' => 'sm-10', - 'label_attributes' => array('class' => 'col-sm-2'), - 'value_options' => array( - 'option1' => 'Option one', - 'option2' => 'Option two' - ) - )); - - // Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'radio-horizontal-layout.phtml', $this->formRowHelper->__invoke($oElement)); - } - - public function testRenderFormRowWithSpecificClass() - { - $oElement = new \Laminas\Form\Element\Text('test-text', array( - 'label' => 'Test text', - 'column-size' => 'sm-10', - 'label_attributes' => array('class' => 'col-sm-2'), - 'twb-row-class' => 'my-row-class' - )); - - // Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'row-class.phtml', $this->formRowHelper->__invoke($oElement)); - } - - public function testRenderInputWithHelpTextAndError() - { - $oElement = new \Laminas\Form\Element\Text('input-text', array( - 'label' => 'Input text label', - 'help-block' => 'Help block text' - )); - $oElement->setMessages(array('Error message')); - // Test content - $this->twbAssertStringEqualsFile($this->expectedPath . 'input-with-help-text-and-error.phtml', $this->formRowHelper->__invoke($oElement)); - } - - public function testRenderWithBothInlineAndNoInlineRadios() { - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'optInput1', - 'type' => 'radio', - 'options' => array( - 'label' => 'Opt1', - 'value_options' => array('label1','label2','label3'), - 'inline' => true, - ), - ))->add(array( - 'name' => 'optInput2', - 'type' => 'radio', - 'options' => array( - 'label' => 'Opt2', - 'value_options' => array('label1','label2','label3'), - 'inline' => false, - ), - )); - - $this->twbAssertStringEqualsFile($this->expectedPath . 'both-inline-and-no-inline-radios.phtml', $this->formRowHelper->__invoke($oForm->get('optInput1')).$this->formRowHelper->__invoke($oForm->get('optInput2'))); - } - - public function testAllowsFeedbackInTextField(){ - $oForm = new \Laminas\Form\Form(); - $oForm->add(array( - 'name' => 'username', - 'type' => 'text', - 'options' => array( - 'label' => 'Your Username', - 'feedback' => 'glyphicon glyphicon-user', - ), - )); - - $this->twbAssertStringEqualsFile($this->expectedPath . 'has-feedback-in-textfield.phtml', $this->formRowHelper->__invoke($oForm->get('username'))); - } - - /** - * @param string $sExpectedFile - * @param string $sActualString - * @param string $sMessage - * @param boolean $bCanonicalize - * @param boolean $bIgnoreCase - */ - public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) - { - return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); - } -} +expectedPath = __DIR__ . DIRECTORY_SEPARATOR . '../../../../_files/expected-rows' . DIRECTORY_SEPARATOR; + $oViewHelperPluginManager = \TwbBundleTest\Bootstrap::getServiceManager()->get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $oRenderer->setResolver(\TwbBundleTest\Bootstrap::getServiceManager()->get('ViewResolver')); + $this->formRowHelper = $oViewHelperPluginManager->get('formRow')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + $this->formRowHelper->setPartial(null); + } + + public function testRenderPartial() + { + $this->formRowHelper->setPartial('partial-row'); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'partial.phtml', $this->formRowHelper->render(new \Laminas\Form\Element('test-element'))); + } + + public function testRenderAddOnWithValidationStateAndDefinedLabelClass() + { + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRow'); + $oReflectionMethod = $oReflectionClass->getMethod('renderElement'); + $oReflectionMethod->setAccessible(true); + + $oElement = new \Laminas\Form\Element('test-element', ['validation-state' => 'warning']); + $oElement + ->setLabel('test-label') + ->setLabelAttributes(['class' => 'test-label-class']); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'add-on-validation-states.phtml', $oReflectionMethod->invoke($this->formRowHelper, $oElement)); + } + + public function testRenderAddOnWithInlineLayoutAndDefinedLabelClass() + { + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRow'); + $oReflectionMethod = $oReflectionClass->getMethod('renderElement'); + $oReflectionMethod->setAccessible(true); + + $oElement = new \Laminas\Form\Element('test-element', ['twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_INLINE]); + $oElement + ->setLabel('test-label') + ->setLabelAttributes(['class' => 'test-label-class']); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'add-on-inline-layout.phtml', $oReflectionMethod->invoke($this->formRowHelper, $oElement)); + } + + public function testRenderAddOnWithHorizontalLayoutAndDefinedLabelClass() + { + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRow'); + $oReflectionMethod = $oReflectionClass->getMethod('renderElement'); + $oReflectionMethod->setAccessible(true); + + $oElement = new \Laminas\Form\Element('test-element', ['twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_HORIZONTAL]); + $oElement + ->setLabel('test-label') + ->setLabelAttributes(['class' => 'test-label-class']); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'add-on-horizontal-layout.phtml', $oReflectionMethod->invoke($this->formRowHelper, $oElement)); + } + + public function testRenderAddOnWithWrongLayout() + { + $this->expectException(\DomainException::class); + $oReflectionClass = new \ReflectionClass('\TwbBundle\Form\View\Helper\TwbBundleFormRow'); + $oReflectionMethod = $oReflectionClass->getMethod('renderElement'); + $oReflectionMethod->setAccessible(true); + $oReflectionMethod->invoke($this->formRowHelper, new \Laminas\Form\Element('test-element', ['label' => 'test-label', 'twb-layout' => 'wrong'])); + } + + public function testRenderErrorsWithInputErrorClass() + { + $this->formRowHelper->setInputErrorClass('input-error'); + $oElement = new \Laminas\Form\Element\Text('input-text'); + $oElement->setAttribute('class', 'test-class'); + $oElement->setMessages([ + 'This is an error message', + 'This is an another one error message' + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'errors-input-errors-class.phtml', $this->formRowHelper->__invoke($oElement)); + } + + public function testRenderErrorsWithoutInputErrorClass() + { + $this->formRowHelper->setInputErrorClass('input-error'); + $oElement = new \Laminas\Form\Element\Text('input-text'); + $oElement->setMessages([ + 'This is an error message', + 'This is an another one error message' + ]); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'errors-without-input-errors-class.phtml', $this->formRowHelper->__invoke($oElement)); + } + + public function testRenderHiddenElement() + { + $this->formRowHelper->setInputErrorClass('input-error'); + $oElement = new \Laminas\Form\Element\Hidden('input-hidden'); + //Test content + $this->assertEquals( + '', + $this->formRowHelper->__invoke($oElement) + ); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'hidden-element.phtml', $this->formRowHelper->__invoke($oElement)); + } + + public function testRendeCheckboxWithDefinedLabelAttributes() + { + $oElement = new \Laminas\Form\Element\Checkbox('test-checkbox'); + $oElement->setLabel('Test checkbox'); + $aLabelAttributes = $this->formRowHelper->getLabelAttributes(); + $this->formRowHelper->setLabelAttributes(['class' => 'test-class']); + + //Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'checkbox-defined-label-attributes.phtml', $this->formRowHelper->__invoke($oElement)); + + // Restore original label attributes + $this->formRowHelper->setLabelAttributes($aLabelAttributes); + } + + public function testRenderRadiosWithHorizontalLayout() + { + $oElement = new \Laminas\Form\Element\Radio('test-radio', [ + 'twb-layout' => \TwbBundle\Form\View\Helper\TwbBundleForm::LAYOUT_HORIZONTAL, + 'label' => 'Test radio', + 'column-size' => 'sm-10', + 'label_attributes' => ['class' => 'col-sm-2'], + 'value_options' => [ + 'option1' => 'Option one', + 'option2' => 'Option two' + ] + ]); + + // Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'radio-horizontal-layout.phtml', $this->formRowHelper->__invoke($oElement)); + } + + public function testRenderFormRowWithSpecificClass() + { + $oElement = new \Laminas\Form\Element\Text('test-text', [ + 'label' => 'Test text', + 'column-size' => 'sm-10', + 'label_attributes' => ['class' => 'col-sm-2'], + 'twb-row-class' => 'my-row-class' + ]); + + // Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'row-class.phtml', $this->formRowHelper->__invoke($oElement)); + } + + public function testRenderInputWithHelpTextAndError() + { + $oElement = new \Laminas\Form\Element\Text('input-text', [ + 'label' => 'Input text label', + 'help-block' => 'Help block text' + ]); + $oElement->setMessages(['Error message']); + // Test content + $this->twbAssertStringEqualsFile($this->expectedPath . 'input-with-help-text-and-error.phtml', $this->formRowHelper->__invoke($oElement)); + } + + public function testRenderWithBothInlineAndNoInlineRadios() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'optInput1', + 'type' => 'radio', + 'options' => [ + 'label' => 'Opt1', + 'value_options' => ['label1','label2','label3'], + 'inline' => true, + ], + ])->add([ + 'name' => 'optInput2', + 'type' => 'radio', + 'options' => [ + 'label' => 'Opt2', + 'value_options' => ['label1','label2','label3'], + 'inline' => false, + ], + ]); + + $this->twbAssertStringEqualsFile($this->expectedPath . 'both-inline-and-no-inline-radios.phtml', $this->formRowHelper->__invoke($oForm->get('optInput1')) . $this->formRowHelper->__invoke($oForm->get('optInput2'))); + } + + public function testAllowsFeedbackInTextField() + { + $oForm = new \Laminas\Form\Form(); + $oForm->add([ + 'name' => 'username', + 'type' => 'text', + 'options' => [ + 'label' => 'Your Username', + 'feedback' => 'glyphicon glyphicon-user', + ], + ]); + + $this->twbAssertStringEqualsFile($this->expectedPath . 'has-feedback-in-textfield.phtml', $this->formRowHelper->__invoke($oForm->get('username'))); + } + + /** + * @param string $sExpectedFile + * @param string $sActualString + * @param string $sMessage + * @param boolean $bCanonicalize + * @param boolean $bIgnoreCase + */ + public static function twbAssertStringEqualsFile($sExpectedFile, $sActualString, $sMessage = '', $bCanonicalize = false, $bIgnoreCase = false) + { + return parent::assertStringEqualsFile($sExpectedFile, $sActualString, $sMessage, $bCanonicalize, $bIgnoreCase); + } +} diff --git a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormTest.php b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormTest.php index e870c40..473e527 100644 --- a/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormTest.php +++ b/tests/TwbBundleTest/Form/View/Helper/TwbBundleFormTest.php @@ -1,34 +1,34 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->formHelper = $oViewHelperPluginManager->get('form')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testInvoke() - { - return $this->assertSame($this->formHelper, $this->formHelper->__invoke()); - } - - public function testRenderFormWithClassAlreadyDefined() - { - $oForm = new \Laminas\Form\Form(null, array('attributes' => array('class' => 'test-class'))); - $this->formHelper->render($oForm->setAttribute('class', 'test-class')); - $this->assertEquals('test-class form-horizontal', $oForm->getAttribute('class')); - } -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->formHelper = $oViewHelperPluginManager->get('form')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testInvoke() + { + return $this->assertSame($this->formHelper, $this->formHelper->__invoke()); + } + + public function testRenderFormWithClassAlreadyDefined() + { + $oForm = new \Laminas\Form\Form(null, ['attributes' => ['class' => 'test-class']]); + $this->formHelper->render($oForm->setAttribute('class', 'test-class')); + $this->assertEquals('test-class form-horizontal', $oForm->getAttribute('class')); + } +} diff --git a/tests/TwbBundleTest/ModuleTest.php b/tests/TwbBundleTest/ModuleTest.php index fdb0fd5..9b0f88f 100644 --- a/tests/TwbBundleTest/ModuleTest.php +++ b/tests/TwbBundleTest/ModuleTest.php @@ -1,17 +1,20 @@ -module = new \TwbBundle\Module(); - } - - public function testGetConfig(){ - $this->assertTrue(is_array($this->module->getConfig())); - } -} \ No newline at end of file +module = new \TwbBundle\Module(); + } + + public function testGetConfig() + { + $this->assertIsArray($this->module->getConfig()); + } +} diff --git a/tests/TwbBundleTest/View/Helper/Navigation/AbstractTest.php b/tests/TwbBundleTest/View/Helper/Navigation/AbstractTestCase.php similarity index 96% rename from tests/TwbBundleTest/View/Helper/Navigation/AbstractTest.php rename to tests/TwbBundleTest/View/Helper/Navigation/AbstractTestCase.php index ae3ad94..f464ff4 100644 --- a/tests/TwbBundleTest/View/Helper/Navigation/AbstractTest.php +++ b/tests/TwbBundleTest/View/Helper/Navigation/AbstractTestCase.php @@ -24,7 +24,7 @@ /** * Base class for navigation view helper tests */ -abstract class AbstractTest extends TestCase +abstract class AbstractTestCase extends TestCase { /** * @var ServiceManager @@ -63,6 +63,8 @@ abstract class AbstractTest extends TestCase private $_oldControllerDir; // @codingStandardsIgnoreEnd + protected $routeMatchType; + /** * Prepares the environment before running a test * @@ -77,7 +79,7 @@ protected function setUp(): void // read navigation config $this->_files = $cwd . '/_files'; - $config = ConfigFactory::fromFile($this->_files . '/navigation.xml', true); + $config = ConfigFactory::fromFile($this->_files . '/navigation.xml', true); // setup containers from config $this->_nav = new Navigation($config->get('nav_test1')); diff --git a/tests/TwbBundleTest/View/Helper/Navigation/TwbBundleMenuTest.php b/tests/TwbBundleTest/View/Helper/Navigation/TwbBundleMenuTest.php index 4351645..1e45650 100644 --- a/tests/TwbBundleTest/View/Helper/Navigation/TwbBundleMenuTest.php +++ b/tests/TwbBundleTest/View/Helper/Navigation/TwbBundleMenuTest.php @@ -12,7 +12,7 @@ use TwbBundle\View\Helper\Navigation\TwbBundleMenu; -class TwbBundleMenuTest extends AbstractTest +class TwbBundleMenuTest extends AbstractTestCase { // @codingStandardsIgnoreStart /** diff --git a/tests/TwbBundleTest/View/Helper/TwbBundleAlertTest.php b/tests/TwbBundleTest/View/Helper/TwbBundleAlertTest.php index 6f8f6e0..35b1540 100644 --- a/tests/TwbBundleTest/View/Helper/TwbBundleAlertTest.php +++ b/tests/TwbBundleTest/View/Helper/TwbBundleAlertTest.php @@ -1,35 +1,38 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->alertHelper = $oViewHelperPluginManager->get('alert')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderWithWrongTypeAttributes() - { - $this->expectException(\InvalidArgumentException::class); - $this->alertHelper->render('test',new \stdClass()); - } - - public function testRenderWithEmptyClassAttributes() - { - $this->expectException(\InvalidArgumentException::class); - $this->alertHelper->render('test',array('class' => '')); - } - - public function testRenderWithWrongTypeClassAttributes() - { - $this->expectException(\InvalidArgumentException::class); - $this->alertHelper->render('test',array('class' => new \stdClass())); - } -} \ No newline at end of file +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->alertHelper = $oViewHelperPluginManager->get('alert')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderWithWrongTypeAttributes() + { + $this->expectException(\InvalidArgumentException::class); + $this->alertHelper->render('test', new \stdClass()); + } + + public function testRenderWithEmptyClassAttributes() + { + $this->expectException(\InvalidArgumentException::class); + $this->alertHelper->render('test', ['class' => '']); + } + + public function testRenderWithWrongTypeClassAttributes() + { + $this->expectException(\InvalidArgumentException::class); + $this->alertHelper->render('test', ['class' => new \stdClass()]); + } +} diff --git a/tests/TwbBundleTest/View/Helper/TwbBundleDropDownTest.php b/tests/TwbBundleTest/View/Helper/TwbBundleDropDownTest.php index 1752898..65582a0 100644 --- a/tests/TwbBundleTest/View/Helper/TwbBundleDropDownTest.php +++ b/tests/TwbBundleTest/View/Helper/TwbBundleDropDownTest.php @@ -1,62 +1,64 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->dropDownHelper = $oViewHelperPluginManager->get('dropDown')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderToggleWithWrongTypeAttributes() - { - $this->expectException(\InvalidArgumentException::class); - $this->dropDownHelper->renderToggle(array('toggle_attributes' => 'wrong')); - } - - public function testRenderToggleWithEmptyClassAttribute() - { - $this->assertEquals(' ', $this->dropDownHelper->renderToggle(array('toggle_attributes' => array('class' => '')))); - } - - public function testRenderToggleWithDefinedClassAttribute() - { - $this->assertEquals(' ', $this->dropDownHelper->renderToggle(array('toggle_attributes' => array('class' => 'test-toggle')))); - } - - public function testRenderItemWithDefinedClassAttribute() - { - $oReflectionClass = new \ReflectionClass('\TwbBundle\View\Helper\TwbBundleDropDown'); - $oReflectionMethod = $oReflectionClass->getMethod('renderItem'); - $oReflectionMethod->setAccessible(true); - - //Header - $this->assertEquals( - '', $oReflectionMethod->invoke($this->dropDownHelper, array( - 'type' => \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_HEADER, - 'label' => 'test-label', - 'attributes' => array('class' => 'test-item') - )) - ); - - //Divider - $this->assertEquals( - '', $oReflectionMethod->invoke($this->dropDownHelper, array( - 'type' => \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, - 'attributes' => array('class' => 'test-item') - )) - ); - } -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->dropDownHelper = $oViewHelperPluginManager->get('dropDown')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderToggleWithWrongTypeAttributes() + { + $this->expectException(\InvalidArgumentException::class); + $this->dropDownHelper->renderToggle(['toggle_attributes' => 'wrong']); + } + + public function testRenderToggleWithEmptyClassAttribute() + { + $this->assertEquals(' ', $this->dropDownHelper->renderToggle(['toggle_attributes' => ['class' => '']])); + } + + public function testRenderToggleWithDefinedClassAttribute() + { + $this->assertEquals(' ', $this->dropDownHelper->renderToggle(['toggle_attributes' => ['class' => 'test-toggle']])); + } + + public function testRenderItemWithDefinedClassAttribute() + { + $oReflectionClass = new \ReflectionClass('\TwbBundle\View\Helper\TwbBundleDropDown'); + $oReflectionMethod = $oReflectionClass->getMethod('renderItem'); + $oReflectionMethod->setAccessible(true); + + //Header + $this->assertEquals( + '', + $oReflectionMethod->invoke($this->dropDownHelper, [ + 'type' => \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_HEADER, + 'label' => 'test-label', + 'attributes' => ['class' => 'test-item'] + ]) + ); + + //Divider + $this->assertEquals( + '', + $oReflectionMethod->invoke($this->dropDownHelper, [ + 'type' => \TwbBundle\View\Helper\TwbBundleDropDown::TYPE_ITEM_DIVIDER, + 'attributes' => ['class' => 'test-item'] + ]) + ); + } +} diff --git a/tests/TwbBundleTest/View/Helper/TwbBundleFontAwesomeTest.php b/tests/TwbBundleTest/View/Helper/TwbBundleFontAwesomeTest.php index 5a51bb8..c8f4380 100644 --- a/tests/TwbBundleTest/View/Helper/TwbBundleFontAwesomeTest.php +++ b/tests/TwbBundleTest/View/Helper/TwbBundleFontAwesomeTest.php @@ -1,53 +1,58 @@ -get('ViewHelperManager'); - $oRenderer = new PhpRenderer(); - $this->fontAwesomeHelper = $oViewHelperPluginManager->get('fontAwesome') - ->setView( - $oRenderer->setHelperPluginManager($oViewHelperPluginManager) - ); - } - - public function testInvoke() { - $this->assertSame( - $this->fontAwesomeHelper, $this->fontAwesomeHelper->__invoke() - ); - } - - public function testRenderWithWrongTypeFontAwesome() - { - $this->expectException(\InvalidArgumentException::class); - $this->fontAwesomeHelper->render(new \stdClass()); - } - - public function testRenderWithEmptyClassAttributes() { - $this->assertEquals( - '', - $this->fontAwesomeHelper->render('test', array('class' => '')) - ); - } - - public function testRenderWithDefinedClassAttributes() { - $this->assertEquals( - '', - $this->fontAwesomeHelper->render('test', array('class' => 'test')) - ); - } -} \ No newline at end of file +get('ViewHelperManager'); + $oRenderer = new PhpRenderer(); + $this->fontAwesomeHelper = $oViewHelperPluginManager->get('fontAwesome') + ->setView( + $oRenderer->setHelperPluginManager($oViewHelperPluginManager) + ); + } + + public function testInvoke() + { + $this->assertSame( + $this->fontAwesomeHelper, + $this->fontAwesomeHelper->__invoke() + ); + } + + public function testRenderWithWrongTypeFontAwesome() + { + $this->expectException(\InvalidArgumentException::class); + $this->fontAwesomeHelper->render(new \stdClass()); + } + + public function testRenderWithEmptyClassAttributes() + { + $this->assertEquals( + '', + $this->fontAwesomeHelper->render('test', ['class' => '']) + ); + } + + public function testRenderWithDefinedClassAttributes() + { + $this->assertEquals( + '', + $this->fontAwesomeHelper->render('test', ['class' => 'test']) + ); + } +} diff --git a/tests/TwbBundleTest/View/Helper/TwbBundleGlyphiconTest.php b/tests/TwbBundleTest/View/Helper/TwbBundleGlyphiconTest.php index b12a166..c4b0455 100644 --- a/tests/TwbBundleTest/View/Helper/TwbBundleGlyphiconTest.php +++ b/tests/TwbBundleTest/View/Helper/TwbBundleGlyphiconTest.php @@ -1,39 +1,44 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->glyphiconHelper = $oViewHelperPluginManager->get('glyphicon')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testInvoke() { - $this->assertSame($this->glyphiconHelper, $this->glyphiconHelper->__invoke()); - } - - public function testRenderWithWrongTypeGlyphicon() - { - $this->expectException(\InvalidArgumentException::class); - $this->glyphiconHelper->render(new \stdClass()); - } - - public function testRenderWithEmptyClassAttributes() { - $this->assertEquals('', $this->glyphiconHelper->render('test', array('class' => ''))); - } - - public function testRenderWithDefinedClassAttributes() { - $this->assertEquals('', $this->glyphiconHelper->render('test', array('class' => 'test'))); - } - -} +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->glyphiconHelper = $oViewHelperPluginManager->get('glyphicon')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testInvoke() + { + $this->assertSame($this->glyphiconHelper, $this->glyphiconHelper->__invoke()); + } + + public function testRenderWithWrongTypeGlyphicon() + { + $this->expectException(\InvalidArgumentException::class); + $this->glyphiconHelper->render(new \stdClass()); + } + + public function testRenderWithEmptyClassAttributes() + { + $this->assertEquals('', $this->glyphiconHelper->render('test', ['class' => ''])); + } + + public function testRenderWithDefinedClassAttributes() + { + $this->assertEquals('', $this->glyphiconHelper->render('test', ['class' => 'test'])); + } + +} diff --git a/tests/TwbBundleTest/View/Helper/TwbBundleLabelTest.php b/tests/TwbBundleTest/View/Helper/TwbBundleLabelTest.php index f7e1125..15a9c27 100644 --- a/tests/TwbBundleTest/View/Helper/TwbBundleLabelTest.php +++ b/tests/TwbBundleTest/View/Helper/TwbBundleLabelTest.php @@ -1,35 +1,38 @@ -get('ViewHelperManager'); - $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); - $this->labelHelper = $oViewHelperPluginManager->get('label')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); - } - - public function testRenderWithWrongTypeAttributes() - { - $this->expectException(\InvalidArgumentException::class); - $this->labelHelper->render('test',new \stdClass()); - } - - public function testRenderWithEmptyClassAttributes() - { - $this->expectException(\InvalidArgumentException::class); - $this->labelHelper->render('test',array('class' => '')); - } - - public function testRenderWithWrongTypeClassAttributes() - { - $this->expectException(\InvalidArgumentException::class); - $this->labelHelper->render('test',array('class' => new \stdClass())); - } -} \ No newline at end of file +get('ViewHelperManager'); + $oRenderer = new \Laminas\View\Renderer\PhpRenderer(); + $this->labelHelper = $oViewHelperPluginManager->get('label')->setView($oRenderer->setHelperPluginManager($oViewHelperPluginManager)); + } + + public function testRenderWithWrongTypeAttributes() + { + $this->expectException(\InvalidArgumentException::class); + $this->labelHelper->render('test', new \stdClass()); + } + + public function testRenderWithEmptyClassAttributes() + { + $this->expectException(\InvalidArgumentException::class); + $this->labelHelper->render('test', ['class' => '']); + } + + public function testRenderWithWrongTypeClassAttributes() + { + $this->expectException(\InvalidArgumentException::class); + $this->labelHelper->render('test', ['class' => new \stdClass()]); + } +} diff --git a/tests/_files/expected-buttons/disabled.phtml b/tests/_files/expected-buttons/disabled.phtml index 5614319..7f549f9 100644 --- a/tests/_files/expected-buttons/disabled.phtml +++ b/tests/_files/expected-buttons/disabled.phtml @@ -1,2 +1,2 @@ - - + + diff --git a/tests/_files/expected-forms/control-states-form-horizontal.phtml b/tests/_files/expected-forms/control-states-form-horizontal.phtml index 23930ea..a4eec6f 100644 --- a/tests/_files/expected-forms/control-states-form-horizontal.phtml +++ b/tests/_files/expected-forms/control-states-form-horizontal.phtml @@ -1,6 +1,6 @@
    -
    +
    diff --git a/tests/_files/expected-forms/control-states-form.phtml b/tests/_files/expected-forms/control-states-form.phtml index d506c84..bf22d4d 100644 --- a/tests/_files/expected-forms/control-states-form.phtml +++ b/tests/_files/expected-forms/control-states-form.phtml @@ -1,6 +1,6 @@
    -
    +
    diff --git a/tests/_files/expected-forms/supported-controls-form.phtml b/tests/_files/expected-forms/supported-controls-form.phtml index e3a22c1..39253f2 100644 --- a/tests/_files/expected-forms/supported-controls-form.phtml +++ b/tests/_files/expected-forms/supported-controls-form.phtml @@ -9,7 +9,7 @@
    -
    diff --git a/tests/configuration.php b/tests/configuration.php index c97f922..5c4a6f6 100644 --- a/tests/configuration.php +++ b/tests/configuration.php @@ -1,9 +1,9 @@ - array( - 'doctype' => 'HTML5', - 'template_map' => array( - 'partial-row' => __DIR__.'/_files/partial/partial-row.phtml' - ) - ), -); \ No newline at end of file + [ + 'doctype' => 'HTML5', + 'template_map' => [ + 'partial-row' => __DIR__ . '/_files/partial/partial-row.phtml' + ] + ], +]; diff --git a/tests/phpunit.xml b/tests/phpunit.xml deleted file mode 100644 index b9b5c12..0000000 --- a/tests/phpunit.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - ./TwbBundleTest/ - - - - - ../src/ - ../Module.php - - -