yii2-bootstrap5/tests/CarouselTest.php

96 lines
4.6 KiB
PHP
Raw Normal View History

<?php
namespace yiiunit\extensions\bootstrap5;
use yii\bootstrap5\Carousel;
/**
* @group bootstrap5
*/
class CarouselTest extends TestCase
{
function testContainerOptions()
{
Carousel::$counter = 0;
$out = Carousel::widget([
'items' => [
[
'content' => '<img src="https://via.placeholder.com/800x400?text=First+slide" class="d-block w-100">',
'caption' => '<h5>First slide label</h5><p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>',
'captionOptions' => [
'class' => ['d-none', 'd-md-block']
]
],
[
'content' => '<img src="https://via.placeholder.com/800x400?text=Second+slide" class="d-block w-100">',
'caption' => '<h5>Second slide label</h5><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>',
'captionOptions' => [
'class' => ['d-none', 'd-md-block']
]
],
[
'content' => '<img src="https://via.placeholder.com/800x400?text=Third+slide" class="d-block w-100">',
'caption' => '<h5>Third slide label</h5><p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>',
'captionOptions' => [
'class' => ['d-none', 'd-md-block']
]
]
]
]);
$expected = <<<HTML
<div id="w0" class="carousel slide" data-bs-ride="carousel">
<ol class="carousel-indicators"><li class="active" data-target="#w0" data-slide-to="0"></li>
<li data-target="#w0" data-slide-to="1"></li>
<li data-target="#w0" data-slide-to="2"></li></ol>
<div class="carousel-inner"><div class="carousel-item active"><img src="https://via.placeholder.com/800x400?text=First+slide" class="d-block w-100">
<div class="d-none d-md-block carousel-caption"><h5>First slide label</h5><p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p></div></div>
<div class="carousel-item"><img src="https://via.placeholder.com/800x400?text=Second+slide" class="d-block w-100">
<div class="d-none d-md-block carousel-caption"><h5>Second slide label</h5><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></div></div>
<div class="carousel-item"><img src="https://via.placeholder.com/800x400?text=Third+slide" class="d-block w-100">
<div class="d-none d-md-block carousel-caption"><h5>Third slide label</h5><p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p></div></div></div>
<a class="carousel-control-prev" href="#w0" data-slide="prev" role="button"><span class="carousel-control-prev-icon" aria-hidden="true"></span><span class="visually-hidden">Previous</span></a>
<a class="carousel-control-next" href="#w0" data-slide="next" role="button"><span class="carousel-control-next-icon" aria-hidden="true"></span><span class="visually-hidden">Next</span></a>
</div>
HTML;
$this->assertEqualsWithoutLE($expected, $out);
}
/**
* @depends testContainerOptions
*/
public function testCrossfade()
{
Carousel::$counter = 0;
$out = Carousel::widget([
'crossfade' => true,
'items' => [
[
'content' => '<img src="https://via.placeholder.com/800x400?text=First+slide" class="d-block w-100">',
'caption' => '<h5>First slide label</h5><p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>',
'captionOptions' => [
'class' => ['d-none', 'd-md-block']
]
],
[
'content' => '<img src="https://via.placeholder.com/800x400?text=Second+slide" class="d-block w-100">',
'caption' => '<h5>Second slide label</h5><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>',
'captionOptions' => [
'class' => ['d-none', 'd-md-block']
]
],
[
'content' => '<img src="https://via.placeholder.com/800x400?text=Third+slide" class="d-block w-100">',
'caption' => '<h5>Third slide label</h5><p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>',
'captionOptions' => [
'class' => ['d-none', 'd-md-block']
]
]
]
]);
$this->assertContains('class="carousel slide carousel-fade"', $out);
}
}