diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de4a392 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/vendor +/composer.lock diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a46a97b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,48 @@ +language: php + +php: + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - hhvm + - hhvm-nightly + +# run build against hhvm but allow them to fail +# http://docs.travis-ci.com/user/build-configuration/#Rows-That-are-Allowed-To-Fail +matrix: + fast_finish: true + allow_failures: + - php: hhvm-nightly + - php: 7.0 + +# faster builds on new travis setup not using sudo +sudo: false + +# cache vendor dirs +cache: + directories: + - vendor + - $HOME/.composer/cache + +install: + - travis_retry composer self-update && composer --version + - travis_retry composer global require "fxp/composer-asset-plugin:1.0.0" + - export PATH="$HOME/.composer/vendor/bin:$PATH" + - travis_retry composer install --prefer-dist --no-interaction + +before_script: + - | + if [ $TRAVIS_PHP_VERSION = '5.6' ]; then + PHPUNIT_FLAGS="--coverage-clover=coverage.clover" + fi + +script: + - phpunit --verbose $PHPUNIT_FLAGS + +after_script: + - | + if [ $TRAVIS_PHP_VERSION = '5.6' ]; then + travis_retry wget https://scrutinizer-ci.com/ocular.phar + php ocular.phar code-coverage:upload --format=php-clover coverage.clover + fi diff --git a/README.md b/README.md index 27cc5dc..d647349 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,17 @@ Twitter Bootstrap Extension for Yii 2 ===================================== -This is the Twitter Bootstrap extension for Yii 2. It encapsulates [Bootstrap](http://getbootstrap.com/) components +This is the Twitter Bootstrap extension for [Yii framework 2.0](http://www.yiiframework.com). It encapsulates [Bootstrap](http://getbootstrap.com/) components and plugins in terms of Yii widgets, and thus makes using Bootstrap components/plugins in Yii applications extremely easy. For license information check the [LICENSE](LICENSE.md)-file. +[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-bootstrap/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-bootstrap) +[![Total Downloads](https://poser.pugx.org/yiisoft/yii2-bootstrap/downloads.png)](https://packagist.org/packages/yiisoft/yii2-bootstrap) +[![Build Status](https://travis-ci.org/yiisoft/yii2-bootstrap.svg?branch=master)](https://travis-ci.org/yiisoft/yii2-bootstrap) + + Installation ------------ diff --git a/composer.json b/composer.json index 4a5da0d..fde1a87 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,10 @@ "extra": { "branch-alias": { "dev-master": "2.0.x-dev" + }, + "asset-installer-paths": { + "npm-asset-library": "vendor/npm", + "bower-asset-library": "vendor/bower" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..3a3db9f --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,13 @@ + + + + + ./tests + + + diff --git a/tests/ButtonDropdownTest.php b/tests/ButtonDropdownTest.php new file mode 100644 index 0000000..8b12dc0 --- /dev/null +++ b/tests/ButtonDropdownTest.php @@ -0,0 +1,31 @@ + [ + 'class' => $containerClass, + ], + 'label' => 'Action', + 'dropdown' => [ + 'items' => [ + ['label' => 'DropdownA', 'url' => '/'], + ['label' => 'DropdownB', 'url' => '#'], + ], + ], + ]); + + $this->assertContains("$containerClass btn-group", $out); + } +} diff --git a/tests/CollapseTest.php b/tests/CollapseTest.php new file mode 100644 index 0000000..30bdbec --- /dev/null +++ b/tests/CollapseTest.php @@ -0,0 +1,74 @@ + [ + [ + 'label' => 'Collapsible Group Item #1', + 'content' => 'test content1', + ], + [ + 'label' => '

Collapsible Group Item #2

', + 'content' => '

test content2

', + 'contentOptions' => [ + 'class' => 'testContentOptions2' + ], + 'options' => [ + 'class' => 'testClass2', + 'id' => 'testId2' + ], + 'encode' => true + ], + [ + 'label' => '

Collapsible Group Item #3

', + 'content' => '

test content3

', + 'contentOptions' => [ + 'class' => 'testContentOptions3' + ], + 'options' => [ + 'class' => 'testClass3', + 'id' => 'testId3' + ], + 'encode' => false + ], + [ + 'label' => '

Collapsible Group Item #4

', + 'content' => '

test content4

', + ], + ] + ]); + + $this->assertEqualsWithoutLE(<< +

Collapsible Group Item #1 +

+
test content1
+
+

<h1>Collapsible Group Item #2</h1> +

+

test content2

+
+

Collapsible Group Item #3

+

+

test content3

+
+

<h1>Collapsible Group Item #4</h1> +

+

test content4

+
+ + +HTML + , $output); + } +} diff --git a/tests/DropdownTest.php b/tests/DropdownTest.php new file mode 100644 index 0000000..ef284e6 --- /dev/null +++ b/tests/DropdownTest.php @@ -0,0 +1,50 @@ + [ + [ + 'label' => 'Page1', + 'content' => 'Page1', + ], + [ + 'label' => 'Dropdown1', + 'items' => [ + ['label' => 'Page2', 'content' => 'Page2'], + ['label' => 'Page3', 'content' => 'Page3'], + ] + ], + [ + 'label' => 'Dropdown2', + 'visible' => false, + 'items' => [ + ['label' => 'Page4', 'content' => 'Page4'], + ['label' => 'Page5', 'content' => 'Page5'], + ] + ] + ] + ] + ); + + $expected = << + +EXPECTED; + + $this->assertEqualsWithoutLE($expected, $out); + } +} diff --git a/tests/NavTest.php b/tests/NavTest.php new file mode 100644 index 0000000..3fad720 --- /dev/null +++ b/tests/NavTest.php @@ -0,0 +1,50 @@ + [ + [ + 'label' => 'Page1', + 'content' => 'Page1', + ], + [ + 'label' => 'Dropdown1', + 'items' => [ + ['label' => 'Page2', 'content' => 'Page2'], + ['label' => 'Page3', 'content' => 'Page3'], + ] + ], + [ + 'label' => 'Dropdown2', + 'visible' => false, + 'items' => [ + ['label' => 'Page4', 'content' => 'Page4'], + ['label' => 'Page5', 'content' => 'Page5'], + ] + ] + ] + ] + ); + + $expected = <<
  • Page1
  • + +EXPECTED; + + $this->assertEqualsWithoutLE($expected, $out); + } +} diff --git a/tests/TabsTest.php b/tests/TabsTest.php new file mode 100644 index 0000000..18e39c7 --- /dev/null +++ b/tests/TabsTest.php @@ -0,0 +1,74 @@ + [ + [ + 'label' => 'Page1', 'content' => 'Page1', + ], + [ + 'label' => 'Dropdown1', + 'items' => [ + ['label' => 'Page2', 'content' => 'Page2'], + ['label' => 'Page3', 'content' => 'Page3'], + ] + ], + [ + 'label' => 'Dropdown2', + 'items' => [ + ['label' => 'Page4', 'content' => 'Page4'], + ['label' => 'Page5', 'content' => 'Page5'], + ] + ] + ] + ]); + + $page1 = 'w0-tab0'; + $page2 = 'w0-dd1-tab0'; + $page3 = 'w0-dd1-tab1'; + $page4 = 'w0-dd2-tab0'; + $page5 = 'w0-dd2-tab1'; + + $shouldContain = [ + 'w0', // nav widget container + "#$page1", // Page1 + + 'w1', // Dropdown1 + "$page2", // Page2 + "$page3", // Page3 + + + 'w2', // Dropdown2 + "#$page4", // Page4 + "#$page5", // Page5 + + // containers + "id=\"$page1\"", + "id=\"$page2\"", + "id=\"$page3\"", + "id=\"$page4\"", + "id=\"$page5\"", + ]; + + foreach ($shouldContain as $string) { + $this->assertContains($string, $out); + } + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..95cf330 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,83 @@ +mockWebApplication(); + } + + /** + * Clean up after test. + * By default the application created with [[mockApplication]] will be destroyed. + */ + protected function tearDown() + { + parent::tearDown(); + $this->destroyApplication(); + } + + /** + * Populates Yii::$app with a new application + * The application will be destroyed on tearDown() automatically. + * @param array $config The application configuration, if needed + * @param string $appClass name of the application class to create + */ + protected function mockApplication($config = [], $appClass = '\yii\console\Application') + { + new $appClass(ArrayHelper::merge([ + 'id' => 'testapp', + 'basePath' => __DIR__, + 'vendorPath' => dirname(__DIR__) . '/vendor', + ], $config)); + } + + protected function mockWebApplication($config = [], $appClass = '\yii\web\Application') + { + new $appClass(ArrayHelper::merge([ + 'id' => 'testapp', + 'basePath' => __DIR__, + 'vendorPath' => dirname(__DIR__) . '/vendor', + 'components' => [ + 'request' => [ + 'cookieValidationKey' => 'wefJDF8sfdsfSDefwqdxj9oq', + 'scriptFile' => __DIR__ .'/index.php', + 'scriptUrl' => '/index.php', + ], + ] + ], $config)); + } + + /** + * Destroys application in Yii::$app by setting it to null. + */ + protected function destroyApplication() + { + Yii::$app = null; + Yii::$container = new Container(); + } + + /** + * Asserting two strings equality ignoring line endings + * + * @param string $expected + * @param string $actual + */ + public function assertEqualsWithoutLE($expected, $actual) + { + $expected = str_replace("\r\n", "\n", $expected); + $actual = str_replace("\r\n", "\n", $actual); + + $this->assertEquals($expected, $actual); + } +} diff --git a/tests/assets/.gitignore b/tests/assets/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/tests/assets/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..0eb9a9b --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,15 @@ +