1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2025 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Client\Html\Cms\Page\Cataloglist; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private $view; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelper::context(); |
22
|
|
|
$this->view = $this->context->view(); |
23
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\Client\Html\Cms\Page\Cataloglist\Standard( $this->context ); |
25
|
|
|
$this->object->setView( $this->view ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
protected function tearDown() : void |
30
|
|
|
{ |
31
|
|
|
unset( $this->object, $this->context, $this->view ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
public function testData() |
36
|
|
|
{ |
37
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'catalog' ); |
38
|
|
|
$catId1 = $manager->find( 'cafe' )->getId(); |
|
|
|
|
39
|
|
|
$catId2 = $manager->find( 'new' )->getId(); |
40
|
|
|
|
41
|
|
|
$view = $this->view; |
42
|
|
|
$view->pageCmsItem = \Aimeos\MShop::create( $this->context, 'cms' )->find( '/catlist', ['text'] ); |
43
|
|
|
|
44
|
|
|
$textItems = $view->pageCmsItem->getRefItems( 'text', 'content' )->map( function( $item ) { |
45
|
|
|
$data = ( $json = json_decode( $item->getContent(), true ) ) ? $json['html'] : $item->getContent(); |
46
|
|
|
return '<div class="cms-content>' . $data . '</div>'; |
47
|
|
|
} )->all(); |
48
|
|
|
|
49
|
|
|
$this->assertEquals( 1, count( $textItems ) ); |
50
|
|
|
|
51
|
|
|
foreach( $textItems as $textItem ) { |
52
|
|
|
$textItem = str_replace( ['_cat1_', '_cat2_'], [$catId1, $catId2], $textItem ); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$view->pageContent = $textItems; |
56
|
|
|
|
57
|
|
|
$view = $this->object->data( $view ); |
58
|
|
|
|
59
|
|
|
foreach( $view->pageContent as $text ) { |
60
|
|
|
$this->assertStringContainsString( '<div class="catalog-list', $text ); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testModify() |
66
|
|
|
{ |
67
|
|
|
$output = 'BEFORE<!-- catalog.lists.items.csrf -->CSRF<!-- catalog.lists.items.csrf -->AFTER'; |
68
|
|
|
|
69
|
|
|
$output = $this->object->modify( $output, 1 ); |
70
|
|
|
|
71
|
|
|
$this->assertStringContainsString( '<input class="csrf-token" type="hidden" name="_csrf_token" value="_csrf_value"', $output ); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|