StandardTest::testHeader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 19
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2019-2025
6
 */
7
8
9
namespace Aimeos\Client\Html\Catalog\Product;
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
		\Aimeos\Controller\Frontend::cache( true );
22
		\Aimeos\MShop::cache( true );
23
24
		$this->view = \TestHelper::view();
25
		$this->context = \TestHelper::context();
26
		$this->context->config()->set( 'client/html/catalog/product/product-codes', ['CNE', 'ABCD', 'CNC'] );
27
28
		$this->object = new \Aimeos\Client\Html\Catalog\Product\Standard( $this->context );
29
		$this->object->setView( $this->view );
30
	}
31
32
33
	protected function tearDown() : void
34
	{
35
		\Aimeos\Controller\Frontend::cache( false );
36
		\Aimeos\MShop::cache( false );
37
38
		unset( $this->object, $this->context, $this->view );
39
	}
40
41
42
	public function testHeader()
43
	{
44
45
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
46
		$filter = $manager->filter()->add( ['product.code' => ['CNE', 'ABCD', 'CNC']] );
47
		$map = $manager->search( $filter )->col( 'product.id', 'product.code' );
48
49
		$tags = [];
50
		$expire = null;
51
52
		$this->object->setView( $this->object->data( $this->view, $tags, $expire ) );
53
		$output = $this->object->header();
54
55
		$this->assertStringContainsString( '<script', $output );
56
		$prodCodeParam = '/st_pid%5B[0-9]%5D=';
57
		$this->assertMatchesRegularExpression( $prodCodeParam . $map['CNE'] . '/', $output );
58
		$this->assertMatchesRegularExpression( $prodCodeParam . $map['ABCD'] . '/', $output );
59
		$this->assertMatchesRegularExpression( $prodCodeParam . $map['CNC'] . '/', $output );
60
		$this->assertEquals( '2098-01-01 00:00:00', $expire );
61
	}
62
63
64
	public function testBody()
65
	{
66
67
		$tags = [];
68
		$expire = null;
69
70
		$this->object->setView( $this->object->data( $this->view, $tags, $expire ) );
71
		$output = $this->object->body();
72
73
		$productNameCNE = '<h2 class="name" itemprop="name">Cafe Noire Expresso</h2>';
74
		$productNameABCD = '<h2 class="name" itemprop="name">Unterproduct 1</h2>';
75
		$productNameCNC = '<h2 class="name" itemprop="name">Cafe Noire Cappuccino</h2>';
76
		$this->assertStringContainsString( $productNameCNE, $output );
77
		$this->assertStringContainsString( $productNameABCD, $output );
78
		$this->assertStringContainsString( $productNameCNC, $output );
79
80
		$outputPosCNE = strpos( $output, $productNameCNE );
81
		$outputPosABCD = strpos( $output, $productNameABCD );
82
		$outputPosCNC = strpos( $output, $productNameCNC );
83
		$this->assertGreaterThan( $outputPosCNE, $outputPosABCD );
84
		$this->assertGreaterThan( $outputPosABCD, $outputPosCNC );
85
86
		$this->assertEquals( '2098-01-01 00:00:00', $expire );
87
	}
88
}
89