. * */ namespace Ampache\Gui\Browse\ListRenderer; use Ampache\MockeryTestCase; use Ampache\Module\Database\Query\Browse; use Override; /** * A renderer whose only per-render value is the id list it was handed. */ final class RowsListRenderer extends AbstractBrowseListRenderer { public ?BrowseListContext $nested = null; /** * Prints its rows, renders the nested context once, then prints its rows again. */ public function body(): string { $output = implode(',', $this->getRows()); $nested = $this->nested; if ($nested !== null) { $this->nested = null; $output .= ' [' . $this->renderList($nested) . '] ' . implode(',', $this->getRows()); } return $output; } /** * @return list */ public function getRows(): array { /** @var list */ return $this->cachePerRender('rows', $this->getObjectIds(...)); } #[Override] protected function templateFile(): string { return __DIR__ . '/fixtures/rows.phtml'; } } class AbstractBrowseListRendererTest extends MockeryTestCase { /** * Two disk sections on one album page render the same shared renderer twice, so the second must not * inherit the first one's rows. */ public function testRenderCacheIsRebuiltForEachRender(): void { $subject = new RowsListRenderer(); $this->assertSame('1,3,2', $subject->renderList($this->createContext([1, 3, 2]))); $this->assertSame('4,5', $subject->renderList($this->createContext([4, 5]))); } /** * A template rendering a second browse of the same type must leave the outer render's rows intact. */ public function testRenderCacheIsRestoredAfterANestedRender(): void { $subject = new RowsListRenderer(); $subject->nested = $this->createContext([4, 5]); $this->assertSame('1,3,2 [4,5] 1,3,2', $subject->renderList($this->createContext([1, 3, 2]))); } /** * @param list $objectIds */ private function createContext(array $objectIds): BrowseListContext { return new BrowseListContext( $this->mock(Browse::class), $objectIds, [], '', '', false, false ); } }