diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-10-28 13:58:16 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2019-12-04 13:06:52 +0000 |
| commit | 96ab29c9873ee3d0f603068c6bc0c2d4056a3081 (patch) | |
| tree | 4890b03a55293187d5e28569472e2990a7ca6950 /addons/web/tests | |
| parent | 1ae66862d5570ebdb97ba0301ff591c27b969254 (diff) | |
[IMP] web: template inheritance respects XPATH specs
At the conception of this feature it has been intentionally thought that
the behavior for static templates should resemble
what is done for ir.ui.view
While keeping the general previous behavior (and this is important)
A little bit of context for ir.ui.view
They are defined as XML's, but end up as python objects
Their meta-data (id, name, inheritance specs...) are thus
present in their XML definition, but end up as part of python objects members
Hence, the final, business, usable arch is free of those meta-data
and is left only with business-relevant dom nodes
The static inheritance feature was backed with those ideas
but inherently encountered the issue that, for them,
the meta-data also end up in the business dom, since
they are at no point considered as plain objects.
Decision has been made, back then, to exclude the root node
that holds the metadata, to be at all targeted by any XPATH
This decision is now challenged as the specs of XPATH should be respected
This commit consequently introduces the root node as any other
It can be replaced, and will be targeted by
`expr="."` or `expr="//NODE_TAG"`
The few attributes that are necessary to define them are kept across
inheritance cycles though.
Diffstat (limited to 'addons/web/tests')
| -rw-r--r-- | addons/web/tests/test_serving_base.py | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/addons/web/tests/test_serving_base.py b/addons/web/tests/test_serving_base.py index 31be8bfa89e..87c01d748dc 100644 --- a/addons/web/tests/test_serving_base.py +++ b/addons/web/tests/test_serving_base.py @@ -397,7 +397,7 @@ class TestStaticInheritance(BaseCase): <div t-name="template_%(t_number)s_mod_%(m_number)s" t-inherit="template_%(t_inherit)s_mod_%(m_number)s" t-inherit-mode="primary"> - <xpath expr="//div[1]" position="before"> + <xpath expr="/div/div[1]" position="before"> <div>Sick XPath</div> </xpath> </div> @@ -408,7 +408,7 @@ class TestStaticInheritance(BaseCase): <div t-name="template_%(t_number)s_mod_%(m_number)s" t-inherit="mod_%(m_module_inherit)s.template_%(t_module_inherit)s_mod_%(m_module_inherit)s" t-inherit-mode="primary"> - <xpath expr="//div[1]" position="inside"> + <xpath expr="/div/div[1]" position="inside"> <div>Mental XPath</div> </xpath> </div> @@ -476,9 +476,9 @@ class TestStaticInheritance(BaseCase): contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True) expected = b""" <templates> - <form overriden-attr="overriden"> + <div overriden-attr="overriden" t-name="template_1_1"> <!-- Modified by template_1_2 from module_1 -->And I grew strong - </form> + </div> </templates> """ @@ -510,11 +510,12 @@ class TestStaticInheritance(BaseCase): contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True) expected = b""" <templates> - <form> - <!-- Modified by template_1_2 from module_1 -->And I grew strong + <div t-name="template_1_1"> + <!-- Modified by template_1_2 from module_1 --> + And I grew strong <p>And I learned how to get along</p> And so you're back - </form> + </div> </templates> """ @@ -550,11 +551,11 @@ class TestStaticInheritance(BaseCase): contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True) expected = b""" <templates> - <form> + <div t-name="template_1_1"> <!-- Modified by template_1_2 from module_1 --> And I grew strong <p>And I learned how to get along</p> - </form> + </div> And so you're back </templates> """ @@ -563,7 +564,7 @@ class TestStaticInheritance(BaseCase): def test_replace_root_node_tag(self): """ - Root node is not targeted by //NODE_TAG in xpath + Root node IS targeted by //NODE_TAG in xpath """ self.modules = [ ('module_1_file_1', None, 'module_1'), @@ -589,11 +590,10 @@ class TestStaticInheritance(BaseCase): contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=True) expected = b""" <templates> - <form t-name="template_1_1" random-attr="gloria"> - <div>At first I was afraid</div> + <div t-name="template_1_1"> <!-- Modified by template_1_2 from module_1 --> - <div>Form replacer</div> - </form> + Form replacer + </div> </templates> """ @@ -601,7 +601,7 @@ class TestStaticInheritance(BaseCase): def test_replace_root_node_tag_in_primary(self): """ - Root node is not targeted by //NODE_TAG in xpath + Root node IS targeted by //NODE_TAG in xpath """ self.maxDiff = None self.modules = [ @@ -630,10 +630,9 @@ class TestStaticInheritance(BaseCase): <div>At first I was afraid</div> <form>Inner Form</form> </form> - <form t-name="template_1_2" random-attr="gloria" t-inherit="template_1_1"> - <div>At first I was afraid</div> - <div>Form replacer</div> - </form> + <div t-name="template_1_2" t-inherit="template_1_1"> + Form replacer + </div> </templates> """ @@ -671,10 +670,10 @@ class TestStaticInheritance(BaseCase): <form t-name="template_1_1" random-attr="gloria"> <div>At first I was afraid</div> </form> - <form overriden-attr="overriden" t-name="template_1_2" t-inherit="template_1_1"> + <div overriden-attr="overriden" t-name="template_1_2" t-inherit="template_1_1"> And I grew strong <p>And I learned how to get along</p> - </form> + </div> </templates> """ @@ -708,11 +707,11 @@ class TestStaticInheritance(BaseCase): contents = HomeStaticTemplateHelpers.get_qweb_templates(addons=self._get_module_names(), debug=False) expected = b""" <templates> - <form> + <div t-name="template_1_1"> And I grew strong <p>And I learned how to get along</p> And so you're back - </form> + </div> </templates> """ |
