11describe ( 'Test in frontend that the contact site router' , ( ) => {
2+ afterEach ( ( ) => cy . db_updateExtensionParameter ( 'sef_ids' , '1' , 'com_contact' ) ) ;
3+
24 it ( 'can process contact without a menu item' , ( ) => {
35 cy . db_createContact ( { name : 'Test Contact' , alias : 'test-contact-router' } ) . then ( ( contact ) => {
6+ const url = '/index.php/component/contact/contact/test-contact-router' ;
47 cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } ` , followRedirect : false } ) . then ( ( response ) => {
58 expect ( response . status ) . to . eq ( 301 ) ;
6- expect ( response . redirectedToUrl ) . to . match ( / \/ i n d e x \. p h p \/ c o m p o n e n t \/ c o n t a c t \/ c o n t a c t \/ t e s t - c o n t a c t - r o u t e r $ / ) ;
9+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
10+ } ) ;
11+ cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } -${ contact . alias } ` , followRedirect : false } ) . then ( ( response ) => {
12+ expect ( response . status ) . to . eq ( 301 ) ;
13+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
714 } ) ;
815
9- cy . visit ( '/index.php/component/contact/contact/test-contact-router' ) ;
10- cy . url ( ) . should ( 'match' , / \/ i n d e x \. p h p \/ c o m p o n e n t \/ c o n t a c t \/ c o n t a c t \/ t e s t - c o n t a c t - r o u t e r $ / ) ;
16+ cy . visit ( url ) ;
17+ cy . url ( ) . should ( 'match' , new RegExp ( ` ${ url } $` ) ) ;
1118 cy . title ( ) . should ( 'equal' , 'Test Contact' ) ;
1219 cy . get ( 'main h1' ) . contains ( 'Home' ) ;
1320 cy . get ( 'main h2' ) . contains ( 'Test Contact' ) ;
@@ -20,20 +27,33 @@ describe('Test in frontend that the contact site router', () => {
2027 } ) ;
2128
2229 it ( 'can process contact with a single contact menu item' , ( ) => {
30+ const url = '/index.php/test-menu-contact-router' ;
2331 cy . db_createContact ( { name : 'Test Contact' , alias : 'test-contact-router' } ) . then ( ( contact ) => {
2432 cy . db_createMenuItem ( {
2533 title : 'Test Menu Single Contact' ,
2634 alias : 'test-menu-contact-router' ,
2735 path : 'test-menu-contact-router' ,
2836 link : `index.php?option=com_contact&view=contact&id=${ contact . id } ` ,
2937 } ) ;
38+ cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } ` , followRedirect : false } ) . then ( ( response ) => {
39+ expect ( response . status ) . to . eq ( 301 ) ;
40+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
41+ } ) ;
42+ cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } -${ contact . alias } ` , followRedirect : false } ) . then ( ( response ) => {
43+ expect ( response . status ) . to . eq ( 301 ) ;
44+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
45+ } ) ;
3046 cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } &catid=${ contact . catid } ` , followRedirect : false } ) . then ( ( response ) => {
3147 expect ( response . status ) . to . eq ( 301 ) ;
32- expect ( response . redirectedToUrl ) . to . match ( / \/ i n d e x \. p h p \/ t e s t - m e n u - c o n t a c t - r o u t e r $ / ) ;
48+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
49+ } ) ;
50+ cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } -${ contact . alias } &catid=${ contact . catid } ` , followRedirect : false } ) . then ( ( response ) => {
51+ expect ( response . status ) . to . eq ( 301 ) ;
52+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
3353 } ) ;
3454
35- cy . visit ( '/index.php/test-menu-contact-router' ) ;
36- cy . url ( ) . should ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c o n t a c t - r o u t e r $ / ) ;
55+ cy . visit ( url ) ;
56+ cy . url ( ) . should ( 'match' , new RegExp ( ` ${ url } $` ) ) ;
3757 cy . title ( ) . should ( 'equal' , 'Test Menu Single Contact' ) ;
3858 cy . get ( 'main h1' ) . contains ( 'Test Contact' ) ;
3959 cy . get ( 'main h2' ) . contains ( 'Contact' ) ;
@@ -44,6 +64,7 @@ describe('Test in frontend that the contact site router', () => {
4464 } ) ;
4565
4666 it ( 'can process contact with a category list menu item' , ( ) => {
67+ const url = '/index.php/test-menu-category-router/test-contact-router' ;
4768 cy . db_createContact ( { name : 'Test Contact' , alias : 'test-contact-router' } ) . then ( ( contact ) => {
4869 cy . db_createMenuItem ( {
4970 title : 'Test Menu Contact Category' ,
@@ -53,11 +74,15 @@ describe('Test in frontend that the contact site router', () => {
5374 } ) ;
5475 cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } &catid=${ contact . catid } ` , followRedirect : false } ) . then ( ( response ) => {
5576 expect ( response . status ) . to . eq ( 301 ) ;
56- expect ( response . redirectedToUrl ) . to . match ( / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r y - r o u t e r \/ t e s t - c o n t a c t - r o u t e r $ / ) ;
77+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
78+ } ) ;
79+ cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } -${ contact . alias } &catid=${ contact . catid } ` , followRedirect : false } ) . then ( ( response ) => {
80+ expect ( response . status ) . to . eq ( 301 ) ;
81+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
5782 } ) ;
5883
59- cy . visit ( '/index.php/test-menu-category-router' ) ;
60- cy . url ( ) . should ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r y - r o u t e r $ / ) ;
84+ cy . visit ( url . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ) ;
85+ cy . url ( ) . should ( 'match' , new RegExp ( ` ${ url . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) } $` ) ) ;
6186 cy . title ( ) . should ( 'equal' , 'Test Menu Contact Category' ) ;
6287 cy . get ( 'main h1' ) . contains ( 'Uncategorised' ) ;
6388 cy . get ( 'nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs' ) . children ( ) . as ( 'breadcrumb' ) ;
@@ -66,10 +91,10 @@ describe('Test in frontend that the contact site router', () => {
6691 cy . get ( 'main div.com-contact-category a' )
6792 . contains ( 'Test Contact' )
6893 . should ( 'have.attr' , 'href' )
69- . and ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r y - r o u t e r \/ t e s t - c o n t a c t - r o u t e r $ / ) ;
94+ . and ( 'match' , new RegExp ( ` ${ url } $` ) ) ;
7095
71- cy . visit ( '/index.php/test-menu-category-router/test-contact-router' ) ;
72- cy . url ( ) . should ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r y - r o u t e r \/ t e s t - c o n t a c t - r o u t e r $ / ) ;
96+ cy . visit ( url ) ;
97+ cy . url ( ) . should ( 'match' , new RegExp ( ` ${ url } $` ) ) ;
7398 cy . title ( ) . should ( 'equal' , 'Test Contact' ) ;
7499 cy . get ( 'main h1' ) . contains ( 'Test Contact' ) ;
75100 cy . get ( 'main h2' ) . contains ( 'Contact' ) ;
@@ -81,6 +106,7 @@ describe('Test in frontend that the contact site router', () => {
81106 } ) ;
82107
83108 it ( 'can process contact with a categories list menu item' , ( ) => {
109+ const url = '/index.php/test-menu-categories-router/uncategorised/test-contact-router' ;
84110 cy . db_createContact ( { name : 'Test Contact' , alias : 'test-contact-router' } ) . then ( ( contact ) => {
85111 cy . db_createMenuItem ( {
86112 title : 'Test Menu Contact Categories' ,
@@ -90,22 +116,22 @@ describe('Test in frontend that the contact site router', () => {
90116 } ) ;
91117 cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } &catid=${ contact . catid } ` , followRedirect : false } ) . then ( ( response ) => {
92118 expect ( response . status ) . to . eq ( 301 ) ;
93- expect ( response . redirectedToUrl ) . to . match ( / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r i e s - r o u t e r \/ u n c a t e g o r i s e d \/ t e s t - c o n t a c t - r o u t e r $ / ) ;
119+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( ` ${ url } $` ) ) ;
94120 } ) ;
95121
96- cy . visit ( '/index.php/test-menu-categories-router' ) ;
97- cy . url ( ) . should ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r i e s - r o u t e r $ / ) ;
122+ cy . visit ( url . split ( '/' ) . slice ( 0 , - 2 ) . join ( '/' ) ) ;
123+ cy . url ( ) . should ( 'match' , new RegExp ( ` ${ url . split ( '/' ) . slice ( 0 , - 2 ) . join ( '/' ) } $` ) ) ;
98124 cy . title ( ) . should ( 'equal' , 'Test Menu Contact Categories' ) ;
99125 cy . get ( 'nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs' ) . children ( ) . as ( 'breadcrumb' ) ;
100126 cy . get ( '@breadcrumb' ) . should ( 'have.length' , 3 ) ;
101127 cy . get ( '@breadcrumb' ) . eq ( 2 ) . should ( 'contain' , 'Test Menu Contact Categories' ) ;
102128 cy . get ( 'main div.com-contact-categories h3 a' )
103129 . contains ( 'Uncategorised' )
104130 . should ( 'have.attr' , 'href' )
105- . and ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r i e s - r o u t e r \/ u n c a t e g o r i s e d $ / ) ;
131+ . and ( 'match' , new RegExp ( ` ${ url . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) } $` ) ) ;
106132
107- cy . visit ( '/index.php/test-menu-categories-router/uncategorised' ) ;
108- cy . url ( ) . should ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r i e s - r o u t e r \/ u n c a t e g o r i s e d $ / ) ;
133+ cy . visit ( url . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ) ;
134+ cy . url ( ) . should ( 'match' , new RegExp ( ` ${ url . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) } $` ) ) ;
109135 cy . title ( ) . should ( 'equal' , 'Test Menu Contact Categories' ) ;
110136 cy . get ( 'main h1' ) . contains ( 'Uncategorised' ) ;
111137 cy . get ( 'nav.mod-breadcrumbs__wrapper ol.mod-breadcrumbs' ) . children ( ) . as ( 'breadcrumb' ) ;
@@ -115,10 +141,10 @@ describe('Test in frontend that the contact site router', () => {
115141 cy . get ( 'main div.com-contact-category a' )
116142 . contains ( 'Test Contact' )
117143 . should ( 'have.attr' , 'href' )
118- . and ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r i e s - r o u t e r \/ u n c a t e g o r i s e d \/ t e s t - c o n t a c t - r o u t e r $ / ) ;
144+ . and ( 'match' , new RegExp ( ` ${ url } $` ) ) ;
119145
120- cy . visit ( '/index.php/test-menu-categories-router/uncategorised/test-contact-router' ) ;
121- cy . url ( ) . should ( 'match' , / \/ i n d e x \. p h p \/ t e s t - m e n u - c a t e g o r i e s - r o u t e r \/ u n c a t e g o r i s e d \/ t e s t - c o n t a c t - r o u t e r $ / ) ;
146+ cy . visit ( url ) ;
147+ cy . url ( ) . should ( 'match' , new RegExp ( ` ${ url } $` ) ) ;
122148 cy . title ( ) . should ( 'equal' , 'Test Contact' ) ;
123149 cy . get ( 'main h1' ) . contains ( 'Test Contact' ) ;
124150 cy . get ( 'main h2' ) . contains ( 'Contact' ) ;
@@ -129,4 +155,22 @@ describe('Test in frontend that the contact site router', () => {
129155 cy . get ( '@breadcrumb' ) . eq ( 4 ) . should ( 'contain' , 'Test Contact' ) ;
130156 } ) ;
131157 } ) ;
158+
159+ it ( 'can process contact with legacy routing' , ( ) => {
160+ cy . db_updateExtensionParameter ( 'sef_ids' , '0' , 'com_contact' ) ;
161+ cy . db_createContact ( { name : 'Test Contact' , alias : 'test-contact-router' } ) . then ( ( contact ) => {
162+ const url = `/index.php/component/contact/contact/${ contact . id } -test-contact-router` ;
163+ cy . request ( { url, followRedirect : false } ) . then ( ( response ) => {
164+ expect ( response . status ) . to . eq ( 200 ) ;
165+ } ) ;
166+ cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } ` , followRedirect : false } ) . then ( ( response ) => {
167+ expect ( response . status ) . to . eq ( 301 ) ;
168+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
169+ } ) ;
170+ cy . request ( { url : `/index.php?option=com_contact&view=contact&id=${ contact . id } -${ contact . alias } ` , followRedirect : false } ) . then ( ( response ) => {
171+ expect ( response . status ) . to . eq ( 301 ) ;
172+ expect ( response . redirectedToUrl ) . to . match ( new RegExp ( `${ url } $` ) ) ;
173+ } ) ;
174+ } ) ;
175+ } ) ;
132176} ) ;
0 commit comments