Completed
Push — dev2 ( 5ba5d5...dd5bec )
by Gordon
42:23 queued 39:29
created

testValidIdentifier()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1
Metric Value
dl 0
loc 30
ccs 17
cts 17
cp 1
rs 8.8571
cc 1
eloc 16
nc 1
nop 0
crap 1
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 1
	public function testValidIdentifier() {
14 1
		$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 1
		$found = $searchPage->getSearchPage('testsearchpage');
19
20 1
		$this->assertEquals($searchPage->ID, $found->ID);
21 1
		$this->assertEquals($searchPage->ClassName, $found->ClassName);
22 1
		$this->assertEquals($searchPage->Title, $found->Title);
23 1
		$this->assertEquals('testsearchpage', $found->Identifier);
24
25
		// don't check the server name as this will differ, just check the path is /search/
26 1
		$uri = $searchPage->SearchPageURI('testsearchpage');
27 1
		$splits = explode('/', $uri);
28 1
		$this->assertEquals($splits[3],'search');
29
30
		// check the form
31 1
		$form = $searchPage->SearchPageForm('testsearchpage');
32 1
		$this->assertInstanceOf('ElasticSearchForm',$form);
33
34 1
		$fields = $form->Fields();
35 1
		$actions = $form->Actions();
36
37
		// check for the query text box field
38 1
		$this->assertEquals('q', $fields->FieldByName('q')->getName());
39
40
		// check for the submit button
41 1
		$this->assertEquals('action_submit', $actions->FieldByName('action_submit')->getName());
42 1
	}
43
44
45 1
	public function testButtonOverride() {
46 1
		$searchPage = $this->objFromFixture('ElasticSearchPage', 'search');
47 1
		$buttonText = 'Search Me!';
48 1
		$form = $searchPage->SearchPageForm('testsearchpage',$buttonText);
49 1
		$actions = $form->Actions();
50 1
		$this->assertEquals($buttonText, $actions->FieldByName('action_submit')->Title());
51 1
	}
52
53
54 1
	public function testInvalidIdentifier() {
55 1
		$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 1
		$found = $searchPage->getSearchPage('notasearchpageidentifier');
60
61 1
		$this->assertEquals(null, $found);
62 1
		$uri = $searchPage->SearchPageURI('notasearchpageidentifier');
63
64 1
		$this->assertEquals('', $uri);
65
66 1
		$this->assertEquals(null, $searchPage->SearchPageForm('notasearchpageidentifier'));
67 1
	}
68
69
70 1
	public function testNullIdentifier() {
71 1
		$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 1
		$found = $searchPage->getSearchPage(null);
76 1
		$this->assertEquals(null, $found);
77 1
		$uri = $searchPage->SearchPageURI(null);
78 1
		$this->assertEquals('', $uri);
79 1
		$this->assertEquals(null, $searchPage->SearchPageForm(null));
80 1
	}
81
82
83 1
	public function testDuplicateIdentifier() {
84 1
		$searchPage = $this->objFromFixture('ElasticSearchPage', 'search');
85
86 1
		$esp = new ElasticSearchPage();
87
		// ensure default identifier
88 1
		$esp->Identifier = $searchPage->Identifier;
89 1
		$esp->Title='This should not be saved';
90
		try {
91 1
			$esp->write();
92
			$this->assertFalse(true, 'Duplicate identifier was incorrectly saved');
93 1
		} catch (Exception $e) {
94 1
			$this->assertTrue(true,'The page could not be saved as expected, due to duplicate '.
95 1
								'identifier');
96
		}
97 1
	}
98
99
}
100