1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package comments |
5
|
|
|
*/ |
6
|
|
|
class FindElasticaPageExtensionTest extends ElasticsearchBaseTest { |
7
|
|
|
public static $fixture_file = 'elastica/tests/ElasticaTest.yml'; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Test a valid identifier |
12
|
|
|
*/ |
13
|
|
|
public function testValidIdentifier() { |
14
|
|
|
$searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
15
|
|
|
|
16
|
|
|
//FindElasticaPageExtension is attached to SiteTree so we can search with any page. Here it |
17
|
|
|
//convenient to use the target pgae in order to test for comparison |
18
|
|
|
$found = $searchPage->getSearchPage('testsearchpage'); |
19
|
|
|
|
20
|
|
|
$this->assertEquals($searchPage->ID, $found->ID); |
21
|
|
|
$this->assertEquals($searchPage->ClassName, $found->ClassName); |
22
|
|
|
$this->assertEquals($searchPage->Title, $found->Title); |
23
|
|
|
$this->assertEquals('testsearchpage', $found->Identifier); |
24
|
|
|
|
25
|
|
|
// don't check the server name as this will differ, just check the path is /search/ |
26
|
|
|
$uri = $searchPage->SearchPageURI('testsearchpage'); |
27
|
|
|
$splits = explode('/', $uri); |
28
|
|
|
$this->assertEquals($splits[3],'search'); |
29
|
|
|
|
30
|
|
|
// check the form |
31
|
|
|
$form = $searchPage->SearchPageForm('testsearchpage'); |
32
|
|
|
$this->assertInstanceOf('ElasticSearchForm',$form); |
33
|
|
|
|
34
|
|
|
$fields = $form->Fields(); |
35
|
|
|
$actions = $form->Actions(); |
36
|
|
|
|
37
|
|
|
// check for the query text box field |
38
|
|
|
$this->assertEquals('q', $fields->FieldByName('q')->getName()); |
39
|
|
|
|
40
|
|
|
// check for the submit button |
41
|
|
|
$this->assertEquals('action_submit', $actions->FieldByName('action_submit')->getName()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public function testButtonOverride() { |
46
|
|
|
$searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
47
|
|
|
$buttonText = 'Search Me!'; |
48
|
|
|
$form = $searchPage->SearchPageForm('testsearchpage',$buttonText); |
49
|
|
|
$actions = $form->Actions(); |
50
|
|
|
$this->assertEquals($buttonText, $actions->FieldByName('action_submit')->Title()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testInvalidIdentifier() { |
55
|
|
|
$searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
56
|
|
|
|
57
|
|
|
//FindElasticaPageExtension is attached to SiteTree so we can search with any page. Here it |
58
|
|
|
//convenient to use the target pgae in order to test for comparison |
59
|
|
|
$found = $searchPage->getSearchPage('notasearchpageidentifier'); |
60
|
|
|
|
61
|
|
|
$this->assertEquals(null, $found); |
62
|
|
|
$uri = $searchPage->SearchPageURI('notasearchpageidentifier'); |
63
|
|
|
|
64
|
|
|
$this->assertEquals('', $uri); |
65
|
|
|
|
66
|
|
|
$this->assertEquals(null, $searchPage->SearchPageForm('notasearchpageidentifier')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testNullIdentifier() { |
71
|
|
|
$searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
72
|
|
|
|
73
|
|
|
//FindElasticaPageExtension is attached to SiteTree so we can search with any page. Here it |
74
|
|
|
//convenient to use the target pgae in order to test for comparison |
75
|
|
|
$found = $searchPage->getSearchPage(null); |
76
|
|
|
$this->assertEquals(null, $found); |
77
|
|
|
$uri = $searchPage->SearchPageURI(null); |
78
|
|
|
$this->assertEquals('', $uri); |
79
|
|
|
$this->assertEquals(null, $searchPage->SearchPageForm(null)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
public function testDuplicateIdentifier() { |
84
|
|
|
$searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
85
|
|
|
|
86
|
|
|
$esp = new ElasticSearchPage(); |
87
|
|
|
// ensure default identifier |
88
|
|
|
$esp->Identifier = $searchPage->Identifier; |
89
|
|
|
$esp->Title='This should not be saved'; |
90
|
|
|
try { |
91
|
|
|
$esp->write(); |
92
|
|
|
$this->assertFalse(true, 'Duplicate identifier was incorrectly saved'); |
93
|
|
|
} catch (Exception $e) { |
94
|
|
|
$this->assertTrue(true,'The page could not be saved as expected, due to duplicate '. |
95
|
|
|
'identifier'); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|