This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Test the functionality of the Searchable extension |
||
5 | * @package elastica |
||
6 | */ |
||
7 | class SearchableFieldTest extends ElasticsearchBaseTest { |
||
8 | public static $fixture_file = 'elastica/tests/ElasticaTest.yml'; |
||
9 | |||
10 | public function testCMSFields() { |
||
11 | $sf = new SearchableField(); |
||
12 | $sf->Name = 'TestField'; |
||
0 ignored issues
–
show
|
|||
13 | $sf->ClazzName = 'TestClazz'; |
||
0 ignored issues
–
show
The property
ClazzName does not exist on object<SearchableField> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
14 | $sf->write(); |
||
15 | |||
16 | $fields = $sf->getCMSFields(); |
||
17 | |||
18 | $tab = $this->checkTabExists($fields,'Main'); |
||
19 | |||
20 | //Check fields |
||
21 | $nf = $this->checkFieldExists($tab, 'Name'); |
||
22 | $this->assertTrue($nf->isDisabled()); |
||
23 | } |
||
24 | |||
25 | |||
26 | |||
27 | |||
28 | /* Zero weight is pointless as it means not part of the search */ |
||
29 | View Code Duplication | public function testZeroWeight() { |
|
30 | $searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
||
31 | $lastEdited = $searchPage->LastEdited; |
||
32 | |||
33 | $extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1, |
||
34 | 'Weight' => 0); |
||
35 | $esfs = $searchPage->ElasticaSearchableFields(); |
||
0 ignored issues
–
show
The method
ElasticaSearchableFields() does not exist on DataObject . Did you maybe mean searchableFields() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. ![]() |
|||
36 | foreach ($esfs as $sf) { |
||
37 | if ($sf->Name == 'Title' || $sf->Name == 'Description') { |
||
38 | $esfs->remove($sf); |
||
39 | $esfs->add($sf, $extraFields); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | try { |
||
44 | $searchPage->write(); |
||
45 | $this->fail('Searchable fail should have failed to write'); |
||
46 | } catch (ValidationException $e) { |
||
47 | $this->assertInstanceOf('ValidationException', $e); |
||
0 ignored issues
–
show
The method
assertInstanceOf() does not seem to exist on object<SearchableFieldTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
48 | $expected = 'The field SearchableTestPage.Title has a zero weight. ; The field '. |
||
49 | 'SiteTree.Title has a zero weight. ; The field Page.Title has a zero weight. '; |
||
50 | $this->assertEquals($expected, $e->getMessage()); |
||
51 | } |
||
52 | |||
53 | //Effectively assert that the search page has not been written by checking LastEdited |
||
54 | $pageFromDB = DataObject::get_by_id('ElasticSearchPage', $searchPage->ID); |
||
55 | $this->assertEquals($lastEdited, $pageFromDB->LastEdited); |
||
56 | } |
||
57 | |||
58 | |||
59 | /* Weights must be positive */ |
||
60 | View Code Duplication | public function testNegativeWeight() { |
|
61 | $searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
||
62 | $lastEdited = $searchPage->LastEdited; |
||
63 | |||
64 | $extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1, |
||
65 | 'Weight' => -1); |
||
66 | $esfs = $searchPage->ElasticaSearchableFields(); |
||
0 ignored issues
–
show
The method
ElasticaSearchableFields() does not exist on DataObject . Did you maybe mean searchableFields() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. ![]() |
|||
67 | foreach ($esfs as $sf) { |
||
68 | if ($sf->Name == 'Title' || $sf->Name == 'Description') { |
||
69 | $esfs->remove($sf); |
||
70 | $esfs->add($sf, $extraFields); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | try { |
||
75 | $searchPage->write(); |
||
76 | $this->fail('Searchable fail should have failed to write'); |
||
77 | } catch (ValidationException $e) { |
||
78 | $this->assertInstanceOf('ValidationException', $e); |
||
79 | $expected = 'The field SearchableTestPage.Title has a negative weight. ; The field '. |
||
80 | 'SiteTree.Title has a negative weight. ; The field Page.Title has a negative weight. '; |
||
81 | $this->assertEquals($expected, $e->getMessage()); |
||
82 | } |
||
83 | //Effectively assert that the search page has not been written by checking LastEdited |
||
84 | $pageFromDB = DataObject::get_by_id('ElasticSearchPage', $searchPage->ID); |
||
85 | $this->assertEquals($lastEdited, $pageFromDB->LastEdited); |
||
86 | } |
||
87 | |||
88 | |||
89 | public function testDefaultWeight() { |
||
90 | $searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
||
91 | //$searchPage->write(); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
84% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
92 | $sf = $searchPage->ElasticaSearchableFields()->first(); |
||
0 ignored issues
–
show
The method
ElasticaSearchableFields() does not exist on DataObject . Did you maybe mean searchableFields() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. ![]() |
|||
93 | $this->assertEquals(1, $sf->Weight); |
||
94 | $this->assertTrue($sf->ID > 0); |
||
95 | } |
||
96 | |||
97 | |||
98 | public function testPositiveWeight() { |
||
99 | $sf = new SearchableField(); |
||
100 | $sf->Name = 'TestField'; |
||
0 ignored issues
–
show
The property
Name does not exist on object<SearchableField> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
101 | $sf->Weight = 10; |
||
0 ignored issues
–
show
The property
Weight does not exist on object<SearchableField> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
102 | $sf->write(); |
||
103 | $this->assertEquals(10, $sf->Weight); |
||
0 ignored issues
–
show
The property
Weight does not exist on object<SearchableField> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
104 | $this->assertTrue($sf->ID > 0); |
||
105 | } |
||
106 | |||
107 | |||
108 | public function testHumanReadableSearchable() { |
||
109 | |||
110 | $searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
||
111 | |||
112 | //ensure valid |
||
113 | $extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1, |
||
0 ignored issues
–
show
$extraFields is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
114 | 'Weight' => 1); |
||
115 | $sf = $searchPage->ElasticaSearchableFields()->first(); |
||
0 ignored issues
–
show
The method
ElasticaSearchableFields() does not exist on DataObject . Did you maybe mean searchableFields() ?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. ![]() |
|||
116 | |||
117 | |||
118 | $sf->Name = 'TestField'; |
||
119 | $sf->Searchable = false; |
||
120 | $this->assertEquals('No', $sf->HumanReadableSearchable()); |
||
121 | $sf->Searchable = true; |
||
122 | $this->assertEquals('Yes', $sf->HumanReadableSearchable()); |
||
123 | } |
||
124 | |||
125 | |||
126 | // ---- searchable fields are created via a script, so test do not allow creation/deletion ---- |
||
127 | |||
128 | /* |
||
129 | Ensure CMS users cannot delete searchable fields |
||
130 | */ |
||
131 | public function testCanDelete() { |
||
132 | $sf = new SearchableField(); |
||
133 | $this->assertFalse($sf->canDelete()); |
||
134 | } |
||
135 | |||
136 | /* |
||
137 | Ensure CMS users cannot create searchable fields |
||
138 | */ |
||
139 | public function testCanCreate() { |
||
140 | $sf = new SearchableField(); |
||
141 | $this->assertFalse($sf->canCreate()); |
||
142 | } |
||
143 | |||
144 | |||
145 | } |
||
146 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.