Browse Source

Adjusted widget tests

tags/3.0.0-alpha1
Alexander Makarov 8 years ago
parent
commit
a7b9ef650c
No known key found for this signature in database
GPG Key ID: 3617B79C6A325E4A
  1. 4
      tests/framework/grid/RadiobuttonColumnTest.php
  2. 45
      tests/framework/widgets/ListViewTest.php

4
tests/framework/grid/RadiobuttonColumnTest.php

@ -86,9 +86,7 @@ class RadiobuttonColumnTest extends TestCase
] ]
] ]
]); ]);
ob_start(); $actual = $grid->run();
$grid->run();
$actual = ob_get_clean();
$this->assertEqualsWithoutLE(<<<HTML $this->assertEqualsWithoutLE(<<<HTML
<div id="radio-gridview"><div class="summary">Showing <b>1-2</b> of <b>2</b> items.</div> <div id="radio-gridview"><div class="summary">Showing <b>1-2</b> of <b>2</b> items.</div>
<table class="table table-striped table-bordered"><thead> <table class="table table-striped table-bordered"><thead>

45
tests/framework/widgets/ListViewTest.php

@ -20,27 +20,27 @@ class ListViewTest extends \yiiunit\TestCase
public function testEmptyListShown() public function testEmptyListShown()
{ {
$this->getListView([ $actual = $this->getListView([
'dataProvider' => new ArrayDataProvider(['allModels' => []]), 'dataProvider' => new ArrayDataProvider(['allModels' => []]),
'emptyText' => "Nothing at all", 'emptyText' => "Nothing at all",
])->run(); ])->run();
$this->expectOutputString('<div id="w0" class="list-view"><div class="empty">Nothing at all</div></div>'); $this->assertEqualsWithoutLE('<div id="w0" class="list-view"><div class="empty">Nothing at all</div></div>', $actual);
} }
public function testEmptyListNotShown() public function testEmptyListNotShown()
{ {
$this->getListView([ $actual = $this->getListView([
'dataProvider' => new ArrayDataProvider(['allModels' => []]), 'dataProvider' => new ArrayDataProvider(['allModels' => []]),
'showOnEmpty' => true, 'showOnEmpty' => true,
])->run(); ])->run();
$this->expectOutputString(<<<HTML $expected = <<<HTML
<div id="w0" class="list-view"> <div id="w0" class="list-view">
</div> </div>
HTML HTML;
); $this->assertEqualsWithoutLE($expected, $actual);
} }
private function getListView($options = []) private function getListView($options = [])
@ -64,28 +64,29 @@ HTML
public function testSimplyListView() public function testSimplyListView()
{ {
$this->getListView()->run(); $actual = $this->getListView()->run();
$this->expectOutputString(<<<HTML $expected = <<<HTML
<div id="w0" class="list-view"><div class="summary">Showing <b>1-3</b> of <b>3</b> items.</div> <div id="w0" class="list-view"><div class="summary">Showing <b>1-3</b> of <b>3</b> items.</div>
<div data-key="0">0</div> <div data-key="0">0</div>
<div data-key="1">1</div> <div data-key="1">1</div>
<div data-key="2">2</div> <div data-key="2">2</div>
</div> </div>
HTML HTML;
);
$this->assertEqualsWithoutLE($expected, $actual);
} }
public function testWidgetOptions() public function testWidgetOptions()
{ {
$this->getListView(['options' => ['class' => 'test-passed'], 'separator' => ''])->run(); $actual = $this->getListView(['options' => ['class' => 'test-passed'], 'separator' => ''])->run();
$this->expectOutputString(<<<HTML $expected = <<<HTML
<div id="w0" class="test-passed"><div class="summary">Showing <b>1-3</b> of <b>3</b> items.</div> <div id="w0" class="test-passed"><div class="summary">Showing <b>1-3</b> of <b>3</b> items.</div>
<div data-key="0">0</div><div data-key="1">1</div><div data-key="2">2</div> <div data-key="0">0</div><div data-key="1">1</div><div data-key="2">2</div>
</div> </div>
HTML HTML;
); $this->assertEqualsWithoutLE($expected, $actual);
} }
public function itemViewOptions() public function itemViewOptions()
@ -125,8 +126,8 @@ HTML
*/ */
public function testItemViewOptions($itemView, $expected) public function testItemViewOptions($itemView, $expected)
{ {
$this->getListView(['itemView' => $itemView])->run(); $actual = $this->getListView(['itemView' => $itemView])->run();
$this->expectOutputString($expected); $this->assertEqualsWithoutLE($expected, $actual);
} }
public function itemOptions() public function itemOptions()
@ -167,8 +168,8 @@ HTML
*/ */
public function testItemOptions($itemOptions, $expected) public function testItemOptions($itemOptions, $expected)
{ {
$this->getListView(['itemOptions' => $itemOptions])->run(); $actual = $this->getListView(['itemOptions' => $itemOptions])->run();
$this->expectOutputString($expected); $this->assertEqualsWithoutLE($expected, $actual);
} }
public function testBeforeAndAfterItem() public function testBeforeAndAfterItem()
@ -184,12 +185,12 @@ HTML
$widget = get_class($widget); $widget = get_class($widget);
return "<!-- after: {$model['id']}, key: $key, index: $index, widget: $widget -->"; return "<!-- after: {$model['id']}, key: $key, index: $index, widget: $widget -->";
}; };
$this->getListView([ $actual = $this->getListView([
'beforeItem' => $before, 'beforeItem' => $before,
'afterItem' => $after 'afterItem' => $after
])->run(); ])->run();
$this->expectOutputString(<<<HTML $expected = <<<HTML
<div id="w0" class="list-view"><div class="summary">Showing <b>1-3</b> of <b>3</b> items.</div> <div id="w0" class="list-view"><div class="summary">Showing <b>1-3</b> of <b>3</b> items.</div>
<!-- before: 1, key: 0, index: 0, widget: yii\widgets\ListView --> <!-- before: 1, key: 0, index: 0, widget: yii\widgets\ListView -->
<div data-key="0">0</div> <div data-key="0">0</div>
@ -200,7 +201,7 @@ HTML
<div data-key="2">2</div> <div data-key="2">2</div>
<!-- after: 3, key: 2, index: 2, widget: yii\widgets\ListView --> <!-- after: 3, key: 2, index: 2, widget: yii\widgets\ListView -->
</div> </div>
HTML HTML;
); $this->assertEqualsWithoutLE($expected, $actual);
} }
} }

Loading…
Cancel
Save