1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* @copyright 2014 Mautic Contributors. All rights reserved |
5
|
|
|
* @author Mautic |
6
|
|
|
* |
7
|
|
|
* @link http://mautic.org |
8
|
|
|
* |
9
|
|
|
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mautic\PageBundle\Tests\Model; |
13
|
|
|
|
14
|
|
|
use Mautic\CoreBundle\Entity\IpAddress; |
15
|
|
|
use Mautic\LeadBundle\Entity\Lead; |
16
|
|
|
use Mautic\PageBundle\Entity\Hit; |
17
|
|
|
use Mautic\PageBundle\Entity\Page; |
18
|
|
|
use Mautic\PageBundle\Tests\PageTestAbstract; |
19
|
|
|
use ReflectionClass; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
|
22
|
|
|
class PageModelTest extends PageTestAbstract |
23
|
|
|
{ |
24
|
|
|
public function testUtf8CharsInTitleWithTransletirationEnabled() |
25
|
|
|
{ |
26
|
|
|
$providedTitle = '你好,世界'; |
27
|
|
|
$expectedTitle = 'ni hao, shi jie'; |
28
|
|
|
$hit = new Hit(); |
29
|
|
|
$page = new Page(); |
30
|
|
|
$request = new Request(); |
31
|
|
|
$contact = new Lead(); |
32
|
|
|
$pageModel = $this->getPageModel(); |
33
|
|
|
|
34
|
|
|
$hit->setIpAddress(new IpAddress()); |
35
|
|
|
$hit->setQuery(['page_title' => $providedTitle]); |
36
|
|
|
|
37
|
|
|
$pageModel->processPageHit($hit, $page, $request, $contact, false); |
38
|
|
|
|
39
|
|
|
$this->assertSame($expectedTitle, $hit->getUrlTitle()); |
40
|
|
|
$this->assertSame(['page_title' => $expectedTitle], $hit->getQuery()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testUtf8CharsInTitleWithTransletirationDisabled() |
44
|
|
|
{ |
45
|
|
|
$providedTitle = '你好,世界'; |
46
|
|
|
$expectedTitle = '你好,世界'; |
47
|
|
|
$hit = new Hit(); |
48
|
|
|
$page = new Page(); |
49
|
|
|
$request = new Request(); |
50
|
|
|
$contact = new Lead(); |
51
|
|
|
$pageModel = $this->getPageModel(false); |
52
|
|
|
|
53
|
|
|
$hit->setIpAddress(new IpAddress()); |
54
|
|
|
$hit->setQuery(['page_title' => $providedTitle]); |
55
|
|
|
|
56
|
|
|
$pageModel->processPageHit($hit, $page, $request, $contact, false); |
57
|
|
|
|
58
|
|
|
$this->assertSame($expectedTitle, $hit->getUrlTitle()); |
59
|
|
|
$this->assertSame(['page_title' => $expectedTitle], $hit->getQuery()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGenerateUrl_WhenCalled_ReturnsValidUrl() |
63
|
|
|
{ |
64
|
|
|
$page = new Page(); |
65
|
|
|
$page->setAlias('this-is-a-test'); |
66
|
|
|
$pageModel = $this->getPageModel(); |
67
|
|
|
$url = $pageModel->generateUrl($page); |
68
|
|
|
$this->assertContains('/this-is-a-test', $url); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testCleanQuery_WhenCalled_ReturnsSafeAndValidData() |
72
|
|
|
{ |
73
|
|
|
$pageModel = $this->getPageModel(); |
74
|
|
|
$pageModelReflection = new ReflectionClass(get_class($pageModel)); |
75
|
|
|
$cleanQueryMethod = $pageModelReflection->getMethod('cleanQuery'); |
76
|
|
|
$cleanQueryMethod->setAccessible(true); |
77
|
|
|
$res = $cleanQueryMethod->invokeArgs($pageModel, [ |
78
|
|
|
[ |
79
|
|
|
'page_title' => 'Mautic & PHP', |
80
|
|
|
'page_url' => 'http://mautic.com/page/test?hello=world&lorem=ipsum', |
81
|
|
|
'page_language' => 'en', |
82
|
|
|
], |
83
|
|
|
]); |
84
|
|
|
$this->assertEquals($res, [ |
85
|
|
|
'page_title' => 'Mautic & PHP', |
86
|
|
|
'page_url' => 'http://mautic.com/page/test?hello=world&lorem=ipsum', |
87
|
|
|
'page_language' => 'en', |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|