This commit is contained in:
Chenx221 2024-03-28 16:27:15 +08:00
parent 1a4f4d66c9
commit 222037df7d
23 changed files with 89 additions and 90 deletions

View File

@ -1,6 +1,6 @@
{
"name": "yiisoft/yii2-bootstrap5",
"description": "The Twitter Bootstrap v5 extension for the Yii framework",
"name": "x221/yii2-bootstrap5-mod",
"description": "The Twitter Bootstrap v5 extension for the Yii framework (Mod Version)",
"keywords": [
"yii2",
"bootstrap",
@ -9,7 +9,7 @@
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
"source": "https://github.com/yiisoft/yii2-bootstrap5"
"source": "https://git.chenx221.cyou/chenx221/yii2-bootstrap5-mod"
},
"authors": [
{
@ -27,11 +27,11 @@
"php": ">=7.0",
"ext-json": "*",
"yiisoft/yii2": "^2.0.42",
"bower-asset/bootstrap": "^5.1.0"
"npm-asset/bootstrap": "^5.3.0"
},
"require-dev": {
"yiisoft/yii2-coding-standards": "~2.0",
"phpunit/phpunit": "^6.5.14",
"phpunit/phpunit": ">=8.5",
"twbs/bootstrap-icons": "^1.7.2"
},
"suggest": {

View File

@ -1,14 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -19,7 +19,7 @@ class BootstrapAsset extends AssetBundle
/**
* @inheritDoc
*/
public $sourcePath = '@bower/bootstrap';
public $sourcePath = '@npm/bootstrap';
/**
* @inheritDoc

View File

@ -19,7 +19,7 @@ class BootstrapPluginAsset extends AssetBundle
/**
* @inheritDoc
*/
public $sourcePath = '@bower/bootstrap';
public $sourcePath = '@npm/bootstrap';
/**
* @inheritDoc

View File

@ -204,7 +204,7 @@ HTML
, $output);
}
public function invalidItemsProvider()
public static function invalidItemsProvider()
{
return [
[['content']], // only content without label key
@ -215,10 +215,11 @@ HTML
/**
* @dataProvider invalidItemsProvider
* @expectedException \yii\base\InvalidConfigException
*
*/
public function testMissingLabel($items)
{
$this->expectException(\yii\base\InvalidConfigException::class);
Accordion::widget([
'items' => $items,
]);
@ -278,12 +279,12 @@ HTML
$output = Accordion::widget([
'items' => $items
]);
$this->assertContains('data-bs-parent="', $output);
$this->assertStringContainsString('data-bs-parent="', $output);
$output = Accordion::widget([
'autoCloseItems' => false,
'items' => $items
]);
$this->assertNotContains('data-bs-parent="', $output);
$this->assertStringNotContainsString('data-bs-parent="', $output);
}
/**
@ -310,8 +311,8 @@ HTML
'class' => 'custom-toggle',
],
]);
$this->assertContains('<h5 class="mb-0"><a type="button" class="custom-toggle" href="#w0-collapse0" ', $output);
$this->assertNotContains('<button', $output);
$this->assertStringContainsString('<h5 class="mb-0"><a type="button" class="custom-toggle" href="#w0-collapse0" ', $output);
$this->assertStringNotContainsString('<button', $output);
$output = Accordion::widget([
'items' => $items,
@ -320,7 +321,7 @@ HTML
'class' => ['widget' => 'custom-toggle'],
],
]);
$this->assertContains('<h5 class="mb-0"><a type="button" class="custom-toggle" href="#w1-collapse0" ', $output);
$this->assertNotContains('collapse-toggle', $output);
$this->assertStringContainsString('<h5 class="mb-0"><a type="button" class="custom-toggle" href="#w1-collapse0" ', $output);
$this->assertStringNotContainsString('collapse-toggle', $output);
}
}

View File

@ -189,7 +189,7 @@ HTML;
$this->assertContainsWithoutLE($expected3, $out);
}
protected function setUp()
protected function setUp(): void
{
// dirty way to have Request object not throwing exception when running testHomeLinkNull()
$_SERVER['SCRIPT_FILENAME'] = 'index.php';

View File

@ -291,7 +291,7 @@ HTML;
]
])->render();
$this->assertContains('data-attribute="test"', $content);
$this->assertStringContainsString('data-attribute="test"', $content);
}
/**
@ -306,10 +306,10 @@ HTML;
]
])->render();
$this->assertContains('data-attribute="test"', $content);
$this->assertStringContainsString('data-attribute="test"', $content);
}
protected function setUp()
protected function setUp(): void
{
// dirty way to have Request object not throwing exception when running testHomeLinkNull()
$_SERVER['SCRIPT_FILENAME'] = "index.php";

View File

@ -397,7 +397,7 @@ HTML;
{
$form = ActiveForm::widget();
$this->assertNotContains('role="form"', $form);
$this->assertStringNotContainsString('role="form"', $form);
}
public function testErrorSummaryRendering()
@ -418,7 +418,7 @@ HTML;
$this->assertContainsWithoutLE('<div class="alert alert-danger"', $out);
}
protected function setUp()
protected function setUp(): void
{
// dirty way to have Request object not throwing exception when running testFormNoRoleAttribute()
$_SERVER['REQUEST_URI'] = "index.php";

View File

@ -28,7 +28,7 @@ class ButtonDropdownTest extends TestCase
],
]);
$this->assertContains("$containerClass dropup btn-group", $out);
$this->assertStringContainsString("$containerClass dropup btn-group", $out);
}
public function testDirection()

View File

@ -90,6 +90,6 @@ HTML;
]
]);
$this->assertContains('class="carousel slide carousel-fade"', $out);
$this->assertStringContainsString('class="carousel slide carousel-fade"', $out);
}
}

View File

@ -13,7 +13,7 @@ class HtmlTest extends TestCase
/**
* @return array
*/
public function dataProviderStaticControl()
public static function dataProviderStaticControl()
{
return [
[

View File

@ -25,22 +25,22 @@ class LinkPagerTest extends TestCase
'firstPageLabel' => true,
'lastPageLabel' => true,
]);
$this->assertContains('<li class="page-item first"><a class="page-link" href="/?r=test&amp;page=1" data-page="0">1</a></li>', $output);
$this->assertContains('<li class="page-item last"><a class="page-link" href="/?r=test&amp;page=25" data-page="24">25</a></li>', $output);
$this->assertStringContainsString('<li class="page-item first"><a class="page-link" href="/?r=test&amp;page=1" data-page="0">1</a></li>', $output);
$this->assertStringContainsString('<li class="page-item last"><a class="page-link" href="/?r=test&amp;page=25" data-page="24">25</a></li>', $output);
$output = LinkPager::widget([
'pagination' => $pagination,
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
]);
$this->assertContains('<li class="page-item first"><a class="page-link" href="/?r=test&amp;page=1" data-page="0">First</a></li>', $output);
$this->assertContains('<li class="page-item last"><a class="page-link" href="/?r=test&amp;page=25" data-page="24">Last</a></li>', $output);
$this->assertStringContainsString('<li class="page-item first"><a class="page-link" href="/?r=test&amp;page=1" data-page="0">First</a></li>', $output);
$this->assertStringContainsString('<li class="page-item last"><a class="page-link" href="/?r=test&amp;page=25" data-page="24">Last</a></li>', $output);
$output = LinkPager::widget([
'pagination' => $pagination,
'firstPageLabel' => false,
'lastPageLabel' => false,
]);
$this->assertNotContains('<li class="page-item first">', $output);
$this->assertNotContains('<li class="page-item last">', $output);
$this->assertStringNotContainsString('<li class="page-item first">', $output);
$this->assertStringNotContainsString('<li class="page-item last">', $output);
}
public function testDisabledPageElementOptions()
@ -49,7 +49,7 @@ class LinkPagerTest extends TestCase
'pagination' => $this->getPagination(0),
'disabledListItemSubTagOptions' => ['class' => ['foo-bar']],
]);
$this->assertContains('<li class="page-item prev disabled"><a class="page-link foo-bar"', $output);
$this->assertStringContainsString('<li class="page-item prev disabled"><a class="page-link foo-bar"', $output);
}
/**
@ -60,7 +60,7 @@ class LinkPagerTest extends TestCase
'pagination' => $this->getPagination(0),
'disabledListItemSubTagOptions' => ['class' => new ReplaceArrayValue(['foo-bar'])],
]);
$this->assertContains('<li class="page-item prev disabled"><a class="foo-bar"', $output);
$this->assertStringContainsString('<li class="page-item prev disabled"><a class="foo-bar"', $output);
}
public function testDisableCurrentPageButton()
@ -70,12 +70,12 @@ class LinkPagerTest extends TestCase
'pagination' => $pagination,
'disableCurrentPageButton' => false,
]);
$this->assertContains('<li class="page-item active" aria-current="page"><a class="page-link" href="/?r=test&amp;page=6" data-page="5">6</a></li>', $output);
$this->assertStringContainsString('<li class="page-item active" aria-current="page"><a class="page-link" href="/?r=test&amp;page=6" data-page="5">6</a></li>', $output);
$output = LinkPager::widget([
'pagination' => $pagination,
'disableCurrentPageButton' => true,
]);
$this->assertContains('<li class="page-item active disabled" aria-current="page"><a class="page-link" href="/?r=test&amp;page=6" data-page="5" tabindex="-1">6</a></li>', $output);
$this->assertStringContainsString('<li class="page-item active disabled" aria-current="page"><a class="page-link" href="/?r=test&amp;page=6" data-page="5" tabindex="-1">6</a></li>', $output);
}
public function testOptionsWithTagOption()
@ -100,11 +100,11 @@ class LinkPagerTest extends TestCase
'class' => 'my-class',
],
]);
$this->assertContains(
$this->assertStringContainsString(
'<div class="my-class page-item"><a class="page-link" href="/?r=test&amp;page=3" data-page="2">3</a></div>',
$output
);
$this->assertContains(
$this->assertStringContainsString(
'<div class="my-class page-item active" aria-current="page"><a class="page-link" href="/?r=test&amp;page=2" data-page="1">2</a></div>',
$output
);
@ -125,7 +125,7 @@ class LinkPagerTest extends TestCase
$this->assertTrue($initTriggered);
}
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->mockWebApplication([

View File

@ -108,7 +108,7 @@ HTML;
Modal::end();
$out = ob_get_clean();
$this->assertContains(
$this->assertStringContainsString(
'<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#w0">Launch demo modal</button>',
$out
);

View File

@ -46,9 +46,9 @@ EXPECTED;
'brandUrl' => '/',
]);
$this->assertContains('<a class="navbar-brand" href="/"><img src="/images/test.jpg" alt=""></a>', $out);
$this->assertStringContainsString('<a class="navbar-brand" href="/"><img src="/images/test.jpg" alt=""></a>', $out);
}
public function testBrandImageOptions()
{
$out = NavBar::widget([
@ -57,7 +57,7 @@ EXPECTED;
'brandUrl' => '/',
]);
$this->assertContains('<a class="navbar-brand" href="/"><img src="/images/test.jpg" alt="test image"></a>', $out);
$this->assertStringContainsString('<a class="navbar-brand" href="/"><img src="/images/test.jpg" alt="test image"></a>', $out);
}
public function testBrandLink()
@ -67,7 +67,7 @@ EXPECTED;
'brandUrl' => false,
]);
$this->assertContains('<a class="navbar-brand" href="/index.php">Yii Framework</a>', $out);
$this->assertStringContainsString('<a class="navbar-brand" href="/index.php">Yii Framework</a>', $out);
}
public function testBrandSpan()
@ -77,7 +77,7 @@ EXPECTED;
'brandUrl' => null,
]);
$this->assertContains('<span class="navbar-brand">Yii Framework</span>', $out);
$this->assertStringContainsString('<span class="navbar-brand">Yii Framework</span>', $out);
}
/**

View File

@ -347,7 +347,7 @@ EXPECTED;
$this->assertEqualsWithoutLE($expected, $out);
}
protected function setUp()
protected function setUp(): void
{
$this->mockWebApplication([
'components' => [

View File

@ -86,7 +86,7 @@ HTML;
Offcanvas::end();
$out = ob_get_clean();
$this->assertContains(
$this->assertStringContainsString(
'<button type="button" class="btn btn-primary" data-bs-toggle="offcanvas" data-bs-target="#w0" aria-controls="w0">Launch demo offcanvas</button>',
$out
);

View File

@ -36,7 +36,8 @@ HTML;
$js = Yii::$app->view->js[View::POS_READY];
$this->assertInternalType(IsType::TYPE_ARRAY, $js);
// $this->assertInternalType(IsType::TYPE_ARRAY, $js);
$this->assertIsArray($js);
$options = array_shift($js);
$this->assertContainsWithoutLE("(new bootstrap.Popover('#w0', {", $options);
@ -55,7 +56,8 @@ HTML;
$js = Yii::$app->view->js[View::POS_READY];
$this->assertInternalType(IsType::TYPE_ARRAY, $js);
// $this->assertInternalType(IsType::TYPE_ARRAY, $js);
$this->assertIsArray($js);
$options = array_shift($js);
$this->assertContainsWithoutLE('"content":"\u003Cspan class=\u0022test-content\u0022\u003ETest content\u003C\/span\u003E"', $options);

View File

@ -140,11 +140,11 @@ class TabsTest extends TestCase
]
]);
$this->assertNotContains('InvisiblePage', $html);
$this->assertNotContains('Invisible Page Content', $html);
$this->assertNotContains('InvisibleItem', $html);
$this->assertNotContains('Invisible Item Content', $html);
$this->assertNotContains('Invisible External Link', $html);
$this->assertStringNotContainsString('InvisiblePage', $html);
$this->assertStringNotContainsString('Invisible Page Content', $html);
$this->assertStringNotContainsString('InvisibleItem', $html);
$this->assertStringNotContainsString('Invisible Item Content', $html);
$this->assertStringNotContainsString('Invisible External Link', $html);
}
public function testDisabled()
@ -179,23 +179,23 @@ class TabsTest extends TestCase
]
]);
$this->assertContains(
$this->assertStringContainsString(
'<li class="nav-item"><a class="nav-link disabled" href="#w0-tab0" data-bs-toggle="tab" role="tab" aria-controls="w0-tab0" aria-disabled="true" tabindex="-1">Page1</a></li>',
$html
);
$this->assertContains(
$this->assertStringContainsString(
'<li class="nav-item"><a class="nav-link active" href="#w0-tab1" data-bs-toggle="tab" role="tab" aria-controls="w0-tab1" aria-selected="true">Page2</a></li>',
$html
);
$this->assertContains(
$this->assertStringContainsString(
'<li class="nav-item"><a class="nav-link disabled" href="#w0-tab2" data-bs-toggle="tab" role="tab" aria-controls="w0-tab2" aria-disabled="true" tabindex="-1">DisabledPage</a></li>',
$html
);
$this->assertContains(
$this->assertStringContainsString(
'<a class="dropdown-item disabled" href="#w0-dd3-tab1" data-bs-toggle="tab" role="tab" aria-controls="w0-dd3-tab1" aria-disabled="true" tabindex="-1">DisabledItem</a>',
$html
);
$this->assertContains(
$this->assertStringContainsString(
'<a class="dropdown-item disabled" href="/index.php?r=other%2Fdropdown%2Froute" tabindex="-1" aria-disabled="true">Disabled External Link</a>',
$html
);
@ -220,7 +220,7 @@ class TabsTest extends TestCase
'renderTabContent' => true,
]);
$this->assertContains('<' . $checkTag, $out);
$this->assertStringContainsString('<' . $checkTag, $out);
}
public function testTabContentOptions()
@ -240,8 +240,8 @@ class TabsTest extends TestCase
]
]);
$this->assertContains($checkAttribute . '=', $out);
$this->assertContains($checkValue, $out);
$this->assertStringContainsString($checkAttribute . '=', $out);
$this->assertStringContainsString($checkValue, $out);
}
public function testActivateFirstVisibleTab()
@ -270,15 +270,15 @@ class TabsTest extends TestCase
]
]);
$this->assertNotContains(
$this->assertStringNotContainsString(
'<li class="nav-item"><a class="nav-link active" href="#mytab-tab0" data-bs-toggle="tab" role="tab" aria-controls="mytab-tab0" aria-selected="true">Tab 1</a></li>',
$html
);
$this->assertNotContains(
$this->assertStringNotContainsString(
'<li class="nav-item"><a class="nav-link active" href="#mytab-tab1" data-bs-toggle="tab" role="tab" aria-controls="mytab-tab1" aria-selected="true">Tab 2</a></li>',
$html
);
$this->assertContains(
$this->assertStringContainsString(
'<li class="nav-item"><a class="nav-link active" href="#mytab-tab2" data-bs-toggle="tab" role="tab" aria-controls="mytab-tab2" aria-selected="true">Tab 3</a></li>',
$html
);
@ -309,7 +309,7 @@ class TabsTest extends TestCase
]
]
]);
$this->assertContains(
$this->assertStringContainsString(
'<li class="nav-item"><a class="nav-link active" href="#mytab-tab2" data-bs-toggle="tab" role="tab" aria-controls="mytab-tab2" aria-selected="true">Tab 3</a></li>',
$html
);
@ -336,9 +336,9 @@ class TabsTest extends TestCase
],
]
]);
$this->assertContains('&lt;span&gt;encoded&lt;/span&gt;', $html);
$this->assertContains('<span>not encoded</span>', $html);
$this->assertContains('<span>not encoded too</span>', $html);
$this->assertStringContainsString('&lt;span&gt;encoded&lt;/span&gt;', $html);
$this->assertStringContainsString('<span>not encoded</span>', $html);
$this->assertStringContainsString('<span>not encoded too</span>', $html);
}
/**
@ -403,6 +403,6 @@ HTML;
<div id="w0-tab1" class="tab-pane"><div>Content 2</div></div></div>
HTML;
$this->assertEquals($expected, $html);
$this->assertEqualsWithoutLE($expected, $html);
}
}

View File

@ -39,13 +39,13 @@ class TestCase extends \PHPUnit\Framework\TestCase
$needle = str_replace("\r\n", "\n", $needle);
$haystack = str_replace("\r\n", "\n", $haystack);
$this->assertContains($needle, $haystack);
$this->assertStringContainsString($needle, $haystack);
}
/**
* {@inheritDoc}
*/
protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->mockWebApplication();
@ -54,7 +54,7 @@ class TestCase extends \PHPUnit\Framework\TestCase
/**
* {@inheritDoc}
*/
protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->destroyApplication();

View File

@ -132,12 +132,13 @@ HTML;
Toast::end();
$out = ob_get_clean();
$this->assertInternalType(IsType::TYPE_ARRAY, $toast->clientOptions);
$this->assertIsArray($toast->clientOptions);
$this->assertCount(0, $toast->clientOptions);
$js = Yii::$app->view->js[View::POS_READY];
$this->assertInternalType(IsType::TYPE_ARRAY, $js);
// $this->assertInternalType(IsType::TYPE_ARRAY, $js);
$this->assertIsArray($js);
$options = array_shift($js);
$this->assertContainsWithoutLE("(new bootstrap.Toast('#w0', {}));", $options);
@ -180,7 +181,8 @@ HTML;
$this->assertArrayHasKey(View::POS_READY, Yii::$app->view->js);
$js = Yii::$app->view->js[View::POS_READY];
$this->assertInternalType(IsType::TYPE_ARRAY, $js);
// $this->assertInternalType(IsType::TYPE_ARRAY, $js);
$this->assertIsArray($js);
$options = array_shift($js);
$this->assertContainsWithoutLE("(new bootstrap.Toast('#w0', {\"delay\":1000}));", $options);

View File

@ -48,7 +48,7 @@ HTML;
],
]);
$this->assertContains('<input type="checkbox" id="i1" class="btn-check" name="ToggleButtonGroupTestModel[value][]" value="2" checked autocomplete="off">', $html);
$this->assertStringContainsString('<input type="checkbox" id="i1" class="btn-check" name="ToggleButtonGroupTestModel[value][]" value="2" checked autocomplete="off">', $html);
}
public function testRadio()
@ -88,7 +88,7 @@ HTML;
],
]);
$this->assertContains('<input type="radio" id="i1" class="btn-check" name="ToggleButtonGroupTestModel[value]" value="2" checked autocomplete="off">', $html);
$this->assertStringContainsString('<input type="radio" id="i1" class="btn-check" name="ToggleButtonGroupTestModel[value]" value="2" checked autocomplete="off">', $html);
}
}

View File

@ -11,7 +11,7 @@ use yii\bootstrap5\Breadcrumbs;
class TranslationTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
$this->mockWebApplication([
'language' => 'de-CH',

View File

@ -13,7 +13,7 @@ use yii\bootstrap5\ActiveField;
*/
class ExtendedActiveField extends ActiveField
{
public ?array $horizontalCssClasses = [
public $horizontalCssClasses = [
'offset' => 'col-md-offset-4',
'label' => 'col-md-4',
'wrapper' => 'col-md-6',