Skip to content

Commit

Permalink
#14: add ListView::itemViewTag() and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
glpzzz committed Sep 7, 2024
1 parent 1914426 commit 78b18b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ public function itemView(string|Closure $value): self
return $new;
}

public function itemViewTag(?string $tag): self
{
$new = clone $this;
$new->itemViewTag= $tag;

Check failure on line 142 in src/ListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

PropertyTypeCoercion

src/ListView.php:142:28: PropertyTypeCoercion: $new->itemViewTag expects 'non-empty-string|null', parent type 'null|string' provided (see https://psalm.dev/198)

Check failure on line 142 in src/ListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.2-ubuntu-latest

PropertyTypeCoercion

src/ListView.php:142:28: PropertyTypeCoercion: $new->itemViewTag expects 'non-empty-string|null', parent type 'null|string' provided (see https://psalm.dev/198)

Check failure on line 142 in src/ListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.3-ubuntu-latest

PropertyTypeCoercion

src/ListView.php:142:28: PropertyTypeCoercion: $new->itemViewTag expects 'non-empty-string|null', parent type 'null|string' provided (see https://psalm.dev/198)
return $new;
}

/**
* return new instance with the HTML attributes for the container of item view.
*
Expand Down
27 changes: 27 additions & 0 deletions tests/ListView/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,31 @@ public function testChangeItemsWrapperTag(): void
);
}

public function testChangeItemsAndItemWrapperTag(): void
{
Assert::equalsWithoutLE(
<<<HTML
<div>
<div>
<div>
<div>Id: 1</div><div>Name: John</div><div>Age: 20</div>
</div>
<div>
<div>Id: 2</div><div>Name: Mary</div><div>Age: 21</div>
</div>
</div>
<div>Page <b>1</b> of <b>1</b></div>
</div>
HTML,
ListView::widget()
->itemsWrapperTag('div')
->itemViewTag('div')
->itemView(dirname(__DIR__) . '/Support/view/_listview.php')
->dataReader($this->createOffsetPaginator($this->data, 10))
->render(),
);
}

public function testChangeItemsWrapperTagAttributes(): void
{
Assert::equalsWithoutLE(
Expand All @@ -315,4 +340,6 @@ public function testChangeItemsWrapperTagAttributes(): void
->render(),
);
}


}

0 comments on commit 78b18b0

Please sign in to comment.