diff --git a/tests/AccordionTest.php b/tests/AccordionTest.php index 036704f..64a0b0e 100644 --- a/tests/AccordionTest.php +++ b/tests/AccordionTest.php @@ -1,7 +1,9 @@ HTML - , $output); + , $output); } public function testLabelKeys() @@ -131,7 +133,7 @@ HTML 'label' => 'Item3', 'content' => 'Content3', ], - 'FormField' => $form->field(new DynamicModel(['test']), 'test',['template' => '{input}']), + 'FormField' => $form->field(new DynamicModel(['test']), 'test', ['template' => '{input}']), ] ]); @@ -166,7 +168,7 @@ HTML HTML - , $output); + , $output); } public function testExpandOptions() @@ -199,15 +201,15 @@ HTML HTML - , $output); + , $output); } public function invalidItemsProvider() { return [ - [ ['content'] ], // only content without label key - [ [[]] ], // only content array without label - [ [['content' => 'test']] ], // only content array without label + [['content']], // only content without label key + [[[]]], // only content array without label + [[['content' => 'test']]], // only content array without label ]; } @@ -257,7 +259,7 @@ HTML HTML - , $output); + , $output); } public function testAutoCloseItems() @@ -285,7 +287,6 @@ HTML } /** - * @depends testRender */ public function testItemToggleTag() { diff --git a/tests/ActiveFieldDefaultFormCheckTest.php b/tests/ActiveFieldDefaultFormCheckTest.php index e8a6fa4..f03aaf6 100644 --- a/tests/ActiveFieldDefaultFormCheckTest.php +++ b/tests/ActiveFieldDefaultFormCheckTest.php @@ -1,4 +1,5 @@ mockWebApplication([ - 'container' => [ - 'definitions' => [ - 'yii\bootstrap5\ActiveField' => [ - 'checkTemplate' => "
\n{input}\n{label}\n{error}\n{hint}\n
", - 'radioTemplate' => "
\n{input}\n{label}\n{error}\n{hint}\n
", - 'checkHorizontalTemplate' => "{beginWrapper}\n
\n{input}\n{label}\n{error}\n{hint}\n
\n{endWrapper}", - 'radioHorizontalTemplate' => "{beginWrapper}\n
\n{input}\n{label}\n{error}\n{hint}\n
\n{endWrapper}", - 'checkOptions' => [ - 'class' => ['widget' => 'form-check-input'], - 'labelOptions' => [ - 'class' => ['widget' => 'form-check-label'] - ], - 'wrapperOptions' => [ - 'class' => ['widget' => 'form-check'] - ] - ], - 'radioOptions' => [ - 'class' => ['widget' => 'form-check-input'], - 'labelOptions' => [ - 'class' => ['widget' => 'form-check-label'] - ], - 'wrapperOptions' => [ - 'class' => ['widget' => 'form-check'] - ] - ] - ] - ] - ] - ]); - - $this->_helperModel = new DynamicModel(['attributeName']); - ob_start(); - $this->_helperForm = ActiveForm::begin(['action' => '/something']); - ActiveForm::end(); - ob_end_clean(); - - $this->_activeField = Yii::createObject([ - 'class' => 'yii\bootstrap5\ActiveField', - 'form' => $this->_helperForm - ]); - $this->_activeField->model = $this->_helperModel; - $this->_activeField->attribute = $this->_attributeName; - } - public function testDefaultCheckboxByConfig() { Html::$counter = 0; @@ -238,4 +188,55 @@ HTML; $this->assertContainsWithoutLE($expected2, $out); $this->assertContainsWithoutLE($expected3, $out); } + + protected function setUp() + { + // dirty way to have Request object not throwing exception when running testHomeLinkNull() + $_SERVER['SCRIPT_FILENAME'] = 'index.php'; + $_SERVER['SCRIPT_NAME'] = 'index.php'; + + $this->mockWebApplication([ + 'container' => [ + 'definitions' => [ + 'yii\bootstrap5\ActiveField' => [ + 'checkTemplate' => "
\n{input}\n{label}\n{error}\n{hint}\n
", + 'radioTemplate' => "
\n{input}\n{label}\n{error}\n{hint}\n
", + 'checkHorizontalTemplate' => "{beginWrapper}\n
\n{input}\n{label}\n{error}\n{hint}\n
\n{endWrapper}", + 'radioHorizontalTemplate' => "{beginWrapper}\n
\n{input}\n{label}\n{error}\n{hint}\n
\n{endWrapper}", + 'checkOptions' => [ + 'class' => ['widget' => 'form-check-input'], + 'labelOptions' => [ + 'class' => ['widget' => 'form-check-label'] + ], + 'wrapperOptions' => [ + 'class' => ['widget' => 'form-check'] + ] + ], + 'radioOptions' => [ + 'class' => ['widget' => 'form-check-input'], + 'labelOptions' => [ + 'class' => ['widget' => 'form-check-label'] + ], + 'wrapperOptions' => [ + 'class' => ['widget' => 'form-check'] + ] + ] + ] + ] + ] + ]); + + $this->_helperModel = new DynamicModel(['attributeName']); + ob_start(); + $this->_helperForm = ActiveForm::begin(['action' => '/something']); + ActiveForm::end(); + ob_end_clean(); + + $this->_activeField = Yii::createObject([ + 'class' => 'yii\bootstrap5\ActiveField', + 'form' => $this->_helperForm + ]); + $this->_activeField->model = $this->_helperModel; + $this->_activeField->attribute = $this->_attributeName; + } } diff --git a/tests/ActiveFieldTest.php b/tests/ActiveFieldTest.php index f8cccce..4b2d642 100644 --- a/tests/ActiveFieldTest.php +++ b/tests/ActiveFieldTest.php @@ -26,25 +26,6 @@ class ActiveFieldTest extends TestCase */ private $attributeName = 'attributeName'; - protected function setUp() - { - // dirty way to have Request object not throwing exception when running testHomeLinkNull() - $_SERVER['SCRIPT_FILENAME'] = "index.php"; - $_SERVER['SCRIPT_NAME'] = "index.php"; - - parent::setUp(); - - $this->helperModel = new DynamicModel(['attributeName']); - ob_start(); - $this->helperForm = ActiveForm::begin(['action' => '/something']); - ActiveForm::end(); - ob_end_clean(); - - $this->activeField = new ActiveField(['form' => $this->helperForm]); - $this->activeField->model = $this->helperModel; - $this->activeField->attribute = $this->attributeName; - } - public function testFileInput() { Html::$counter = 0; @@ -62,8 +43,6 @@ HTML; $this->assertEqualsWithoutLE($expectedHtml, $html); } - // Tests : - public function testRadioList() { Html::$counter = 0; @@ -89,6 +68,8 @@ HTML; $this->assertEqualsWithoutLE($expectedHtml, $html); } + // Tests : + public function testRadioError() { Html::$counter = 0; @@ -257,7 +238,6 @@ HTML; } /** - * @depends testRadioList * * @see https://github.com/yiisoft/yii2-bootstrap/issues/81 */ @@ -274,7 +254,6 @@ HTML; } /** - * @depends testCheckboxList * * @see https://github.com/yiisoft/yii2-bootstrap/issues/81 */ @@ -289,4 +268,23 @@ HTML; $this->assertContains('data-attribute="test"', $content); } + + protected function setUp() + { + // dirty way to have Request object not throwing exception when running testHomeLinkNull() + $_SERVER['SCRIPT_FILENAME'] = "index.php"; + $_SERVER['SCRIPT_NAME'] = "index.php"; + + parent::setUp(); + + $this->helperModel = new DynamicModel(['attributeName']); + ob_start(); + $this->helperForm = ActiveForm::begin(['action' => '/something']); + ActiveForm::end(); + ob_end_clean(); + + $this->activeField = new ActiveField(['form' => $this->helperForm]); + $this->activeField->model = $this->helperModel; + $this->activeField->attribute = $this->attributeName; + } } diff --git a/tests/ActiveFormTest.php b/tests/ActiveFormTest.php index 0da20a5..7782109 100644 --- a/tests/ActiveFormTest.php +++ b/tests/ActiveFormTest.php @@ -15,15 +15,6 @@ use yiiunit\extensions\bootstrap5\data\User; class ActiveFormTest extends TestCase { - protected function setUp() - { - // dirty way to have Request object not throwing exception when running testFormNoRoleAttribute() - $_SERVER['REQUEST_URI'] = "index.php"; - - parent::setUp(); - - } - public function testDefaultLayout() { ActiveForm::$counter = 0; @@ -124,7 +115,6 @@ HTML; } /** - * @depends testHorizontalLayout */ public function testHorizontalLayoutTemplateOverride() { @@ -375,4 +365,13 @@ HTML; $this->assertContainsWithoutLE('
mockWebApplication([ - 'components' => [ - 'urlManager' => [ - 'scriptUrl' => '/', - ], - ], - ]); - } - - /** - * Get pagination. - * @param int $page - * @return Pagination - */ - private function getPagination($page) - { - $pagination = new Pagination(); - $pagination->setPage($page); - $pagination->totalCount = 500; - $pagination->route = 'test'; - return $pagination; - } - public function testFirstLastPageLabels() { $pagination = $this->getPagination(5); @@ -79,7 +53,6 @@ class LinkPagerTest extends TestCase } /** - * @depends testDisabledPageElementOptions */ public function testOverrideDisabledPageElementOptions() { @@ -151,4 +124,31 @@ class LinkPagerTest extends TestCase ]); $this->assertTrue($initTriggered); } + + protected function setUp() + { + parent::setUp(); + $this->mockWebApplication([ + 'components' => [ + 'urlManager' => [ + 'scriptUrl' => '/', + ], + ], + ]); + } + + /** + * Get pagination. + * @param int $page + * @return Pagination + */ + private function getPagination($page) + { + $pagination = new Pagination(); + $pagination->setPage($page); + $pagination->totalCount = 500; + $pagination->route = 'test'; + + return $pagination; + } } diff --git a/tests/ModalTest.php b/tests/ModalTest.php index 631d975..2e0b10a 100644 --- a/tests/ModalTest.php +++ b/tests/ModalTest.php @@ -38,7 +38,6 @@ HTML; } /** - * @depends testBodyOptions */ public function testContainerOptions() { diff --git a/tests/NavBarTest.php b/tests/NavBarTest.php index 75def04..3debf6d 100644 --- a/tests/NavBarTest.php +++ b/tests/NavBarTest.php @@ -1,4 +1,5 @@ mockWebApplication([ - 'components' => [ - 'request' => [ - 'class' => 'yii\web\Request', - 'scriptUrl' => '/base/index.php', - 'hostInfo' => 'http://example.com/', - 'url' => '/base/index.php&r=site%2Fcurrent&id=42' - ], - 'urlManager' => [ - 'class' => 'yii\web\UrlManager', - 'baseUrl' => '/base', - 'scriptUrl' => '/base/index.php', - 'hostInfo' => 'http://example.com/', - ] - ], - ]); - } - public function testIds() { Nav::$counter = 0; @@ -365,4 +346,24 @@ EXPECTED; $this->assertEqualsWithoutLE($expected, $out); } + + protected function setUp() + { + $this->mockWebApplication([ + 'components' => [ + 'request' => [ + 'class' => 'yii\web\Request', + 'scriptUrl' => '/base/index.php', + 'hostInfo' => 'http://example.com/', + 'url' => '/base/index.php&r=site%2Fcurrent&id=42' + ], + 'urlManager' => [ + 'class' => 'yii\web\UrlManager', + 'baseUrl' => '/base', + 'scriptUrl' => '/base/index.php', + 'hostInfo' => 'http://example.com/', + ] + ], + ]); + } } diff --git a/tests/ProgressTest.php b/tests/ProgressTest.php index e762637..ae1c626 100644 --- a/tests/ProgressTest.php +++ b/tests/ProgressTest.php @@ -1,4 +1,5 @@ mockWebApplication([ - 'language' => 'ru-RU', + 'language' => 'ru-RU', 'sourceLanguage' => 'en-US', ]); diff --git a/tests/TabsTest.php b/tests/TabsTest.php index f42b98e..4df7e7a 100644 --- a/tests/TabsTest.php +++ b/tests/TabsTest.php @@ -152,12 +152,12 @@ class TabsTest extends TestCase Tabs::$counter = 0; $html = Tabs::widget([ 'items' => [ - [ + [ 'label' => 'Page1', 'content' => 'Page1', 'disabled' => true - ], - [ + ], + [ 'label' => 'Page2', 'content' => 'Page2', ], @@ -371,7 +371,7 @@ HTML; $this->assertEquals($expected, $html); } - public function testHeaderOptions() + public function testHeaderOptions() { Tabs::$counter = 0; $html = Tabs::widget([ diff --git a/tests/ToastTest.php b/tests/ToastTest.php index 4c580dd..bb160f9 100644 --- a/tests/ToastTest.php +++ b/tests/ToastTest.php @@ -33,7 +33,6 @@ HTML; } /** - * @depends testBodyOptions */ public function testContainerOptions() { diff --git a/tests/ToggleButtonGroupTest.php b/tests/ToggleButtonGroupTest.php index e07111e..ee4718a 100644 --- a/tests/ToggleButtonGroupTest.php +++ b/tests/ToggleButtonGroupTest.php @@ -32,9 +32,9 @@ HTML; } /** - * @depends testCheckbox */ - public function testCheckboxChecked() { + public function testCheckboxChecked() + { Html::$counter = 0; $html = ToggleButtonGroup::widget([ 'type' => ToggleButtonGroup::TYPE_CHECKBOX, @@ -70,9 +70,9 @@ HTML; } /** - * @depends testRadio */ - public function testRadioChecked() { + public function testRadioChecked() + { Html::$counter = 0; $html = ToggleButtonGroup::widget([ 'type' => ToggleButtonGroup::TYPE_RADIO, diff --git a/tests/data/Singer.php b/tests/data/Singer.php index fd8ad5e..3fe37a1 100644 --- a/tests/data/Singer.php +++ b/tests/data/Singer.php @@ -21,7 +21,9 @@ class Singer extends Model [['lastName'], 'default', 'value' => 'Lennon'], [['lastName'], 'required'], [['underscore_style'], 'yii\captcha\CaptchaValidator'], - [['test'], 'required', 'when' => function($model) { return $model->firstName === 'cebe'; }], + [['test'], 'required', 'when' => function ($model) { + return $model->firstName === 'cebe'; + }], ]; } }