Commit 79a0349
committed
Move declaration of replacements and selectors to new function
At present the declaration of all raw un-processed selectors and their
replacements is in either the class body (private vars) or the
constructor.
This has the effect of modifying the original selectors on the class
instance vars during class instantiation, and also prevents any subclass
of ExactNamedSelector or PartialNamedSelector from making changes to any
replacement that has been explicitly overridden in those classes
constructors.
For example, it is impossible for a child class of either of these to
further override the '%tagTextMatch%' replacement because those changes
would either be overridden in the constructor of its parent, or all
original selector replacements would not be applied.
```
class MyPartialNamedSelector extends PartialNamedSelector
{
public function __construct()
{
// Note: Calling the constructor here (before registerReplacement)
// will mean that the call to registerReplacement will update the
// replacement, but only for any new selector defined after the
// replacement is defined.
// It will not have any effect upon any selector or replacement
// already registered.
parent::__construct();
$this->registerReplacement('%tagTextMatch%', 'contains(text(), %locator%)');
// Note: Calling the constructor here (after registerReplacement) will
// cause the above tagTextMatch replacement to be overwritten by the
// override defined in the constructor of PartialNamedSelector.
parent::__construct();
}
}
```
Furthermore the original values of both the selectors and replacements
have been mutated in the constructor so it is not possible for any child
class to simply re-apply the original translations.
The only solution to this problem is to extend the NamedSelector base
class and manually copy the standard replacements from
PartialNamedSelector or ExactNamedSelector (as appropriate) into your
new child class, but this approach is not sustainable.
This patch modifies the Selector classes to:
* moves the storage and fetching of the original, unmodified and
untranslated selectors and replacements to a function. This
effectively makes them immutable; and
* allows the child classes to override or define their own selectors
and replacements by simply overriding the parent class function and
updating or adding the required array values.
This change allows the replacements (or selectors) to be updated as in
the following example:
```
class MyPartialNamedSelector extends PartialNamedSelector
{
protected function getRawReplacements()
{
return array_merge(parent::getRawReplacements(), [
'%tagTextMatch%' => 'contains(text(), %locator%)',
]);
}
protected function getRawSelectors()
{
return array_merge(parent::getRawSelectors(), [
'link' => './/a[./@href][%tagTextMatch%]',
]);
}
}
```
Note: For any usage where the child class was directly extending the
`NamedSelector` class and defining its custom selectors and replacements
in the constructor, these will need to be updated to define the relevant
`getRawSelectors()` and/or `getRawReplacements()` classes as above.
This change should be considered a possibly breaking change in this
situation and therefore would demand a new major release (1.10.0
presumably).
Whilst this is a breaking change, it will have provide a more
sustainable approach in future for more advanced uses of Mink.1 parent f7032c3 commit 79a0349
File tree
4 files changed
+110
-80
lines changed- src/Selector
4 files changed
+110
-80
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
1 | 9 | | |
2 | 10 | | |
3 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
53 | 91 | | |
54 | 92 | | |
55 | 93 | | |
56 | 94 | | |
57 | | - | |
| 95 | + | |
58 | 96 | | |
59 | 97 | | |
60 | 98 | | |
| |||
66 | 104 | | |
67 | 105 | | |
68 | 106 | | |
69 | | - | |
| 107 | + | |
70 | 108 | | |
71 | 109 | | |
72 | 110 | | |
73 | 111 | | |
74 | 112 | | |
75 | 113 | | |
76 | 114 | | |
77 | | - | |
| 115 | + | |
78 | 116 | | |
79 | 117 | | |
80 | 118 | | |
| |||
88 | 126 | | |
89 | 127 | | |
90 | 128 | | |
91 | | - | |
| 129 | + | |
92 | 130 | | |
93 | 131 | | |
94 | 132 | | |
| |||
105 | 143 | | |
106 | 144 | | |
107 | 145 | | |
108 | | - | |
| 146 | + | |
109 | 147 | | |
110 | 148 | | |
111 | 149 | | |
112 | 150 | | |
113 | | - | |
| 151 | + | |
114 | 152 | | |
115 | 153 | | |
116 | 154 | | |
117 | 155 | | |
118 | 156 | | |
119 | 157 | | |
120 | | - | |
| 158 | + | |
121 | 159 | | |
122 | 160 | | |
123 | 161 | | |
124 | 162 | | |
125 | 163 | | |
126 | 164 | | |
127 | | - | |
| 165 | + | |
128 | 166 | | |
129 | 167 | | |
130 | 168 | | |
131 | 169 | | |
132 | 170 | | |
133 | 171 | | |
134 | | - | |
| 172 | + | |
135 | 173 | | |
136 | 174 | | |
137 | 175 | | |
138 | 176 | | |
139 | 177 | | |
140 | 178 | | |
141 | | - | |
| 179 | + | |
142 | 180 | | |
143 | 181 | | |
144 | 182 | | |
145 | 183 | | |
146 | | - | |
| 184 | + | |
147 | 185 | | |
148 | 186 | | |
149 | 187 | | |
150 | 188 | | |
151 | | - | |
| 189 | + | |
152 | 190 | | |
153 | 191 | | |
154 | 192 | | |
155 | | - | |
| 193 | + | |
156 | 194 | | |
157 | 195 | | |
158 | | - | |
| 196 | + | |
159 | 197 | | |
160 | 198 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
| 199 | + | |
178 | 200 | | |
179 | 201 | | |
180 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
0 commit comments