diff --git a/classes/class-archive-mapping.php b/classes/class-archive-mapping.php index 934cd52a..999f1b9a 100644 --- a/classes/class-archive-mapping.php +++ b/classes/class-archive-mapping.php @@ -238,11 +238,13 @@ public function converting_load_more_and_infinite_paginate_next_page_to_friendly * @return array */ public function converting_paginate_links_to_friendly_url( $arr, $args, $vp_options ) { + $permalink_structure = get_option( 'permalink_structure' ); // Determine if a page is an archive. if ( self::is_archive( $vp_options ) && isset( $arr ) && - ! empty( $arr ) + ! empty( $arr ) && + ! empty( $permalink_structure ) ) { if ( $arr['url'] ) { // Parsing the content of links. @@ -1264,24 +1266,28 @@ private function get_relative_archive_link() { * @return string */ private function converting_paginate_link_to_friendly_url( $link, $num_page = null ) { - // Parsing the content of links. - preg_match( '/vp_page=(\d+)/', $link, $match_vp_page ); - preg_match( '/page\/(\d+)/', $link, $match_page ); + $permalink_structure = get_option( 'permalink_structure' ); - if ( empty( $num_page ) && is_array( $match_vp_page ) && ! empty( $match_vp_page ) ) { - $num_page = $match_vp_page[1]; - } + if ( ! empty( $permalink_structure ) ) { + // Parsing the content of links. + preg_match( '/vp_page=(\d+)/', $link, $match_vp_page ); + preg_match( '/page\/(\d+)/', $link, $match_page ); - if ( ! empty( $num_page ) && is_array( $match_page ) && ! empty( $match_page ) ) { - $link = str_replace( $match_page[0], 'page/' . $num_page, $link ); - } + if ( empty( $num_page ) && is_array( $match_vp_page ) && ! empty( $match_vp_page ) ) { + $num_page = $match_vp_page[1]; + } - if ( ! empty( $num_page ) && empty( $match_page ) ) { - $link = str_replace( '/?', '/page/' . $num_page . '/?', $link ); - } + if ( ! empty( $num_page ) && is_array( $match_page ) && ! empty( $match_page ) ) { + $link = str_replace( $match_page[0], 'page/' . $num_page, $link ); + } + + if ( ! empty( $num_page ) && empty( $match_page ) ) { + $link = str_replace( '/?', '/page/' . $num_page . '/?', $link ); + } - if ( strpos( $link, 'vp_page' ) !== false ) { - $link = remove_query_arg( 'vp_page', $link ); + if ( strpos( $link, 'vp_page' ) !== false ) { + $link = remove_query_arg( 'vp_page', $link ); + } } return $link; @@ -1298,9 +1304,10 @@ private function converting_paginate_link_to_friendly_url( $link, $num_page = nu */ private function convert_category_to_friendly_url( $category_url ) { preg_match( '/vp_filter=([^&]*)/', $category_url, $match_filter ); - $base_page = $this->get_relative_archive_link(); + $base_page = $this->get_relative_archive_link(); + $permalink_structure = get_option( 'permalink_structure' ); - if ( is_array( $match_filter ) && ! empty( $match_filter ) ) { + if ( is_array( $match_filter ) && ! empty( $match_filter ) && ! empty( $permalink_structure ) ) { // We extract the contents of the filter and form a new link. $taxonomies = explode( ':', rawurldecode( $match_filter[1] ) ); if ( is_array( $taxonomies ) && 'portfolio_category' === $taxonomies[0] ) { diff --git a/package-lock.json b/package-lock.json index 9a2e97b4..e7b1eca5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3269,7 +3269,6 @@ "version": "0.3.6", "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz", "integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==", - "dev": true, "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25" @@ -4210,7 +4209,6 @@ "version": "9.6.0", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.0.tgz", "integrity": "sha512-gi6WQJ7cHRgZxtkQEoyHMppPjq9Kxo5Tjn2prSKDSmZrCz8TZ3jSRCeTJm+WoM+oB0WG37bRqLzaaU3q7JypGg==", - "dev": true, "dependencies": { "@types/estree": "*", "@types/json-schema": "*" @@ -4220,7 +4218,6 @@ "version": "3.7.7", "resolved": "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.7.tgz", "integrity": "sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==", - "dev": true, "dependencies": { "@types/eslint": "*", "@types/estree": "*" @@ -4229,8 +4226,7 @@ "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", - "dev": true + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==" }, "node_modules/@types/express": { "version": "4.17.21", @@ -4373,7 +4369,6 @@ "version": "20.14.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.12.tgz", "integrity": "sha512-r7wNXakLeSsGT0H1AU863vS2wa5wBOK4bWMjZz2wj+8nBx+m5PeIn0k8AloSLpRuiwdRQZwarZqHE4FNArPuJQ==", - "dev": true, "dependencies": { "undici-types": "~5.26.4" } @@ -4859,7 +4854,6 @@ "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.12.1.tgz", "integrity": "sha512-EKfMUOPRRUTy5UII4qJDGPpqfwjOmZ5jeGFwid9mnoqIFK+e0vqoi1qH56JpmZSzEL53jKnNzScdmftJyG5xWg==", - "dev": true, "dependencies": { "@webassemblyjs/helper-numbers": "1.11.6", "@webassemblyjs/helper-wasm-bytecode": "1.11.6" @@ -4868,26 +4862,22 @@ "node_modules/@webassemblyjs/floating-point-hex-parser": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/floating-point-hex-parser/-/floating-point-hex-parser-1.11.6.tgz", - "integrity": "sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw==", - "dev": true + "integrity": "sha512-ejAj9hfRJ2XMsNHk/v6Fu2dGS+i4UaXBXGemOfQ/JfQ6mdQg/WXtwleQRLLS4OvfDhv8rYnVwH27YJLMyYsxhw==" }, "node_modules/@webassemblyjs/helper-api-error": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-api-error/-/helper-api-error-1.11.6.tgz", - "integrity": "sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q==", - "dev": true + "integrity": "sha512-o0YkoP4pVu4rN8aTJgAyj9hC2Sv5UlkzCHhxqWj8butaLvnpdc2jOwh4ewE6CX0txSfLn/UYaV/pheS2Txg//Q==" }, "node_modules/@webassemblyjs/helper-buffer": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-buffer/-/helper-buffer-1.12.1.tgz", - "integrity": "sha512-nzJwQw99DNDKr9BVCOZcLuJJUlqkJh+kVzVl6Fmq/tI5ZtEyWT1KZMyOXltXLZJmDtvLCDgwsyrkohEtopTXCw==", - "dev": true + "integrity": "sha512-nzJwQw99DNDKr9BVCOZcLuJJUlqkJh+kVzVl6Fmq/tI5ZtEyWT1KZMyOXltXLZJmDtvLCDgwsyrkohEtopTXCw==" }, "node_modules/@webassemblyjs/helper-numbers": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-numbers/-/helper-numbers-1.11.6.tgz", "integrity": "sha512-vUIhZ8LZoIWHBohiEObxVm6hwP034jwmc9kuq5GdHZH0wiLVLIPcMCdpJzG4C11cHoQ25TFIQj9kaVADVX7N3g==", - "dev": true, "dependencies": { "@webassemblyjs/floating-point-hex-parser": "1.11.6", "@webassemblyjs/helper-api-error": "1.11.6", @@ -4897,14 +4887,12 @@ "node_modules/@webassemblyjs/helper-wasm-bytecode": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-bytecode/-/helper-wasm-bytecode-1.11.6.tgz", - "integrity": "sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA==", - "dev": true + "integrity": "sha512-sFFHKwcmBprO9e7Icf0+gddyWYDViL8bpPjJJl0WHxCdETktXdmtWLGVzoHbqUcY4Be1LkNfwTmXOJUFZYSJdA==" }, "node_modules/@webassemblyjs/helper-wasm-section": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/helper-wasm-section/-/helper-wasm-section-1.12.1.tgz", "integrity": "sha512-Jif4vfB6FJlUlSbgEMHUyk1j234GTNG9dBJ4XJdOySoj518Xj0oGsNi59cUQF4RRMS9ouBUxDDdyBVfPTypa5g==", - "dev": true, "dependencies": { "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-buffer": "1.12.1", @@ -4916,7 +4904,6 @@ "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/ieee754/-/ieee754-1.11.6.tgz", "integrity": "sha512-LM4p2csPNvbij6U1f19v6WR56QZ8JcHg3QIJTlSwzFcmx6WSORicYj6I63f9yU1kEUtrpG+kjkiIAkevHpDXrg==", - "dev": true, "dependencies": { "@xtuc/ieee754": "^1.2.0" } @@ -4925,7 +4912,6 @@ "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/leb128/-/leb128-1.11.6.tgz", "integrity": "sha512-m7a0FhE67DQXgouf1tbN5XQcdWoNgaAuoULHIfGFIEVKA6tu/edls6XnIlkmS6FrXAquJRPni3ZZKjw6FSPjPQ==", - "dev": true, "dependencies": { "@xtuc/long": "4.2.2" } @@ -4933,14 +4919,12 @@ "node_modules/@webassemblyjs/utf8": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/utf8/-/utf8-1.11.6.tgz", - "integrity": "sha512-vtXf2wTQ3+up9Zsg8sa2yWiQpzSsMyXj0qViVP6xKGCUT8p8YJ6HqI7l5eCnWx1T/FYdsv07HQs2wTFbbof/RA==", - "dev": true + "integrity": "sha512-vtXf2wTQ3+up9Zsg8sa2yWiQpzSsMyXj0qViVP6xKGCUT8p8YJ6HqI7l5eCnWx1T/FYdsv07HQs2wTFbbof/RA==" }, "node_modules/@webassemblyjs/wasm-edit": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-edit/-/wasm-edit-1.12.1.tgz", "integrity": "sha512-1DuwbVvADvS5mGnXbE+c9NfA8QRcZ6iKquqjjmR10k6o+zzsRVesil54DKexiowcFCPdr/Q0qaMgB01+SQ1u6g==", - "dev": true, "dependencies": { "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-buffer": "1.12.1", @@ -4956,7 +4940,6 @@ "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-gen/-/wasm-gen-1.12.1.tgz", "integrity": "sha512-TDq4Ojh9fcohAw6OIMXqiIcTq5KUXTGRkVxbSo1hQnSy6lAM5GSdfwWeSxpAo0YzgsgF182E/U0mDNhuA0tW7w==", - "dev": true, "dependencies": { "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-wasm-bytecode": "1.11.6", @@ -4969,7 +4952,6 @@ "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-opt/-/wasm-opt-1.12.1.tgz", "integrity": "sha512-Jg99j/2gG2iaz3hijw857AVYekZe2SAskcqlWIZXjji5WStnOpVoat3gQfT/Q5tb2djnCjBtMocY/Su1GfxPBg==", - "dev": true, "dependencies": { "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-buffer": "1.12.1", @@ -4981,7 +4963,6 @@ "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/wasm-parser/-/wasm-parser-1.12.1.tgz", "integrity": "sha512-xikIi7c2FHXysxXe3COrVUPSheuBtpcfhbpFj4gmu7KRLYOzANztwUU0IbsqvMqzuNK2+glRGWCEqZo1WCLyAQ==", - "dev": true, "dependencies": { "@webassemblyjs/ast": "1.12.1", "@webassemblyjs/helper-api-error": "1.11.6", @@ -4995,7 +4976,6 @@ "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/wast-printer/-/wast-printer-1.12.1.tgz", "integrity": "sha512-+X4WAlOisVWQMikjbcvY2e0rwPsKQ9F688lksZhBcPycBBuii3O7m8FACbDMWDojpAqvjIncrG8J0XHKyQfVeA==", - "dev": true, "dependencies": { "@webassemblyjs/ast": "1.12.1", "@xtuc/long": "4.2.2" @@ -5638,14 +5618,12 @@ "node_modules/@xtuc/ieee754": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", - "integrity": "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==", - "dev": true + "integrity": "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA==" }, "node_modules/@xtuc/long": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@xtuc/long/-/long-4.2.2.tgz", - "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==", - "dev": true + "integrity": "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==" }, "node_modules/abab": { "version": "2.0.6", @@ -5676,7 +5654,6 @@ "version": "8.12.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", - "dev": true, "bin": { "acorn": "bin/acorn" }, @@ -5698,7 +5675,6 @@ "version": "1.9.5", "resolved": "https://registry.npmjs.org/acorn-import-attributes/-/acorn-import-attributes-1.9.5.tgz", "integrity": "sha512-n02Vykv5uA3eHGM/Z2dQrcD56kL8TyDb2p1+0P83PClMnC/nc+anbQRhIOWnSq4Ke/KvDPrY3C9hDtC/A3eHnQ==", - "dev": true, "peerDependencies": { "acorn": "^8" } @@ -5762,7 +5738,6 @@ "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -5823,7 +5798,6 @@ "version": "3.5.2", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", - "dev": true, "peerDependencies": { "ajv": "^6.9.1" } @@ -6947,7 +6921,6 @@ "version": "4.23.2", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.2.tgz", "integrity": "sha512-qkqSyistMYdxAcw+CzbZwlBy8AGmS/eEWs+sEV5TnLRGDOL+C5M2EnH6tlZyg0YoAxGJAFKh61En9BR941GnHA==", - "dev": true, "funding": [ { "type": "opencollective", @@ -7020,8 +6993,7 @@ "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, "node_modules/builtin-modules": { "version": "3.3.0", @@ -7176,7 +7148,6 @@ "version": "1.0.30001643", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001643.tgz", "integrity": "sha512-ERgWGNleEilSrHM6iUz/zJNSQTP8Mr21wDWpdgvRwcTXGAq6jMtOUPP4dqFPTdKqZ2wKTdtB+uucZ3MRpAUSmg==", - "dev": true, "funding": [ { "type": "opencollective", @@ -7423,7 +7394,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.4.tgz", "integrity": "sha512-rNjApaLzuwaOTjCiT8lSDdGN1APCiqkChLMJxJPWLunPAt5fy8xgU9/jNOchV84wfIxrA0lRQB7oCT8jrn/wrQ==", - "dev": true, "engines": { "node": ">=6.0" } @@ -9550,8 +9520,7 @@ "node_modules/electron-to-chromium": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.1.tgz", - "integrity": "sha512-FKbOCOQ5QRB3VlIbl1LZQefWIYwszlBloaXcY2rbfpu9ioJnNh3TK03YtIDKDo3WKBi8u+YV4+Fn2CkEozgf4w==", - "dev": true + "integrity": "sha512-FKbOCOQ5QRB3VlIbl1LZQefWIYwszlBloaXcY2rbfpu9ioJnNh3TK03YtIDKDo3WKBi8u+YV4+Fn2CkEozgf4w==" }, "node_modules/emittery": { "version": "0.13.1", @@ -9623,7 +9592,6 @@ "version": "5.17.1", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz", "integrity": "sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==", - "dev": true, "dependencies": { "graceful-fs": "^4.2.4", "tapable": "^2.2.0" @@ -9815,8 +9783,7 @@ "node_modules/es-module-lexer": { "version": "1.5.4", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.5.4.tgz", - "integrity": "sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==", - "dev": true + "integrity": "sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==" }, "node_modules/es-object-atoms": { "version": "1.0.0", @@ -9874,7 +9841,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", - "dev": true, "engines": { "node": ">=6" } @@ -10512,7 +10478,6 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", - "dev": true, "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^4.1.1" @@ -10525,7 +10490,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", - "dev": true, "engines": { "node": ">=4.0" } @@ -10870,7 +10834,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", - "dev": true, "dependencies": { "estraverse": "^5.2.0" }, @@ -10882,7 +10845,6 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", - "dev": true, "engines": { "node": ">=4.0" } @@ -10920,7 +10882,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", - "dev": true, "engines": { "node": ">=0.8.x" } @@ -11262,8 +11223,7 @@ "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" }, "node_modules/fast-levenshtein": { "version": "2.0.6", @@ -12222,8 +12182,7 @@ "node_modules/glob-to-regexp": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", - "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", - "dev": true + "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==" }, "node_modules/glob-watcher": { "version": "6.0.0", @@ -12401,8 +12360,7 @@ "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" }, "node_modules/graphemer": { "version": "1.4.0", @@ -16007,6 +15965,12 @@ "integrity": "sha512-WZzeDOEtTOBK4Mdsar0IqEU5sMr3vSV2RqkAIzUEV2BHnUfKGyswWFPFwK5EeDo93K3FohSHbLAjj0s1Wzd+dg==", "dev": true }, + "node_modules/jquery": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.7.1.tgz", + "integrity": "sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==", + "peer": true + }, "node_modules/js-library-detector": { "version": "6.7.0", "resolved": "https://registry.npmjs.org/js-library-detector/-/js-library-detector-6.7.0.tgz", @@ -16131,8 +16095,7 @@ "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", @@ -16959,7 +16922,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/loader-runner/-/loader-runner-4.3.0.tgz", "integrity": "sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==", - "dev": true, "engines": { "node": ">=6.11.5" } @@ -17683,8 +17645,7 @@ "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", - "dev": true + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" }, "node_modules/merge2": { "version": "1.4.1", @@ -17737,7 +17698,6 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "dev": true, "engines": { "node": ">= 0.6" } @@ -17746,7 +17706,6 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dev": true, "dependencies": { "mime-db": "1.52.0" }, @@ -17996,8 +17955,7 @@ "node_modules/neo-async": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", - "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", - "dev": true + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" }, "node_modules/netmask": { "version": "2.0.2", @@ -18084,8 +18042,7 @@ "node_modules/node-releases": { "version": "2.0.18", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.18.tgz", - "integrity": "sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g==", - "dev": true + "integrity": "sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g==" }, "node_modules/nomnom": { "version": "1.8.1", @@ -20227,6 +20184,22 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "peer": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/prettier-linter-helpers": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", @@ -20449,7 +20422,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "dev": true, "engines": { "node": ">=6" } @@ -20665,7 +20637,6 @@ "version": "18.3.1", "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", - "dev": true, "dependencies": { "loose-envify": "^1.1.0" }, @@ -20689,6 +20660,19 @@ "react-dom": "^0.13.0 || ^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0" } }, + "node_modules/react-dom": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.2" + }, + "peerDependencies": { + "react": "^18.3.1" + } + }, "node_modules/react-is": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", @@ -21597,6 +21581,15 @@ "node": ">=v12.22.7" } }, + "node_modules/scheduler": { + "version": "0.23.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/schema-utils": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.2.0.tgz", @@ -23140,7 +23133,6 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", - "dev": true, "engines": { "node": ">=6" } @@ -23216,7 +23208,6 @@ "version": "5.31.3", "resolved": "https://registry.npmjs.org/terser/-/terser-5.31.3.tgz", "integrity": "sha512-pAfYn3NIZLyZpa83ZKigvj6Rn9c/vd5KfYGX7cN1mnzqgDcxWvrU5ZtAfIKhEXz9nRecw4z3LXkjaq96/qZqAA==", - "dev": true, "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", @@ -23234,7 +23225,6 @@ "version": "5.3.10", "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-5.3.10.tgz", "integrity": "sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w==", - "dev": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.20", "jest-worker": "^27.4.5", @@ -23268,7 +23258,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "engines": { "node": ">=8" } @@ -23277,7 +23266,6 @@ "version": "27.5.1", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-27.5.1.tgz", "integrity": "sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==", - "dev": true, "dependencies": { "@types/node": "*", "merge-stream": "^2.0.0", @@ -23291,7 +23279,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", - "dev": true, "dependencies": { "@types/json-schema": "^7.0.8", "ajv": "^6.12.5", @@ -23309,7 +23296,6 @@ "version": "8.1.1", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", - "dev": true, "dependencies": { "has-flag": "^4.0.0" }, @@ -23323,14 +23309,12 @@ "node_modules/terser/node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "node_modules/terser/node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -23339,7 +23323,6 @@ "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "dev": true, "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -23804,6 +23787,20 @@ "is-typedarray": "^1.0.0" } }, + "node_modules/typescript": { + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "dev": true, + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", @@ -23886,8 +23883,7 @@ "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" }, "node_modules/unicode-canonical-property-names-ecmascript": { "version": "2.0.0", @@ -23963,7 +23959,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.0.tgz", "integrity": "sha512-EdRAaAyk2cUE1wOf2DkEhzxqOQvFOoRJFNS6NeyJ01Gp2beMRpBAINjM2iDXE3KCuKhwnvHIQCJm6ThL2Z+HzQ==", - "dev": true, "funding": [ { "type": "opencollective", @@ -24011,7 +24006,6 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", - "dev": true, "dependencies": { "punycode": "^2.1.0" } @@ -24451,7 +24445,6 @@ "version": "2.4.1", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.1.tgz", "integrity": "sha512-8wrBCMtVhqcXP2Sup1ctSkga6uc2Bx0IIvKyT7yTFier5AXHooSI+QyQQAtTb7+E0IUCCKyTFmXqdqgum2XWGg==", - "dev": true, "dependencies": { "glob-to-regexp": "^0.4.1", "graceful-fs": "^4.1.2" @@ -24497,7 +24490,6 @@ "version": "5.93.0", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.93.0.tgz", "integrity": "sha512-Y0m5oEY1LRuwly578VqluorkXbvXKh7U3rLoQCEO04M97ScRr44afGVkI0FQFsXzysk5OgFAxjZAb9rsGQVihA==", - "dev": true, "dependencies": { "@types/eslint-scope": "^3.7.3", "@types/estree": "^1.0.5", @@ -24878,7 +24870,6 @@ "version": "3.2.3", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-3.2.3.tgz", "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", - "dev": true, "engines": { "node": ">=10.13.0" } @@ -24887,7 +24878,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", - "dev": true, "dependencies": { "@types/json-schema": "^7.0.8", "ajv": "^6.12.5", diff --git a/tests/e2e/specs/added-images-to-block.spec.js b/tests/e2e/specs/added-images-to-block.spec.js new file mode 100644 index 00000000..1882e5fa --- /dev/null +++ b/tests/e2e/specs/added-images-to-block.spec.js @@ -0,0 +1,778 @@ +/** + * WordPress dependencies + */ +import { expect, test } from '@wordpress/e2e-test-utils-playwright'; + +/** + * Test Images + */ +import imageFixtures from '../../fixtures/images.json'; +import { findAsyncSequential } from '../utils/find-async-sequential'; +import { getWordpressImages } from '../utils/get-wordpress-images'; + +test.describe('added images to block', () => { + test.beforeEach(async ({ requestUtils }) => { + const pluginName = process.env.CORE + ? 'visual-portfolio-pro' + : 'visual-portfolio-posts-amp-image-gallery'; + await requestUtils.activatePlugin(pluginName); + await requestUtils.deleteAllMedia(); + await requestUtils.deleteAllPages(); + }); + test.afterEach(async ({ requestUtils }) => { + await requestUtils.deleteAllMedia(); + await requestUtils.deleteAllPages(); + }); + + /** + * We create a gallery block and add pictures to it manually or automatically. + * + * @param {RequestUtils} requestUtils Playwright utilities for interacting with the WordPress REST API. + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + * @param {Admin} admin End to end test utilities for WordPress admin’s user interface. + * @param {Editor} editor End to end test utilities for the WordPress Block Editor. + * @param {boolean} programmatically Flag for setting manual or automatic adding of pictures to the block. + * @param {boolean} alternativeSetting Flag for setting alternative meta settings for test images. + * @return {{images: {format: string, video_url: string, url: string}[]}} + */ + async function generateGalleryBeforeEachTest( + requestUtils, + page, + admin, + editor, + programmatically = false, + alternativeSetting = false + ) { + await admin.visitAdminPage('edit.php'); + + await admin.createNewPost({ + title: 'Test Adding Images to a Block Programmatically', + postType: 'page', + showWelcomeGuide: false, + legacyCanvas: true, + }); + + const images = await getWordpressImages({ + requestUtils, + page, + admin, + editor, + alternativeSetting, + }); + + let attributes = { + setup_wizard: 'false', + content_source: 'images', + }; + + if (programmatically) { + attributes = { + ...attributes, + images, + }; + } + + await editor.insertBlock({ + name: 'visual-portfolio/block', + attributes, + }); + + return images; + } + + test('added images to a block manually', async ({ + page, + admin, + editor, + requestUtils, + }) => { + const images = await generateGalleryBeforeEachTest( + requestUtils, + page, + admin, + editor + ); + + await page + .locator( + 'button.components-button.vpf-component-gallery-control-item-add', + { + hasText: 'Add Images', + } + ) + .click(); + + await page + .locator('button#menu-item-browse', { + hasText: 'Media Library', + }) + .click(); + + const imageList = page.locator( + 'ul.attachments.ui-sortable.ui-sortable-disabled li.attachment[role="checkbox"]' + ); + + for (const image of await imageList.elementHandles()) { + if ( + typeof images.find( + async (x) => x.id === (await image.getAttribute('data-id')) + ).imgUrl !== 'undefined' + ) { + await image.click(); + } + } + + await page + .locator('button.button.media-button.media-button-select', { + hasText: 'Select', + }) + .click(); + + await page + .locator('.components-base-control__field', { + hasText: 'Items Per Page', + }) + .locator('input.components-text-control__input') + .fill('10'); + + await page.waitForTimeout(500); + + // Check images on backend editor. + for (const image of images) { + await expect( + page.frame('vpf-preview-1').locator('.wp-image-' + image.id) + ).toBeVisible(); + } + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + // Check images on frontend. + for (const image of images) { + await expect(page.locator('.wp-image-' + image.id)).toBeVisible(); + } + }); + + test('added images to a block programmatically', async ({ + page, + admin, + editor, + requestUtils, + }) => { + const images = await generateGalleryBeforeEachTest( + requestUtils, + page, + admin, + editor, + true + ); + + await page + .locator('.components-base-control__field', { + hasText: 'Items Per Page', + }) + .locator('input.components-text-control__input') + .fill('10'); + + await page.waitForTimeout(500); + + // Check images on backend editor. + for (const image of images) { + await expect( + page.frame('vpf-preview-1').locator('.wp-image-' + image.id) + ).toBeVisible(); + } + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + // Check images on frontend. + for (const image of images) { + await expect(page.locator('.wp-image-' + image.id)).toBeVisible(); + } + }); + + test('checking image settings', async ({ + page, + admin, + editor, + requestUtils, + }) => { + const images = await generateGalleryBeforeEachTest( + requestUtils, + page, + admin, + editor + ); + + await page + .locator( + 'button.components-button.vpf-component-gallery-control-item-add', + { + hasText: 'Add Images', + } + ) + .click(); + + await page + .locator('button#menu-item-browse', { + hasText: 'Media Library', + }) + .click(); + + const imageList = page.locator( + 'ul.attachments.ui-sortable.ui-sortable-disabled li.attachment[role="checkbox"]' + ); + + for (const image of await imageList.elementHandles()) { + if ( + typeof images.find( + async (x) => x.id === (await image.getAttribute('data-id')) + ).imgUrl !== 'undefined' + ) { + await image.click(); + + const imageID = await image.getAttribute('data-id'); + + const foundImage = await findAsyncSequential( + images, + async (x) => x.id === Number(imageID) + ); + + const foundFixture = await findAsyncSequential( + imageFixtures, + async (x) => x.description === foundImage.description + ); + + await page + .locator('#attachment-details-alt-text') + .fill(foundFixture.alt); + + await page + .locator('#attachment-details-caption') + .fill(foundFixture.caption); + + await page + .locator('#attachment-details-description') + .fill(foundFixture.description); + } + } + + await page + .locator('button.button.media-button.media-button-select', { + hasText: 'Select', + }) + .click(); + + await page + .locator('.components-base-control__field', { + hasText: 'Items Per Page', + }) + .locator('input.components-text-control__input') + .fill('10'); + + await page + .locator('button.components-button.components-panel__body-toggle', { + hasText: 'Skin', + }) + .click(); + + await page + .locator( + 'button.components-button.vpf-component-icon-selector-item', + { + hasText: 'Classic', + } + ) + .click(); + + await page + .locator('button.components-button.components-navigator-button', { + hasText: 'Caption', + }) + .click(); + + await page + .locator( + 'button.components-button.vpf-component-collapse-control-toggle', + { + hasText: 'Elements', + } + ) + .click(); + + await page.getByRole('checkbox', { name: 'Display Excerpt' }).check(); + + await page.waitForTimeout(500); + + // Check images on backend editor. + for (const image of images) { + const imageContainer = page + .frame('vpf-preview-1') + .locator('.wp-image-' + image.id); + await expect(imageContainer).toBeVisible(); + + await expect( + page + .frame('vpf-preview-1') + .locator('.vp-portfolio__item-meta-excerpt', { + hasText: image.description, + }) + ).toBeVisible(); + + const foundFixture = await findAsyncSequential( + imageFixtures, + async (x) => x.description === image.description + ); + + await expect( + page.frame('vpf-preview-1').getByAltText(foundFixture.alt) + ).toBeVisible(); + } + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + // Check images on frontend. + for (const image of images) { + await expect(page.locator('.wp-image-' + image.id)).toBeVisible(); + + const itemContainer = page + .locator('.vp-portfolio__item') + .filter({ has: page.locator('.wp-image-' + image.id) }); + + await expect(itemContainer).toBeVisible(); + + const descriptionText = itemContainer.locator( + '.vp-portfolio__item-meta-excerpt div' + ); + + await expect(descriptionText).toHaveText(image.description); + + const foundFixture = await findAsyncSequential( + imageFixtures, + async (x) => x.description === image.description + ); + + await expect(page.getByAltText(foundFixture.alt)).toBeVisible(); + } + }); + + test('checking alternative image settings', async ({ + page, + admin, + editor, + requestUtils, + }) => { + const currentPage = page.url(); + + await admin.createNewPost({ + title: 'Sample Test Page', + postType: 'page', + content: 'Test content', + showWelcomeGuide: false, + legacyCanvas: true, + }); + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + const postLink = page.url(); + + await page.goto(currentPage); + + const images = await generateGalleryBeforeEachTest( + requestUtils, + page, + admin, + editor + ); + + await page + .locator( + 'button.components-button.vpf-component-gallery-control-item-add', + { + hasText: 'Add Images', + } + ) + .click(); + + await page + .locator('button#menu-item-browse', { + hasText: 'Media Library', + }) + .click(); + + const imageList = page.locator( + 'ul.attachments.ui-sortable.ui-sortable-disabled li.attachment[role="checkbox"]' + ); + + for (const image of await imageList.elementHandles()) { + if ( + typeof images.find( + async (x) => x.id === (await image.getAttribute('data-id')) + ).imgUrl !== 'undefined' + ) { + await image.click(); + + const imageID = await image.getAttribute('data-id'); + + const foundImage = await findAsyncSequential( + images, + async (x) => x.id === Number(imageID) + ); + + const foundFixture = await findAsyncSequential( + imageFixtures, + async (x) => x.description === foundImage.description + ); + + await page + .locator('#attachment-details-alt-text') + .fill(foundFixture.alt); + + await page + .locator('#attachment-details-caption') + .fill(foundFixture.caption); + + await page + .locator('#attachment-details-description') + .fill(foundFixture.description); + } + } + + await page + .locator('button.button.media-button.media-button-select', { + hasText: 'Select', + }) + .click(); + + await page + .locator('.components-base-control__field', { + hasText: 'Items Per Page', + }) + .locator('input.components-text-control__input') + .fill('10'); + + await page + .locator('button.components-button.components-panel__body-toggle', { + hasText: 'Skin', + }) + .click(); + + await page + .locator( + 'button.components-button.vpf-component-icon-selector-item', + { + hasText: 'Classic', + } + ) + .click(); + + await page + .locator('button.components-button.components-navigator-button', { + hasText: 'Caption', + }) + .click(); + + await page + .locator( + 'button.components-button.vpf-component-collapse-control-toggle', + { + hasText: 'Elements', + } + ) + .click(); + + await page.getByRole('checkbox', { name: 'Display Excerpt' }).check(); + + const galleryControlItems = page.locator( + '.vpf-component-gallery-control-items .vpf-component-gallery-control-item' + ); + + for (const item of await galleryControlItems.elementHandles()) { + await item.click(); + + const itemDescription = await page + .locator('.components-base-control__field', { + hasText: 'Description', + }) + .locator('textarea.components-textarea-control__input') + .innerHTML(); + + const foundImage = await findAsyncSequential( + images, + async (x) => x.description === itemDescription + ); + + const foundFixture = await findAsyncSequential( + imageFixtures, + async (x) => x.description === itemDescription + ); + + const foundFixtureIndex = imageFixtures.indexOf(foundFixture); + + imageFixtures[foundFixtureIndex].id = foundImage.id; + + if (typeof foundFixture.imageSettings !== 'undefined') { + await page + .locator( + '.vpf-component-gallery-control-item-modal .components-base-control__field', + { + hasText: 'Title', + } + ) + .locator('input.components-text-control__input') + .fill(foundFixture.imageSettings.title); + + await page + .locator( + '.vpf-component-gallery-control-item-modal .components-base-control__field', + { + hasText: 'Description', + } + ) + .locator('textarea.components-textarea-control__input') + .fill(foundFixture.imageSettings.description); + + if (typeof foundFixture.imageSettings.format !== 'undefined') { + await page + .locator( + '.vpf-component-gallery-control-item-modal .components-base-control__field', + { + hasText: 'Format', + } + ) + .locator('.vpf-component-select') + .click(); + + await page + .locator('.vpf-component-select-option-label', { + hasText: foundFixture.imageSettings.format, + }) + .click(); + + if ( + foundFixture.imageSettings.format === 'standard' && + typeof foundFixture.imageSettings.url !== 'undefined' + ) { + foundFixture.imageSettings.url = + foundFixture.imageSettings.url === 'postLink' + ? postLink + : foundFixture.imageSettings.url; + + await page + .getByRole('textbox', { name: 'URL', exact: true }) + .fill(foundFixture.imageSettings.url); + } + + if ( + foundFixture.imageSettings.format === 'video' && + typeof foundFixture.imageSettings.videoUrl !== + 'undefined' + ) { + await page + .locator( + '.vpf-component-gallery-control-item-modal .components-base-control__field', + { + hasText: 'Video URL', + } + ) + .locator('input.components-text-control__input') + .fill(foundFixture.imageSettings.videoUrl); + } + } + } + + await page.getByLabel('Close', { exact: true }).click(); + } + + // Check image attributes on backend editor. + for (const image of imageFixtures) { + const imageContainer = page + .frame('vpf-preview-1') + .locator('.wp-image-' + image.id); + await expect(imageContainer).toBeVisible(); + + if (typeof image.imageSettings !== 'undefined') { + await expect( + page + .frame('vpf-preview-1') + .locator('.vp-portfolio__item-meta-excerpt', { + hasText: image.imageSettings.description, + }) + ).toBeVisible(); + + await expect( + page + .frame('vpf-preview-1') + .locator('.vp-portfolio__item-meta-title > a', { + hasText: image.imageSettings.title, + }) + ).toBeVisible(); + + if (typeof image.imageSettings.format !== 'undefined') { + const format = image.imageSettings.format; + if ( + format === 'standard' && + typeof image.imageSettings.url !== 'undefined' + ) { + await expect( + page + .frame('vpf-preview-1') + .locator('.vp-portfolio__item-meta-title > a', { + hasText: image.imageSettings.title, + }) + ).toHaveAttribute('href', image.imageSettings.url); + + await expect( + page + .frame('vpf-preview-1') + .getByRole('link', { name: image.alt }) + ).toHaveAttribute('href', image.imageSettings.url); + } + + if ( + format === 'video' && + typeof image.imageSettings.videoUrl !== 'undefined' + ) { + await expect( + page + .frame('vpf-preview-1') + .locator('.vp-portfolio__item-meta-title > a', { + hasText: image.imageSettings.title, + }) + ).toHaveAttribute('href', image.imageSettings.videoUrl); + + await expect( + page + .frame('vpf-preview-1') + .getByRole('link', { name: image.alt }) + ).toHaveAttribute('href', image.imageSettings.videoUrl); + } + } + } else { + await expect( + page + .frame('vpf-preview-1') + .locator('.vp-portfolio__item-meta-excerpt', { + hasText: image.description, + }) + ).toBeVisible(); + } + + await expect( + page.frame('vpf-preview-1').getByAltText(image.alt) + ).toBeVisible(); + } + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + // Check image attributes on frontend. + for (const image of imageFixtures) { + await expect(page.locator('.wp-image-' + image.id)).toBeVisible(); + + const itemContainer = page + .locator('.vp-portfolio__item') + .filter({ has: page.locator('.wp-image-' + image.id) }); + + await expect(itemContainer).toBeVisible(); + + if (typeof image.imageSettings !== 'undefined') { + await expect( + page.locator('.vp-portfolio__item-meta-excerpt', { + hasText: image.imageSettings.description, + }) + ).toBeVisible(); + + await expect( + page.locator('.vp-portfolio__item-meta-title > a', { + hasText: image.imageSettings.title, + }) + ).toBeVisible(); + + if (typeof image.imageSettings.format !== 'undefined') { + const format = image.imageSettings.format; + if ( + format === 'standard' && + typeof image.imageSettings.url !== 'undefined' + ) { + await expect( + page.locator('.vp-portfolio__item-meta-title > a', { + hasText: image.imageSettings.title, + }) + ).toHaveAttribute('href', image.imageSettings.url); + + await expect( + page.getByRole('link', { name: image.alt }) + ).toHaveAttribute('href', image.imageSettings.url); + } + + if ( + format === 'video' && + typeof image.imageSettings.videoUrl !== 'undefined' + ) { + await expect( + page.locator('.vp-portfolio__item-meta-title > a', { + hasText: image.imageSettings.title, + }) + ).toHaveAttribute('href', image.imageSettings.videoUrl); + + await expect( + page.getByRole('link', { name: image.alt }) + ).toHaveAttribute('href', image.imageSettings.videoUrl); + } + } + } else { + await expect( + page.locator('.vp-portfolio__item-meta-excerpt', { + hasText: image.description, + }) + ).toBeVisible(); + } + + await expect(page.getByAltText(image.alt)).toBeVisible(); + } + }); +}); diff --git a/tests/e2e/specs/archive.spec.js b/tests/e2e/specs/archive.spec.js new file mode 100644 index 00000000..7ed9b724 --- /dev/null +++ b/tests/e2e/specs/archive.spec.js @@ -0,0 +1,708 @@ +/** + * WordPress dependencies + */ +import { expect, test } from '@wordpress/e2e-test-utils-playwright'; + +import expectedArchiveCategoryDefault from '../../fixtures/archive/expected-category-default.json'; +import expectedArchiveCategoryPostName from '../../fixtures/archive/expected-category-post-name.json'; +import expectedArchiveDefault from '../../fixtures/archive/expected-default.json'; +import expectedArchivePostName from '../../fixtures/archive/expected-post-name-permalinks.json'; +import portfolioPosts from '../../fixtures/archive/portfolio-posts.json'; +import imageFixtures from '../../fixtures/images.json'; +import { deleteAllPortfolio } from '../utils/delete-all-portfolio'; +import { findAsyncSequential } from '../utils/find-async-sequential'; +import { getWordpressImages } from '../utils/get-wordpress-images'; + +test.describe('archive pages', () => { + test.beforeEach(async ({ requestUtils }) => { + const pluginName = process.env.CORE + ? 'visual-portfolio-pro' + : 'visual-portfolio-posts-amp-image-gallery'; + await requestUtils.activatePlugin(pluginName); + await requestUtils.deleteAllMedia(); + await requestUtils.deleteAllPages(); + await requestUtils.deleteAllPosts(); + await deleteAllPortfolio({ requestUtils }); + }); + test.afterEach(async ({ requestUtils }) => { + await requestUtils.deleteAllMedia(); + await requestUtils.deleteAllPages(); + await requestUtils.deleteAllPosts(); + await deleteAllPortfolio({ requestUtils }); + }); + + /** + * Deleting all categories of portfolio posts. + * + * @param {Admin} admin End to end test utilities for WordPress admin’s user interface. + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + */ + async function deletePortfolioCategories(admin, page) { + await admin.visitAdminPage( + 'edit-tags.php?taxonomy=portfolio_category&post_type=portfolio' + ); + + if ((await page.locator('#the-list > tr').count()) > 1) { + await page.locator('#cb-select-all-1').check(); + await page + .locator('#bulk-action-selector-top') + .selectOption('delete'); + await page.locator('#doaction').click(); + } + } + + /** + * Deleting all tags of portfolio posts. + * + * @param {Admin} admin End to end test utilities for WordPress admin’s user interface. + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + */ + async function deletePortfolioTags(admin, page) { + await admin.visitAdminPage( + 'edit-tags.php?taxonomy=portfolio_tag&post_type=portfolio' + ); + + if ((await page.locator('#the-list > tr').count()) > 1) { + await page.locator('#cb-select-all-1').check(); + await page + .locator('#bulk-action-selector-top') + .selectOption('delete'); + await page.locator('#doaction').click(); + } + } + + /** + * We get all archive items from the archive page on the front end within the current pagination or selected category. + * + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + */ + async function getArchiveItems(page) { + const archiveItems = []; + const items = page.locator( + '.vp-portfolio__items article.vp-portfolio__item-wrap' + ); + + for (const item of await items.all()) { + await page.waitForTimeout(700); + const url = await item + .locator('.vp-portfolio__item-img > a') + .getAttribute('href'); + const categoriesWrapper = item.locator( + '.vp-portfolio__item-meta .vp-portfolio__item-meta-categories > .vp-portfolio__item-meta-category' + ); + + if (await categoriesWrapper.count()) { + const categories = []; + for (const categoryWrap of await categoriesWrapper.all()) { + const category = await categoryWrap + .locator('a') + .innerText(); + const categoryUrl = await categoryWrap + .locator('a') + .getAttribute('href'); + categories.push({ + category, + categoryUrl, + }); + } + } + + const title = await item + .locator('.vp-portfolio__item-meta-title > a') + .innerText(); + + const description = await item + .locator('.vp-portfolio__item-meta-excerpt > div') + .innerText(); + + archiveItems.push({ + url, + categories: + typeof categories !== 'undefined' + ? // eslint-disable-next-line no-undef + categories + : false, + title, + description, + }); + } + + return archiveItems; + } + + /** + * We create portfolio posts for the archives page. + * We fill these posts with pictures, titles, descriptions and other necessary meta data. + * We also set tags and categories. + * + * @param {RequestUtils} requestUtils Playwright utilities for interacting with the WordPress REST API. + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + * @param {Admin} admin End to end test utilities for WordPress admin’s user interface. + * @param {Editor} editor End to end test utilities for the WordPress Block Editor. + */ + async function createPortfolioPosts(requestUtils, page, admin, editor) { + const images = await getWordpressImages({ + requestUtils, + page, + admin, + editor, + }); + + let key = 0; + for (const post of portfolioPosts) { + await admin.createNewPost(post); + + const foundFixtureImage = await findAsyncSequential( + imageFixtures, + async (x) => x.postTitle === post.title + ); + + const foundImage = await findAsyncSequential( + images, + async (x) => x.description === foundFixtureImage.description + ); + + const featuredExpandedPanel = page.getByRole('button', { + name: 'Featured image', + exact: true, + expanded: false, + }); + + const isFeaturedPanelExpanded = await featuredExpandedPanel.count(); + + if (isFeaturedPanelExpanded) { + await featuredExpandedPanel.click(); + } + + await page + .getByRole('button', { name: 'Set featured image' }) + .click(); + + await page.getByRole('tab', { name: 'Media Library' }).click(); + + const imageContainer = page.locator( + 'ul.attachments.ui-sortable.ui-sortable-disabled li.attachment[data-id="' + + foundImage.id + + '"]' + ); + + await imageContainer.click(); + + await page + .getByRole('button', { name: 'Set featured image' }) + .click(); + + const categoriesExpandedPanel = page.getByRole('button', { + name: 'Categories', + exact: true, + expanded: false, + }); + + const isCategoriesPanelExpanded = + await categoriesExpandedPanel.count(); + + if (isCategoriesPanelExpanded) { + await categoriesExpandedPanel.click(); + } + + if (typeof post.categories !== 'undefined') { + for (const category of post.categories) { + const isVisibleCategoryField = + page.getByLabel('New Category Name'); + + if (!(await isVisibleCategoryField.isVisible())) { + await page + .getByRole('button', { name: 'Add New Category' }) + .first() + .click(); + } + + if (await isVisibleCategoryField.isVisible()) { + await isVisibleCategoryField.fill(category); + await page + .getByLabel('Project') + .locator('form') + .getByRole('button', { name: 'Add New Category' }) + .click(); + } + + await page.waitForTimeout(500); + } + } + + const tagsExpandedPanel = page.getByRole('button', { + name: 'Tags', + exact: true, + expanded: false, + }); + + const isTagsExpandedPanel = await tagsExpandedPanel.count(); + + if (isTagsExpandedPanel) { + await tagsExpandedPanel.click(); + } + + if (typeof post.tags !== 'undefined') { + for (const tag of post.tags) { + await page.getByLabel('Add New Tag').fill(tag); + await page.getByLabel('Add New Tag').press('Enter'); + } + } + + //await page.waitForTimeout(500); + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Project', + }) + .first() + .click(); + + const postLink = page.url(); + + portfolioPosts[key].postLink = postLink; + key = key + 1; + } + } + + /** + * We create an archives page and place a block with archive settings on it. + * We select the number of elements displayed on the page, skin and pagination display. + * Setting the display of the category filter. + * + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + * @param {Admin} admin End to end test utilities for WordPress admin’s user interface. + * @param {Editor} editor End to end test utilities for the WordPress Block Editor. + * @return {{archiveID: number, archiveUrl: string}} Return object with archive page ID and archive URL. + */ + async function createArchivePage(page, admin, editor) { + await admin.createNewPost({ + title: 'Portfolio', + postType: 'page', + showWelcomeGuide: false, + legacyCanvas: true, + }); + + await editor.insertBlock({ + name: 'visual-portfolio/block', + }); + + await page.getByRole('button', { name: 'Posts' }).click(); + await page.getByRole('button', { name: 'Continue' }).click(); + await page + .getByRole('button', { name: 'Classic Preview Classic' }) + .click(); + await page.getByRole('button', { name: 'Continue' }).click(); + await page.getByLabel('Filter').check(); + await page.getByRole('button', { name: 'Continue' }).click(); + await page.getByRole('button', { name: 'More' }).click(); + await page.getByRole('button', { name: 'Current Query' }).click(); + await page.getByRole('button', { name: 'Layout' }).click(); + await page.getByRole('button', { name: 'Pagination' }).click(); + await page.getByRole('button', { name: 'Paged' }).click(); + await page.getByLabel('Close', { exact: true }).click(); + await page.getByRole('button', { name: 'Skin' }).click(); + await page.getByRole('button', { name: 'Caption' }).click(); + await page.getByRole('button', { name: 'Elements' }).click(); + + await page + .locator('.components-base-control__field', { + hasText: 'Categories Count', + }) + .locator('input.components-input-control__input') + .fill('3'); + + await page.getByLabel('Display Excerpt').check(); + await page.getByLabel('Excerpt Words Count').fill('20'); + + // Publish Post. + await editor.publishPost(); + + const archiveUrl = await page + .getByLabel('Page address') + .getAttribute('value'); + + let archiveID = await page + .locator('input[name="post_ID"]') + .inputValue(); + archiveID = + typeof archiveID === 'string' ? parseInt(archiveID, 10) : null; + + return { + archiveID, + archiveUrl, + }; + } + + /** + * Install the previously created archives page in the plugin settings. + * + * @param {Admin} admin End to end test utilities for WordPress admin’s user interface. + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + */ + async function setArchiveSettings(admin, page) { + await admin.visitAdminPage('edit.php?post_type=portfolio'); + + await page + .locator('#menu-posts-portfolio') + .getByRole('link', { name: 'Settings' }) + .click(); + await page.getByRole('textbox', { name: '-- Select Page --' }).click(); + await page.getByRole('option', { name: 'Portfolio' }).click(); + await page.getByLabel('Archive Page Items Per Page').fill('2'); + await page.getByRole('button', { name: 'Save Changes' }).click(); + } + + /** + * We receive an array of objects with archive elements in the process of querying the layout on the front-end side. + * This array will be used as a comparison array against the expected result. + * During the survey process, we also collect information about the current state of pagination, + * Understanding what page we are on and what elements surround us. + * + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + * @return { + * { + * items: + * { + * url: any, categories: any, title: any, description: any + * }[], + * pagination: ( + * { + * text: any, + * active: boolean + * } | + * { + * url: any, + * text: any, + * standard: boolean + * } | + * { + * text: any, + * dots: boolean + * } | + * { + * url: any, + * nextPage: boolean + * } + * )[] + * } + * []} + */ + async function getReceivedArchive(page) { + const pageCounts = 5; + const receivedArchive = []; + let currentCount = 0; + + while (currentCount < pageCounts) { + const archivePagination = []; + + await page.waitForTimeout(700); + + const archiveItems = await getArchiveItems(page); + + const pagination = page.locator( + '.vp-portfolio__layout-elements .vp-pagination' + ); + + const paginationItems = pagination.locator('.vp-pagination__item'); + + for (const paginationItem of await paginationItems.all()) { + const classes = await paginationItem.getAttribute('class'); + + if ( + classes === 'vp-pagination__item vp-pagination__item-active' + ) { + const activeElement = await paginationItem.innerText(); + archivePagination.push({ + text: activeElement, + active: true, + }); + } + + if (classes === 'vp-pagination__item') { + const paginationLink = await paginationItem + .locator('a') + .getAttribute('href'); + const paginationText = await paginationItem + .locator('a') + .innerText(); + archivePagination.push({ + url: paginationLink, + text: paginationText, + standard: true, + }); + } + + if ( + classes === 'vp-pagination__item vp-pagination__item-dots' + ) { + const dotsText = await paginationItem.innerText(); + archivePagination.push({ + text: dotsText, + dots: true, + }); + } + + if ( + classes === 'vp-pagination__item vp-pagination__item-next' + ) { + const nextPaginationLink = await paginationItem + .locator('a') + .getAttribute('href'); + archivePagination.push({ + url: nextPaginationLink, + nextPage: true, + }); + } + } + + receivedArchive.push({ + items: archiveItems, + pagination: archivePagination, + }); + + currentCount++; + + if ( + await pagination + .locator('.vp-pagination__item.vp-pagination__item-next') + .count() + ) { + await pagination + .locator( + '.vp-pagination__item.vp-pagination__item-next > a' + ) + .click(); + + await page.waitForTimeout(700); + } + } + + return receivedArchive; + } + + /** + * We receive an array of objects with category elements in the process of querying the layout on the front-end side. + * This array will be used as a comparison array against the expected result. + * During the survey process, we also collect information about the current state of pagination, + * Understanding what page we are on and what elements surround us. + * + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + * @return {{title: any, url: any, items: never[]}[]} + */ + async function getReceivedCategories(page) { + const filterItems = page + .locator('.vp-filter .vp-filter__item') + .filter({ hasNotText: 'All' }); + const receivedCategories = []; + + for (const filterItem of await filterItems.all()) { + receivedCategories.push({ + title: await filterItem + .locator('a') + .getAttribute('data-vp-filter'), + url: await filterItem.locator('a').getAttribute('href'), + items: [], + }); + } + + let categoryKey = 0; + + for (const category of receivedCategories) { + await page + .locator('.vp-filter .vp-filter__item') + .filter({ hasText: category.title }) + .click(); + + await page.waitForTimeout(700); + + let archiveItems = await getArchiveItems(page); + + const pagination = page.locator( + '.vp-portfolio__layout-elements .vp-pagination' + ); + + if (archiveItems.length === 2 && (await pagination.count())) { + await pagination + .locator( + '.vp-pagination__item.vp-pagination__item-next > a' + ) + .click(); + + await page.waitForTimeout(500); + + archiveItems = archiveItems.concat(await getArchiveItems(page)); + } + + receivedCategories[categoryKey].items = archiveItems; + + categoryKey++; + } + + return receivedCategories; + } + + test('check archive page with default pagination and category filter (plain permalinks)', async ({ + page, + admin, + editor, + requestUtils, + }) => { + await deletePortfolioCategories(admin, page); + await deletePortfolioTags(admin, page); + + await createPortfolioPosts(requestUtils, page, admin, editor); + + // Set Permalink Settings. + await admin.visitAdminPage('options-permalink.php'); + await page.getByLabel('Plain').check(); + await page.getByRole('button', { name: 'Save Changes' }).click(); + + const { archiveID, archiveUrl } = await createArchivePage( + page, + admin, + editor + ); + + await setArchiveSettings(admin, page); + + // prepare Fixtures. + const testBaseUrl = process.env.PLAYWRIGHT_TEST_BASE_URL; + let fixtureKey = 0; + for (const expectedArchiveItem of expectedArchiveDefault) { + let paginationKey = 0; + for (const expectedPaginationItem of expectedArchiveItem.pagination) { + if (typeof expectedPaginationItem.url !== 'undefined') { + const fixtureUrl = testBaseUrl + expectedPaginationItem.url; + + expectedArchiveDefault[fixtureKey].pagination[ + paginationKey + ].url = fixtureUrl.replace( + '/?page_id=0000', + '/?page_id=' + archiveID + ); + } + paginationKey++; + } + + let itemKey = 0; + for (const expectedItem of expectedArchiveItem.items) { + expectedArchiveDefault[fixtureKey].items[itemKey].url = + testBaseUrl + expectedItem.url; + itemKey++; + } + + fixtureKey++; + } + + fixtureKey = 0; + for (const expectedArchiveCategoryItem of expectedArchiveCategoryDefault) { + let itemKey = 0; + for (const expectedItem of expectedArchiveCategoryItem.items) { + expectedArchiveCategoryDefault[fixtureKey].items[itemKey].url = + testBaseUrl + expectedItem.url; + itemKey++; + } + const fixtureUrl = testBaseUrl + expectedArchiveCategoryItem.url; + expectedArchiveCategoryDefault[fixtureKey].url = fixtureUrl.replace( + '/?page_id=000', + '/?page_id=' + archiveID + ); + + fixtureKey++; + } + + await page.goto(archiveUrl); + + const receivedArchive = await getReceivedArchive(page); + + // check Archive page + expect(receivedArchive).toEqual(expectedArchiveDefault); + + const receivedCategories = await getReceivedCategories(page); + + await page.waitForTimeout(500); + + // check Archive Category filter + expect(receivedCategories).toEqual(expectedArchiveCategoryDefault); + }); + + test('check archive page with default pagination and category filter (post name permalinks)', async ({ + page, + admin, + editor, + requestUtils, + }) => { + await deletePortfolioCategories(admin, page); + await deletePortfolioTags(admin, page); + + await createPortfolioPosts(requestUtils, page, admin, editor); + + // Set Permalink Settings. + await admin.visitAdminPage('options-permalink.php'); + await page.getByLabel('Post name').check(); + await page.getByRole('button', { name: 'Save Changes' }).click(); + + const { archiveUrl } = await createArchivePage(page, admin, editor); + + await setArchiveSettings(admin, page); + + // prepare Fixtures. + const testBaseUrl = process.env.PLAYWRIGHT_TEST_BASE_URL; + let fixtureKey = 0; + for (const expectedArchiveItem of expectedArchivePostName) { + let paginationKey = 0; + for (const expectedPaginationItem of expectedArchiveItem.pagination) { + if (typeof expectedPaginationItem.url !== 'undefined') { + const fixtureUrl = testBaseUrl + expectedPaginationItem.url; + + expectedArchivePostName[fixtureKey].pagination[ + paginationKey + ].url = fixtureUrl; + } + paginationKey++; + } + + let itemKey = 0; + for (const expectedItem of expectedArchiveItem.items) { + expectedArchivePostName[fixtureKey].items[itemKey].url = + testBaseUrl + expectedItem.url; + itemKey++; + } + + fixtureKey++; + } + + fixtureKey = 0; + for (const expectedArchiveCategoryItem of expectedArchiveCategoryPostName) { + let itemKey = 0; + for (const expectedItem of expectedArchiveCategoryItem.items) { + expectedArchiveCategoryPostName[fixtureKey].items[itemKey].url = + testBaseUrl + expectedItem.url; + itemKey++; + } + expectedArchiveCategoryPostName[fixtureKey].url = + testBaseUrl + expectedArchiveCategoryItem.url; + + fixtureKey++; + } + + await page.goto(archiveUrl); + + const receivedArchive = await getReceivedArchive(page); + + // check Archive page + expect(receivedArchive).toEqual(expectedArchivePostName); + + const receivedCategories = await getReceivedCategories(page); + + await page.waitForTimeout(500); + + // check Archive Category filter + expect(receivedCategories).toEqual(expectedArchiveCategoryPostName); + }); +}); diff --git a/tests/e2e/specs/click-action-images.spec.js b/tests/e2e/specs/click-action-images.spec.js new file mode 100644 index 00000000..ae2d7905 --- /dev/null +++ b/tests/e2e/specs/click-action-images.spec.js @@ -0,0 +1,571 @@ +/** + * WordPress dependencies + */ +import { expect, test } from '@wordpress/e2e-test-utils-playwright'; + +import expectedPopupPreset from '../../fixtures/click-actions/popup-expected-preset.json'; +import expectedUrlPreset from '../../fixtures/click-actions/url-expected-preset.json'; +import { findAsyncSequential } from '../utils/find-async-sequential'; +import { getWordpressImages } from '../utils/get-wordpress-images'; + +test.describe('click action gallery images', () => { + test.beforeAll(async ({ requestUtils }) => { + const pluginName = process.env.CORE + ? 'visual-portfolio-pro' + : 'visual-portfolio-posts-amp-image-gallery'; + await requestUtils.activatePlugin(pluginName); + await requestUtils.deleteAllMedia(); + await requestUtils.deleteAllPages(); + }); + test.afterAll(async ({ requestUtils }) => { + await requestUtils.deleteAllMedia(); + await requestUtils.deleteAllPages(); + }); + + /** + * We prepare the fixture for popup comparison. + * We correct the paths to the images to be current, loaded into the WordPress system. + * + * @param {string} size Image Resolution. + * @param {string} property Image property. + * @param {number} key Key of Image object. + */ + async function preparePopupFixture(size, property, key) { + if ( + typeof expectedPopupPreset[key][property] === 'string' && + expectedPopupPreset[key][property].includes(size) + ) { + switch (size) { + case '2000x2000': + expectedPopupPreset[key][property] = expectedPopupPreset[ + key + ][property].replace('.jpeg', '-1920x1920.jpeg'); + break; + case '3840x2160': + expectedPopupPreset[key][property] = expectedPopupPreset[ + key + ][property].replace('scaled.jpeg', '1920x1080.jpeg'); + break; + case '3840x2560': + expectedPopupPreset[key][property] = expectedPopupPreset[ + key + ][property].replace('scaled.jpeg', '1920x1280.jpeg'); + break; + } + } + } + + /** + * We prepare the fixture for url comparison. + * We correct the paths to the images to be current, loaded into the WordPress system. + * + * @param {string} size Image Resolution. + * @param {string} property Image property. + * @param {number} key Key of Image object. + */ + async function prepareUrlFixture(size, property, key) { + if ( + typeof expectedUrlPreset[key][property] === 'string' && + expectedUrlPreset[key][property].includes(size) + ) { + switch (size) { + case '2000x2000': + expectedUrlPreset[key][property] = expectedUrlPreset[key][ + property + ].replace('.jpeg', '-1920x1920.jpeg'); + break; + case '3840x2160': + expectedUrlPreset[key][property] = expectedUrlPreset[key][ + property + ].replace('scaled.jpeg', '1920x1080.jpeg'); + break; + case '3840x2560': + expectedUrlPreset[key][property] = expectedUrlPreset[key][ + property + ].replace('scaled.jpeg', '1920x1280.jpeg'); + break; + } + } + } + + test('check disabled click action', async ({ + page, + admin, + editor, + requestUtils, + }) => { + await admin.createNewPost({ + title: 'Click Action', + postType: 'page', + showWelcomeGuide: false, + legacyCanvas: true, + }); + + const images = await getWordpressImages({ + requestUtils, + page, + admin, + editor, + }); + + await editor.insertBlock({ + name: 'visual-portfolio/block', + attributes: { + setup_wizard: 'false', + content_source: 'images', + }, + }); + + await page + .locator( + 'button.components-button.vpf-component-gallery-control-item-add', + { + hasText: 'Add Images', + } + ) + .click(); + + await page + .locator('button#menu-item-browse', { + hasText: 'Media Library', + }) + .click(); + + const imageList = page.locator( + 'ul.attachments.ui-sortable.ui-sortable-disabled li.attachment[role="checkbox"]' + ); + + for (const image of await imageList.elementHandles()) { + if ( + typeof images.find( + async (x) => x.id === (await image.getAttribute('data-id')) + ).imgUrl !== 'undefined' + ) { + await image.click(); + } + } + + await page + .locator('button.button.media-button.media-button-select', { + hasText: 'Select', + }) + .click(); + + await page + .locator('.components-panel__body', { + hasText: 'Click Action', + }) + .click(); + + await page + .locator( + 'button.components-button.vpf-component-icon-selector-item', + { + hasText: 'Disabled', + } + ) + .click(); + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + const link = page.locator('a.vp-portfolio__item-meta'); + + await expect(link).toBeHidden(); + }); + + test('check url click action', async ({ + page, + admin, + editor, + requestUtils, + }) => { + // Create post for testing click action. + await admin.createNewPost({ + title: 'URL Click Action', + postType: 'page', + showWelcomeGuide: false, + legacyCanvas: true, + }); + + // Get images for test gallery. + const images = await getWordpressImages({ + requestUtils, + page, + admin, + editor, + alternativeSetting: true, + }); + + /** + * Prepare the fixture. + * Change the date in the link to the image to the current one. + * Also insert the test domain used at the beginning of the link + */ + const testBaseUrl = process.env.PLAYWRIGHT_TEST_BASE_URL; + + const today = new Date(); + + let month = Number(today.getMonth() + 1); + + if (month < 10) { + month = '0' + month; + } + + const currentYearAndMonth = today.getFullYear() + '/' + month; + + expectedUrlPreset.map(async (object, key) => { + if (object.titleUrl.includes('/wp-content/')) { + const titleUrl = testBaseUrl + object.titleUrl; + expectedUrlPreset[key].titleUrl = titleUrl.replace( + /0000\/00/i, + currentYearAndMonth + ); + } + + if (object.titleUrl.includes('page_id')) { + const foundImage = await findAsyncSequential( + images, + async (x) => x.title === object.title + ); + + expectedUrlPreset[key].titleUrl = foundImage.url; + } + + if (object.titleUrl.includes('image')) { + const foundImage = await findAsyncSequential( + images, + async (x) => x.title === object.title + ); + + expectedUrlPreset[key].titleUrl = foundImage.imgUrl; + + const match = foundImage.imgUrl.match(/(\d+x\d+)/); + + if (match) { + const size = match[0]; + await prepareUrlFixture(size, 'titleUrl', key); + } + } + }); + + await editor.insertBlock({ + name: 'visual-portfolio/block', + attributes: { + setup_wizard: 'false', + content_source: 'images', + items_style: 'default', + images, + items_click_action: 'url', + }, + }); + + await page + .locator('.components-base-control__field', { + hasText: 'Items Per Page', + }) + .locator('input.components-text-control__input') + .fill('10'); + + await page.waitForTimeout(2000); + + const galleryImages = page + .frame('vpf-preview-1') + .locator('.vp-portfolio__items .vp-portfolio__item-wrap'); + + const receivedUrlBackendPreset = []; + + // Check Backend. + for (const galleryImage of await galleryImages.all()) { + /** + * Check the layout and collect an array with information about items. + */ + const popup = await galleryImage + .locator('.vp-portfolio__item-popup') + .count(); + const title = galleryImage.locator( + '.vp-portfolio__item-meta-title > a' + ); + const titleText = await title.innerText(); + const titleUrl = await title.getAttribute('href'); + const isPopup = popup ? true : false; + + receivedUrlBackendPreset.push({ + title: titleText, + isPopup, + titleUrl, + }); + } + + // Compare the Backend resulting array of objects with the expected one. + expect(receivedUrlBackendPreset).toEqual(expectedUrlPreset); + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + // Check Frontend. + const galleryFrontendImages = page.locator( + '.vp-portfolio__items .vp-portfolio__item-wrap' + ); + + const receivedUrlFrontendPreset = []; + + for (const galleryImage of await galleryFrontendImages.all()) { + const popup = await galleryImage + .locator('.vp-portfolio__item-popup') + .count(); + const title = galleryImage.locator( + '.vp-portfolio__item-meta-title > a' + ); + const titleText = await title.innerText(); + const titleUrl = await title.getAttribute('href'); + const isPopup = popup ? true : false; + + receivedUrlFrontendPreset.push({ + title: titleText, + isPopup, + titleUrl, + }); + } + + // Compare the Frontend resulting array of objects with the expected one. + expect(receivedUrlFrontendPreset).toEqual(expectedUrlPreset); + }); + + test('check popup click action', async ({ + page, + admin, + editor, + requestUtils, + }) => { + // Create post for testing click action. + await admin.createNewPost({ + title: 'URL Click Action', + postType: 'page', + showWelcomeGuide: false, + legacyCanvas: true, + }); + + // Get images for test gallery. + const images = await getWordpressImages({ + requestUtils, + page, + admin, + editor, + alternativeSetting: true, + }); + + /** + * Prepare the fixture. + * Change the date in the link to the image to the current one. + * Also insert the test domain used at the beginning of the link + */ + const testBaseUrl = process.env.PLAYWRIGHT_TEST_BASE_URL; + + const today = new Date(); + + let month = Number(today.getMonth() + 1); + + if (month < 10) { + month = '0' + month; + } + + const currentYearAndMonth = today.getFullYear() + '/' + month; + + expectedPopupPreset.map(async (object, key) => { + if (object.titleUrl.includes('/wp-content/')) { + const titleUrl = testBaseUrl + object.titleUrl; + expectedPopupPreset[key].titleUrl = titleUrl.replace( + /0000\/00/i, + currentYearAndMonth + ); + } + + if (object.imageUrl && object.imageUrl.includes('/wp-content/')) { + const imageUrl = testBaseUrl + object.imageUrl; + expectedPopupPreset[key].imageUrl = imageUrl.replace( + /0000\/00/i, + currentYearAndMonth + ); + } + + if (object.titleUrl.includes('page_id')) { + const foundImage = await findAsyncSequential( + images, + async (x) => x.title === object.title + ); + + expectedPopupPreset[key].titleUrl = foundImage.url; + } + + if (object.titleUrl.includes('image')) { + const foundImage = await findAsyncSequential( + images, + async (x) => x.title === object.title + ); + + expectedPopupPreset[key].titleUrl = foundImage.imgUrl; + } + + if ( + typeof object.imageUrl === 'string' && + object.imageUrl.includes('image') + ) { + const foundImage = await findAsyncSequential( + images, + async (x) => x.title === object.title + ); + + expectedPopupPreset[key].imageUrl = foundImage.imgUrl; + + const match = foundImage.imgUrl.match(/(\d+x\d+)/); + + if (match) { + const size = match[0]; + await preparePopupFixture(size, 'titleUrl', key); + await preparePopupFixture(size, 'imageUrl', key); + } + } + }); + + await editor.insertBlock({ + name: 'visual-portfolio/block', + attributes: { + setup_wizard: 'false', + content_source: 'images', + items_style: 'default', + images, + items_click_action: 'popup_gallery', + }, + }); + + await page + .locator('.components-base-control__field', { + hasText: 'Items Per Page', + }) + .locator('input.components-text-control__input') + .fill('10'); + + await page.waitForTimeout(3000); + + const galleryImages = page + .frame('vpf-preview-1') + .locator('.vp-portfolio__items .vp-portfolio__item-wrap'); + + const receivedPopupBackendPreset = []; + + // Check Backend. + for (const galleryImage of await galleryImages.all()) { + /** + * Check the layout and collect an array with information about items. + */ + const popup = galleryImage.locator('.vp-portfolio__item-popup'); + const isVideoPopup = await galleryImage + .locator('[data-vp-popup-video]') + .count(); + const isImagePopup = await galleryImage + .locator('[data-vp-popup-img]') + .count(); + const title = galleryImage.locator( + '.vp-portfolio__item-meta-title > a' + ); + const titleText = await title.innerText(); + const titleUrl = await title.getAttribute('href'); + const isPopup = (await popup.count()) ? true : false; + + let videoUrl = false, + imageUrl = false; + + if (isVideoPopup) { + videoUrl = await popup.getAttribute('data-vp-popup-video'); + } + + if (isImagePopup) { + imageUrl = await popup.getAttribute('data-vp-popup-img'); + } + + receivedPopupBackendPreset.push({ + title: titleText, + isPopup, + titleUrl, + imageUrl, + videoUrl, + }); + } + + // Compare the Backend resulting array of objects with the expected one. + expect(receivedPopupBackendPreset).toEqual(expectedPopupPreset); + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + // Check Frontend. + const galleryFrontendImages = page.locator( + '.vp-portfolio__items .vp-portfolio__item-wrap' + ); + + const receivedPopupFrontendPreset = []; + + for (const galleryImage of await galleryFrontendImages.all()) { + const popup = galleryImage.locator('.vp-portfolio__item-popup'); + const isVideoPopup = await galleryImage + .locator('[data-vp-popup-video]') + .count(); + const isImagePopup = await galleryImage + .locator('[data-vp-popup-img]') + .count(); + const title = galleryImage.locator( + '.vp-portfolio__item-meta-title > a' + ); + const titleText = await title.innerText(); + const titleUrl = await title.getAttribute('href'); + const isPopup = (await popup.count()) ? true : false; + + let videoUrl = false, + imageUrl = false; + + if (isVideoPopup) { + videoUrl = await popup.getAttribute('data-vp-popup-video'); + } + + if (isImagePopup) { + imageUrl = await popup.getAttribute('data-vp-popup-img'); + } + + receivedPopupFrontendPreset.push({ + title: titleText, + isPopup, + titleUrl, + imageUrl, + videoUrl, + }); + } + + // Compare the Frontend resulting array of objects with the expected one. + expect(receivedPopupFrontendPreset).toEqual(expectedPopupPreset); + }); +}); diff --git a/tests/e2e/specs/initial-loading.spec.js b/tests/e2e/specs/initial-loading.spec.js index 3077b959..ab6b255c 100644 --- a/tests/e2e/specs/initial-loading.spec.js +++ b/tests/e2e/specs/initial-loading.spec.js @@ -2,9 +2,10 @@ import { expect, test } from '@wordpress/e2e-test-utils-playwright'; test.describe('initial loading', () => { test.beforeAll(async ({ requestUtils }) => { - await requestUtils.activatePlugin( - 'visual-portfolio-posts-amp-image-gallery' - ); + const pluginName = process.env.CORE + ? 'visual-portfolio-pro' + : 'visual-portfolio-posts-amp-image-gallery'; + await requestUtils.activatePlugin(pluginName); }); test('should have visual portfolio in admin menu', async ({ diff --git a/tests/e2e/utils/delete-all-portfolio.js b/tests/e2e/utils/delete-all-portfolio.js new file mode 100644 index 00000000..88425b1a --- /dev/null +++ b/tests/e2e/utils/delete-all-portfolio.js @@ -0,0 +1,31 @@ +/** + * Delete all posts using REST API. + * + * @param this + * @param this.requestUtils + */ +export async function deleteAllPortfolio({ requestUtils }) { + // List all portfolio posts. + const posts = await requestUtils.rest({ + path: '/wp/v2/portfolio', + params: { + per_page: 100, + // All possible statuses. + status: 'publish,future,draft,pending,private,trash', + }, + }); + + // Delete all portfolio one by one. + // "/wp/v2/posts" not yet supports batch requests. + await Promise.all( + posts.map((post) => + requestUtils.rest({ + method: 'DELETE', + path: `/wp/v2/portfolio/${post.id}`, + params: { + force: true, + }, + }) + ) + ); +} diff --git a/tests/e2e/utils/find-async-sequential.js b/tests/e2e/utils/find-async-sequential.js new file mode 100644 index 00000000..81353b0f --- /dev/null +++ b/tests/e2e/utils/find-async-sequential.js @@ -0,0 +1,15 @@ +/** + * async version of Array.find() + * returns the first element in the provided array that satisfies the provided testin function + * + * @param {Array} array your test array + * @param {Function} asyncCallback callback + * @return {Promise.} first element that passed the test + */ +export async function findAsyncSequential(array, asyncCallback) { + for (const element of array) { + if (await asyncCallback(element)) { + return element; + } + } +} diff --git a/tests/e2e/utils/get-wordpress-images.js b/tests/e2e/utils/get-wordpress-images.js new file mode 100644 index 00000000..1a66c4ef --- /dev/null +++ b/tests/e2e/utils/get-wordpress-images.js @@ -0,0 +1,150 @@ +/** + * External dependencies + */ +const path = require('path'); + +/** + * Test Images + */ +import imagePaths from '../../fixtures/images.json'; + +/** + * + * @param {RequestUtils} requestUtils Playwright utilities for interacting with the WordPress REST API. + * @param {Page} page Provides methods to interact with a single tab in a Browser, or an extension background page in Chromium. + * @param {Admin} admin End to end test utilities for WordPress admin’s user interface. + * @param {Editor} editor End to end test utilities for the WordPress Block Editor. + * @param {boolean} alternativeSetting Set alternative meta settings for test images. + * @return {{images: {format: string, video_url: string, url: string}[]}} + */ +export async function getWordpressImages({ + requestUtils, + page, + admin, + editor, + alternativeSetting = false, +}) { + let images = []; + let postLink = ''; + + if (alternativeSetting) { + const currentPage = page.url(); + + // Create a post for a image that has a link to an internal WordPress post. + await admin.createNewPost({ + title: 'Sample Test Page', + postType: 'page', + content: 'Test content', + showWelcomeGuide: false, + legacyCanvas: true, + }); + + // Publish Post. + await editor.publishPost(); + + // Go to published post. + await page + .locator('.components-button', { + hasText: 'View Page', + }) + .first() + .click(); + + // Remember the link to the post for future use inside the meta image. + postLink = page.url(); + + await page.goto(currentPage); + } + + images = await Promise.all( + imagePaths.map(async (object) => { + const filepath = path.join('tests/fixtures/', object.filename); + // Upload image to WordPress gallery. + const media = await requestUtils.uploadMedia(filepath); + + const periodIndex = object.filename.indexOf('.'); + + let image = {}; + + // We collect all the meta data of the image and write it to an array. + let title = + periodIndex !== -1 + ? object.filename.substring(0, periodIndex) + : object.filename; + + let description = object.description; + + title = object.title !== 'undefined' ? object.title : title; + + if (alternativeSetting) { + title = + typeof object.imageSettings !== 'undefined' + ? object.imageSettings.title + : title; + description = + typeof object.imageSettings !== 'undefined' + ? object.imageSettings.description + : description; + } + + image = { + id: media.id, + imgUrl: media.source_url, + imgThumbnailUrl: media.source_url, + title, + description, + }; + + if (alternativeSetting) { + const format = + typeof object.imageSettings !== 'undefined' && + typeof object.imageSettings.format !== 'undefined' + ? object.imageSettings.format + : false; + if (format) { + image.format = format; + } + + const videoUrl = + typeof object.imageSettings !== 'undefined' && + typeof object.imageSettings.format !== 'undefined' && + object.imageSettings.format === 'video' && + typeof object.imageSettings.videoUrl !== 'undefined' + ? object.imageSettings.videoUrl + : false; + if (videoUrl) { + image.video_url = videoUrl; + } + + let url = + typeof object.imageSettings !== 'undefined' && + typeof object.imageSettings.format !== 'undefined' && + object.imageSettings.format === 'standard' && + typeof object.imageSettings.url !== 'undefined' && + object.imageSettings.url !== 'postLink' + ? object.imageSettings.url + : false; + if (url) { + image.url = url; + } + + url = + typeof object.imageSettings !== 'undefined' && + typeof object.imageSettings.format !== 'undefined' && + object.imageSettings.format === 'standard' && + typeof object.imageSettings.url !== 'undefined' && + object.imageSettings.url === 'postLink' + ? postLink + : url; + + if (url) { + image.url = url; + } + } + + return image; + }) + ); + + return images; +} diff --git a/tests/fixtures/archive/expected-category-default.json b/tests/fixtures/archive/expected-category-default.json new file mode 100644 index 00000000..5cfa8daf --- /dev/null +++ b/tests/fixtures/archive/expected-category-default.json @@ -0,0 +1,116 @@ +[ + { + "title": "bicycle", + "url": "/?page_id=000&vp_filter=portfolio_category%3Abicycle", + "items": [ + { + "url": "/?portfolio=portfolio-2-test-post", + "categories": false, + "title": "Portfolio 2 test post", + "description": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce." + } + ] + }, + { + "title": "car", + "url": "/?page_id=000&vp_filter=portfolio_category%3Acar", + "items": [ + { + "url": "/?portfolio=portfolio-4-test-post", + "categories": false, + "title": "Portfolio 4 test post", + "description": "Aenean vel arcu enim. Aliquam sed rutrum erat, porta mattis lorem. Nulla scelerisque eu ligula eget dictum. Phasellus orci nisi." + }, + { + "url": "/?portfolio=portfolio-3-test-post", + "categories": false, + "title": "Portfolio 3 test post", + "description": "Aliquam sed pretium purus. Cras viverra viverra felis. Ut vitae massa felis. Curabitur tempus vitae eros eu feugiat. Ut molestie." + }, + { + "url": "/?portfolio=portfolio-2-test-post", + "categories": false, + "title": "Portfolio 2 test post", + "description": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce." + } + ] + }, + { + "title": "ocean", + "url": "/?page_id=000&vp_filter=portfolio_category%3Aocean", + "items": [ + { + "url": "/?portfolio=portfolio-7-test-post", + "categories": false, + "title": "Portfolio 7 test post", + "description": "Nulla tincidunt arcu in dictum elementum. Quisque fringilla venenatis nulla ut sollicitudin. Praesent facilisis a libero laoreet viverra. Nunc placerat." + }, + { + "url": "/?portfolio=portfolio-5-test-post", + "categories": false, + "title": "Portfolio 5 test post", + "description": "Morbi tincidunt aliquet velit vitae imperdiet. Curabitur ex mauris, pharetra sit amet varius in, iaculis at libero. Interdum et malesuada." + }, + { + "url": "/?portfolio=portfolio-3-test-post", + "categories": false, + "title": "Portfolio 3 test post", + "description": "Aliquam sed pretium purus. Cras viverra viverra felis. Ut vitae massa felis. Curabitur tempus vitae eros eu feugiat. Ut molestie." + }, + { + "url": "/?portfolio=portfolio-1-test-post", + "categories": false, + "title": "Portfolio 1 test post", + "description": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat." + } + ] + }, + { + "title": "pesto", + "url": "/?page_id=000&vp_filter=portfolio_category%3Apesto", + "items": [ + { + "url": "/?portfolio=portfolio-10-test-post", + "categories": false, + "title": "Portfolio 10 test post", + "description": "Curabitur mollis convallis congue. Pellentesque vel lobortis diam. Morbi et sagittis mi, mollis vehicula dui. Maecenas arcu justo, facilisis non." + } + ] + }, + { + "title": "sea", + "url": "/?page_id=000&vp_filter=portfolio_category%3Asea", + "items": [ + { + "url": "/?portfolio=portfolio-8-test-post", + "categories": false, + "title": "Portfolio 8 test post", + "description": "Morbi id justo tortor. Morbi semper faucibus ligula, ut porttitor velit facilisis eget. Aliquam eleifend dignissim neque nec placerat. Nulla." + }, + { + "url": "/?portfolio=portfolio-1-test-post", + "categories": false, + "title": "Portfolio 1 test post", + "description": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat." + } + ] + }, + { + "title": "something", + "url": "/?page_id=000&vp_filter=portfolio_category%3Asomething", + "items": [ + { + "url": "/?portfolio=portfolio-2-test-post", + "categories": false, + "title": "Portfolio 2 test post", + "description": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce." + }, + { + "url": "/?portfolio=portfolio-1-test-post", + "categories": false, + "title": "Portfolio 1 test post", + "description": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat." + } + ] + } +] diff --git a/tests/fixtures/archive/expected-category-post-name.json b/tests/fixtures/archive/expected-category-post-name.json new file mode 100644 index 00000000..2a179b05 --- /dev/null +++ b/tests/fixtures/archive/expected-category-post-name.json @@ -0,0 +1,116 @@ +[ + { + "title": "bicycle", + "url": "/portfolio-category/bicycle/", + "items": [ + { + "url": "/portfolio/portfolio-2-test-post/", + "categories": false, + "title": "Portfolio 2 test post", + "description": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce." + } + ] + }, + { + "title": "car", + "url": "/portfolio-category/car/", + "items": [ + { + "url": "/portfolio/portfolio-4-test-post/", + "categories": false, + "title": "Portfolio 4 test post", + "description": "Aenean vel arcu enim. Aliquam sed rutrum erat, porta mattis lorem. Nulla scelerisque eu ligula eget dictum. Phasellus orci nisi." + }, + { + "url": "/portfolio/portfolio-3-test-post/", + "categories": false, + "title": "Portfolio 3 test post", + "description": "Aliquam sed pretium purus. Cras viverra viverra felis. Ut vitae massa felis. Curabitur tempus vitae eros eu feugiat. Ut molestie." + }, + { + "url": "/portfolio/portfolio-2-test-post/", + "categories": false, + "title": "Portfolio 2 test post", + "description": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce." + } + ] + }, + { + "title": "ocean", + "url": "/portfolio-category/ocean/", + "items": [ + { + "url": "/portfolio/portfolio-7-test-post/", + "categories": false, + "title": "Portfolio 7 test post", + "description": "Nulla tincidunt arcu in dictum elementum. Quisque fringilla venenatis nulla ut sollicitudin. Praesent facilisis a libero laoreet viverra. Nunc placerat." + }, + { + "url": "/portfolio/portfolio-5-test-post/", + "categories": false, + "title": "Portfolio 5 test post", + "description": "Morbi tincidunt aliquet velit vitae imperdiet. Curabitur ex mauris, pharetra sit amet varius in, iaculis at libero. Interdum et malesuada." + }, + { + "url": "/portfolio/portfolio-3-test-post/", + "categories": false, + "title": "Portfolio 3 test post", + "description": "Aliquam sed pretium purus. Cras viverra viverra felis. Ut vitae massa felis. Curabitur tempus vitae eros eu feugiat. Ut molestie." + }, + { + "url": "/portfolio/portfolio-1-test-post/", + "categories": false, + "title": "Portfolio 1 test post", + "description": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat." + } + ] + }, + { + "title": "pesto", + "url": "/portfolio-category/pesto/", + "items": [ + { + "url": "/portfolio/portfolio-10-test-post/", + "categories": false, + "title": "Portfolio 10 test post", + "description": "Curabitur mollis convallis congue. Pellentesque vel lobortis diam. Morbi et sagittis mi, mollis vehicula dui. Maecenas arcu justo, facilisis non." + } + ] + }, + { + "title": "sea", + "url": "/portfolio-category/sea/", + "items": [ + { + "url": "/portfolio/portfolio-8-test-post/", + "categories": false, + "title": "Portfolio 8 test post", + "description": "Morbi id justo tortor. Morbi semper faucibus ligula, ut porttitor velit facilisis eget. Aliquam eleifend dignissim neque nec placerat. Nulla." + }, + { + "url": "/portfolio/portfolio-1-test-post/", + "categories": false, + "title": "Portfolio 1 test post", + "description": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat." + } + ] + }, + { + "title": "something", + "url": "/portfolio-category/something/", + "items": [ + { + "url": "/portfolio/portfolio-2-test-post/", + "categories": false, + "title": "Portfolio 2 test post", + "description": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce." + }, + { + "url": "/portfolio/portfolio-1-test-post/", + "categories": false, + "title": "Portfolio 1 test post", + "description": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat." + } + ] + } +] diff --git a/tests/fixtures/archive/expected-default.json b/tests/fixtures/archive/expected-default.json new file mode 100644 index 00000000..6f7e2910 --- /dev/null +++ b/tests/fixtures/archive/expected-default.json @@ -0,0 +1,226 @@ +[ + { + "items": [ + { + "url": "/?portfolio=portfolio-10-test-post", + "categories": false, + "title": "Portfolio 10 test post", + "description": "Curabitur mollis convallis congue. Pellentesque vel lobortis diam. Morbi et sagittis mi, mollis vehicula dui. Maecenas arcu justo, facilisis non." + }, + { + "url": "/?portfolio=portfolio-9-test-post", + "categories": false, + "title": "Portfolio 9 test post", + "description": "Quisque tristique, velit et auctor ultrices, ante diam faucibus tellus, quis sodales leo nulla eu ante. Sed condimentum dolor gravida." + } + ], + "pagination": [ + { + "text": "1", + "active": true + }, + { + "url": "/?page_id=0000&vp_page=2", + "text": "2", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=3", + "text": "3", + "standard": true + }, + { + "text": "…", + "dots": true + }, + { + "url": "/?page_id=0000&vp_page=5", + "text": "5", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=2", + "nextPage": true + } + ] + }, + { + "items": [ + { + "url": "/?portfolio=portfolio-8-test-post", + "categories": false, + "title": "Portfolio 8 test post", + "description": "Morbi id justo tortor. Morbi semper faucibus ligula, ut porttitor velit facilisis eget. Aliquam eleifend dignissim neque nec placerat. Nulla." + }, + { + "url": "/?portfolio=portfolio-7-test-post", + "categories": false, + "title": "Portfolio 7 test post", + "description": "Nulla tincidunt arcu in dictum elementum. Quisque fringilla venenatis nulla ut sollicitudin. Praesent facilisis a libero laoreet viverra. Nunc placerat." + } + ], + "pagination": [ + { + "url": "/?page_id=0000&vp_page=1", + "text": "1", + "standard": true + }, + { + "text": "2", + "active": true + }, + { + "url": "/?page_id=0000&vp_page=3", + "text": "3", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=4", + "text": "4", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=5", + "text": "5", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=3", + "nextPage": true + } + ] + }, + { + "items": [ + { + "url": "/?portfolio=portfolio-6-test-post", + "categories": false, + "title": "Portfolio 6 test post", + "description": "Aenean consectetur massa sed aliquet mollis. Etiam elementum lacus sed urna faucibus pulvinar. Duis dictum nisl eget urna vestibulum semper." + }, + { + "url": "/?portfolio=portfolio-5-test-post", + "categories": false, + "title": "Portfolio 5 test post", + "description": "Morbi tincidunt aliquet velit vitae imperdiet. Curabitur ex mauris, pharetra sit amet varius in, iaculis at libero. Interdum et malesuada." + } + ], + "pagination": [ + { + "url": "/?page_id=0000&vp_page=1", + "text": "1", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=2", + "text": "2", + "standard": true + }, + { + "text": "3", + "active": true + }, + { + "url": "/?page_id=0000&vp_page=4", + "text": "4", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=5", + "text": "5", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=4", + "nextPage": true + } + ] + }, + { + "items": [ + { + "url": "/?portfolio=portfolio-4-test-post", + "categories": false, + "title": "Portfolio 4 test post", + "description": "Aenean vel arcu enim. Aliquam sed rutrum erat, porta mattis lorem. Nulla scelerisque eu ligula eget dictum. Phasellus orci nisi." + }, + { + "url": "/?portfolio=portfolio-3-test-post", + "categories": false, + "title": "Portfolio 3 test post", + "description": "Aliquam sed pretium purus. Cras viverra viverra felis. Ut vitae massa felis. Curabitur tempus vitae eros eu feugiat. Ut molestie." + } + ], + "pagination": [ + { + "url": "/?page_id=0000&vp_page=1", + "text": "1", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=2", + "text": "2", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=3", + "text": "3", + "standard": true + }, + { + "text": "4", + "active": true + }, + { + "url": "/?page_id=0000&vp_page=5", + "text": "5", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=5", + "nextPage": true + } + ] + }, + { + "items": [ + { + "url": "/?portfolio=portfolio-2-test-post", + "categories": false, + "title": "Portfolio 2 test post", + "description": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce." + }, + { + "url": "/?portfolio=portfolio-1-test-post", + "categories": false, + "title": "Portfolio 1 test post", + "description": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat." + } + ], + "pagination": [ + { + "url": "/?page_id=0000&vp_page=1", + "text": "1", + "standard": true + }, + { + "text": "…", + "dots": true + }, + { + "url": "/?page_id=0000&vp_page=3", + "text": "3", + "standard": true + }, + { + "url": "/?page_id=0000&vp_page=4", + "text": "4", + "standard": true + }, + { + "text": "5", + "active": true + } + ] + } + ] diff --git a/tests/fixtures/archive/expected-post-name-permalinks.json b/tests/fixtures/archive/expected-post-name-permalinks.json new file mode 100644 index 00000000..e5ab87a3 --- /dev/null +++ b/tests/fixtures/archive/expected-post-name-permalinks.json @@ -0,0 +1,226 @@ +[ + { + "items": [ + { + "url": "/portfolio/portfolio-10-test-post/", + "categories": false, + "title": "Portfolio 10 test post", + "description": "Curabitur mollis convallis congue. Pellentesque vel lobortis diam. Morbi et sagittis mi, mollis vehicula dui. Maecenas arcu justo, facilisis non." + }, + { + "url": "/portfolio/portfolio-9-test-post/", + "categories": false, + "title": "Portfolio 9 test post", + "description": "Quisque tristique, velit et auctor ultrices, ante diam faucibus tellus, quis sodales leo nulla eu ante. Sed condimentum dolor gravida." + } + ], + "pagination": [ + { + "text": "1", + "active": true + }, + { + "url": "/portfolio/page/2/", + "text": "2", + "standard": true + }, + { + "url": "/portfolio/page/3/", + "text": "3", + "standard": true + }, + { + "text": "…", + "dots": true + }, + { + "url": "/portfolio/page/5/", + "text": "5", + "standard": true + }, + { + "url": "/portfolio/page/2/", + "nextPage": true + } + ] + }, + { + "items": [ + { + "url": "/portfolio/portfolio-8-test-post/", + "categories": false, + "title": "Portfolio 8 test post", + "description": "Morbi id justo tortor. Morbi semper faucibus ligula, ut porttitor velit facilisis eget. Aliquam eleifend dignissim neque nec placerat. Nulla." + }, + { + "url": "/portfolio/portfolio-7-test-post/", + "categories": false, + "title": "Portfolio 7 test post", + "description": "Nulla tincidunt arcu in dictum elementum. Quisque fringilla venenatis nulla ut sollicitudin. Praesent facilisis a libero laoreet viverra. Nunc placerat." + } + ], + "pagination": [ + { + "url": "/portfolio/page/1/", + "text": "1", + "standard": true + }, + { + "text": "2", + "active": true + }, + { + "url": "/portfolio/page/3/", + "text": "3", + "standard": true + }, + { + "url": "/portfolio/page/4/", + "text": "4", + "standard": true + }, + { + "url": "/portfolio/page/5/", + "text": "5", + "standard": true + }, + { + "url": "/portfolio/page/3/", + "nextPage": true + } + ] + }, + { + "items": [ + { + "url": "/portfolio/portfolio-6-test-post/", + "categories": false, + "title": "Portfolio 6 test post", + "description": "Aenean consectetur massa sed aliquet mollis. Etiam elementum lacus sed urna faucibus pulvinar. Duis dictum nisl eget urna vestibulum semper." + }, + { + "url": "/portfolio/portfolio-5-test-post/", + "categories": false, + "title": "Portfolio 5 test post", + "description": "Morbi tincidunt aliquet velit vitae imperdiet. Curabitur ex mauris, pharetra sit amet varius in, iaculis at libero. Interdum et malesuada." + } + ], + "pagination": [ + { + "url": "/portfolio/page/1/", + "text": "1", + "standard": true + }, + { + "url": "/portfolio/page/2/", + "text": "2", + "standard": true + }, + { + "text": "3", + "active": true + }, + { + "url": "/portfolio/page/4/", + "text": "4", + "standard": true + }, + { + "url": "/portfolio/page/5/", + "text": "5", + "standard": true + }, + { + "url": "/portfolio/page/4/", + "nextPage": true + } + ] + }, + { + "items": [ + { + "url": "/portfolio/portfolio-4-test-post/", + "categories": false, + "title": "Portfolio 4 test post", + "description": "Aenean vel arcu enim. Aliquam sed rutrum erat, porta mattis lorem. Nulla scelerisque eu ligula eget dictum. Phasellus orci nisi." + }, + { + "url": "/portfolio/portfolio-3-test-post/", + "categories": false, + "title": "Portfolio 3 test post", + "description": "Aliquam sed pretium purus. Cras viverra viverra felis. Ut vitae massa felis. Curabitur tempus vitae eros eu feugiat. Ut molestie." + } + ], + "pagination": [ + { + "url": "/portfolio/page/1/", + "text": "1", + "standard": true + }, + { + "url": "/portfolio/page/2/", + "text": "2", + "standard": true + }, + { + "url": "/portfolio/page/3/", + "text": "3", + "standard": true + }, + { + "text": "4", + "active": true + }, + { + "url": "/portfolio/page/5/", + "text": "5", + "standard": true + }, + { + "url": "/portfolio/page/5/", + "nextPage": true + } + ] + }, + { + "items": [ + { + "url": "/portfolio/portfolio-2-test-post/", + "categories": false, + "title": "Portfolio 2 test post", + "description": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce." + }, + { + "url": "/portfolio/portfolio-1-test-post/", + "categories": false, + "title": "Portfolio 1 test post", + "description": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat." + } + ], + "pagination": [ + { + "url": "/portfolio/page/1/", + "text": "1", + "standard": true + }, + { + "text": "…", + "dots": true + }, + { + "url": "/portfolio/page/3/", + "text": "3", + "standard": true + }, + { + "url": "/portfolio/page/4/", + "text": "4", + "standard": true + }, + { + "text": "5", + "active": true + } + ] + } +] diff --git a/tests/fixtures/archive/portfolio-posts.json b/tests/fixtures/archive/portfolio-posts.json new file mode 100644 index 00000000..cffffb78 --- /dev/null +++ b/tests/fixtures/archive/portfolio-posts.json @@ -0,0 +1,88 @@ +[ + { + "title": "Portfolio 1 test post", + "postType": "portfolio", + "content": "TMauris id tincidunt urna, ut mattis mauris. Curabitur in massa vel felis pretium aliquet vitae ut elit. Aenean at volutpat.", + "categories": ["sea", "ocean", "something"], + "tags": ["tag 1", "tag 2", "tag 3"], + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 2 test post", + "postType": "portfolio", + "content": "Nam at nibh feugiat, semper nisl vel, porttitor nibh. Aliquam massa diam, tincidunt nec lobortis a, fermentum vitae elit. Fusce.", + "categories": ["bicycle", "car", "something"], + "tags": ["tag 3", "tag 4", "tag 5"], + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 3 test post", + "postType": "portfolio", + "content": "Aliquam sed pretium purus. Cras viverra viverra felis. Ut vitae massa felis. Curabitur tempus vitae eros eu feugiat. Ut molestie.", + "categories": ["car", "ocean"], + "tags": ["tag 1", "tag 4"], + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 4 test post", + "postType": "portfolio", + "content": "Aenean vel arcu enim. Aliquam sed rutrum erat, porta mattis lorem. Nulla scelerisque eu ligula eget dictum. Phasellus orci nisi.", + "categories": ["car"], + "tags": ["tag 3"], + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 5 test post", + "postType": "portfolio", + "content": "Morbi tincidunt aliquet velit vitae imperdiet. Curabitur ex mauris, pharetra sit amet varius in, iaculis at libero. Interdum et malesuada.", + "categories": ["ocean"], + "tags": ["tag 2", "tag 3"], + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 6 test post", + "postType": "portfolio", + "content": "Aenean consectetur massa sed aliquet mollis. Etiam elementum lacus sed urna faucibus pulvinar. Duis dictum nisl eget urna vestibulum semper.", + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 7 test post", + "postType": "portfolio", + "content": "Nulla tincidunt arcu in dictum elementum. Quisque fringilla venenatis nulla ut sollicitudin. Praesent facilisis a libero laoreet viverra. Nunc placerat.", + "categories": ["ocean"], + "tags": ["tag 2", "tag 3"], + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 8 test post", + "postType": "portfolio", + "content": "Morbi id justo tortor. Morbi semper faucibus ligula, ut porttitor velit facilisis eget. Aliquam eleifend dignissim neque nec placerat. Nulla.", + "categories": ["sea"], + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 9 test post", + "postType": "portfolio", + "content": "Quisque tristique, velit et auctor ultrices, ante diam faucibus tellus, quis sodales leo nulla eu ante. Sed condimentum dolor gravida.", + "tags": ["tag 1"], + "showWelcomeGuide": false, + "legacyCanvas": true + }, + { + "title": "Portfolio 10 test post", + "postType": "portfolio", + "content": "Curabitur mollis convallis congue. Pellentesque vel lobortis diam. Morbi et sagittis mi, mollis vehicula dui. Maecenas arcu justo, facilisis non.", + "categories": ["pesto"], + "tags": ["tag 6"], + "showWelcomeGuide": false, + "legacyCanvas": true + } +] diff --git a/tests/fixtures/click-actions/popup-expected-preset.json b/tests/fixtures/click-actions/popup-expected-preset.json new file mode 100644 index 00000000..03e8ae5c --- /dev/null +++ b/tests/fixtures/click-actions/popup-expected-preset.json @@ -0,0 +1,72 @@ +[ + { + "title": "Alternative title of 300 on 200", + "isPopup": true, + "titleUrl": "https://www.youtube.com/watch?v=354pybu91aQ&ab_channel=VisualPortfolio", + "imageUrl": false, + "videoUrl": "https://www.youtube.com/watch?v=354pybu91aQ&ab_channel=VisualPortfolio" + }, + { + "title": "Alternative title of 600 on 1920", + "isPopup": false, + "titleUrl": "https://visualportfolio.co/", + "imageUrl": false, + "videoUrl": false + }, + { + "title": "Alternative title of 800 on 600", + "isPopup": true, + "titleUrl": "/wp-content/uploads/0000/00/image-800x600-2.png", + "imageUrl": "/wp-content/uploads/0000/00/image-800x600-2.png", + "videoUrl": false + }, + { + "title": "Alternative title of 800 on 1200", + "isPopup": false, + "titleUrl": "/?page_id=3534", + "imageUrl": false, + "videoUrl": false + }, + { + "title": "Alternative title of 1600 on 1200", + "isPopup": true, + "titleUrl": "/wp-content/uploads/0000/00/image-1600x1200-2.jpeg", + "imageUrl": "/wp-content/uploads/0000/00/image-1600x1200-2.jpeg", + "videoUrl": false + }, + { + "title": "Alternative title of 1920 on 600", + "isPopup": true, + "titleUrl": "https://www.youtube.com/watch?v=354pybu91aQ&ab_channel=VisualPortfolio", + "imageUrl": false, + "videoUrl": "https://www.youtube.com/watch?v=354pybu91aQ&ab_channel=VisualPortfolio" + }, + { + "title": "Image Title of 1920 on 1080", + "isPopup": true, + "titleUrl": "/wp-content/uploads/0000/00/image-1920x1080-2.jpeg", + "imageUrl": "/wp-content/uploads/0000/00/image-1920x1080-2.jpeg", + "videoUrl": false + }, + { + "title": "Image Title of 2000 on 2000", + "isPopup": true, + "titleUrl": "/wp-content/uploads/0000/00/image-2000x2000-2-1920x1920.jpeg", + "imageUrl": "/wp-content/uploads/0000/00/image-2000x2000-2-1920x1920.jpeg", + "videoUrl": false + }, + { + "title": "Image Title of 3840 on 2160", + "isPopup": true, + "titleUrl": "/wp-content/uploads/0000/00/image-3840x2160-2-1920x1080.jpeg", + "imageUrl": "/wp-content/uploads/0000/00/image-3840x2160-2-1920x1080.jpeg", + "videoUrl": false + }, + { + "title": "Image Title of 3840 on 2560", + "isPopup": true, + "titleUrl": "/wp-content/uploads/0000/00/image-3840x2560-2-1920x1280.jpeg", + "imageUrl": "/wp-content/uploads/0000/00/image-3840x2560-2-1920x1280.jpeg", + "videoUrl": false + } +] diff --git a/tests/fixtures/click-actions/url-expected-preset.json b/tests/fixtures/click-actions/url-expected-preset.json new file mode 100644 index 00000000..01ed43ef --- /dev/null +++ b/tests/fixtures/click-actions/url-expected-preset.json @@ -0,0 +1,52 @@ +[ + { + "title": "Alternative title of 300 on 200", + "isPopup": false, + "titleUrl": "https://www.youtube.com/watch?v=354pybu91aQ&ab_channel=VisualPortfolio" + }, + { + "title": "Alternative title of 600 on 1920", + "isPopup": false, + "titleUrl": "https://visualportfolio.co/" + }, + { + "title": "Alternative title of 800 on 600", + "isPopup": false, + "titleUrl": "/wp-content/uploads/0000/00/image-800x600-1.png" + }, + { + "title": "Alternative title of 800 on 1200", + "isPopup": false, + "titleUrl": "/?page_id" + }, + { + "title": "Alternative title of 1600 on 1200", + "isPopup": false, + "titleUrl": "/wp-content/uploads/0000/00/image-1600x1200-1.jpeg" + }, + { + "title": "Alternative title of 1920 on 600", + "isPopup": false, + "titleUrl": "https://www.youtube.com/watch?v=354pybu91aQ&ab_channel=VisualPortfolio" + }, + { + "title": "Image Title of 1920 on 1080", + "isPopup": false, + "titleUrl": "/wp-content/uploads/0000/00/image-1920x1080-1.jpeg" + }, + { + "title": "Image Title of 2000 on 2000", + "isPopup": false, + "titleUrl": "/wp-content/uploads/0000/00/image-2000x2000-1-1920x1920.jpeg" + }, + { + "title": "Image Title of 3840 on 2160", + "isPopup": false, + "titleUrl": "/wp-content/uploads/0000/00/image-3840x2160-1-1920x1080.jpeg" + }, + { + "title": "Image Title of 3840 on 2560", + "isPopup": false, + "titleUrl": "/wp-content/uploads/0000/00/image-3840x2560-1-1920x1280.jpeg" + } +] diff --git a/tests/fixtures/image-1600x1200.jpeg b/tests/fixtures/image-1600x1200.jpeg new file mode 100644 index 00000000..05bf6043 Binary files /dev/null and b/tests/fixtures/image-1600x1200.jpeg differ diff --git a/tests/fixtures/image-1920x1080.jpeg b/tests/fixtures/image-1920x1080.jpeg new file mode 100644 index 00000000..51da15e5 Binary files /dev/null and b/tests/fixtures/image-1920x1080.jpeg differ diff --git a/tests/fixtures/image-1920x600.jpeg b/tests/fixtures/image-1920x600.jpeg new file mode 100644 index 00000000..a4200ebc Binary files /dev/null and b/tests/fixtures/image-1920x600.jpeg differ diff --git a/tests/fixtures/image-2000x2000.jpeg b/tests/fixtures/image-2000x2000.jpeg new file mode 100644 index 00000000..da164943 Binary files /dev/null and b/tests/fixtures/image-2000x2000.jpeg differ diff --git a/tests/fixtures/image-300x200.jpeg b/tests/fixtures/image-300x200.jpeg new file mode 100644 index 00000000..2762dcad Binary files /dev/null and b/tests/fixtures/image-300x200.jpeg differ diff --git a/tests/fixtures/image-3840x2160.jpeg b/tests/fixtures/image-3840x2160.jpeg new file mode 100644 index 00000000..7ced34cb Binary files /dev/null and b/tests/fixtures/image-3840x2160.jpeg differ diff --git a/tests/fixtures/image-3840x2560.jpeg b/tests/fixtures/image-3840x2560.jpeg new file mode 100644 index 00000000..7ba7f107 Binary files /dev/null and b/tests/fixtures/image-3840x2560.jpeg differ diff --git a/tests/fixtures/image-600x1920.jpeg b/tests/fixtures/image-600x1920.jpeg new file mode 100644 index 00000000..d88c5f84 Binary files /dev/null and b/tests/fixtures/image-600x1920.jpeg differ diff --git a/tests/fixtures/image-800x1200.jpeg b/tests/fixtures/image-800x1200.jpeg new file mode 100644 index 00000000..2c3145e8 Binary files /dev/null and b/tests/fixtures/image-800x1200.jpeg differ diff --git a/tests/fixtures/image-800x600.png b/tests/fixtures/image-800x600.png new file mode 100644 index 00000000..a69a35f6 Binary files /dev/null and b/tests/fixtures/image-800x600.png differ diff --git a/tests/fixtures/images.json b/tests/fixtures/images.json new file mode 100644 index 00000000..4c65588e --- /dev/null +++ b/tests/fixtures/images.json @@ -0,0 +1,109 @@ +[ + { + "filename": "image-300x200.jpeg", + "alt": "Alt of image 300 on 200", + "caption": "Caption of image 300 on 200", + "description": "Description of image 300 on 200", + "imageSettings": { + "title": "Alternative title of 300 on 200", + "description": "Alternative description of image 300 on 200", + "format": "video", + "videoUrl": "https://www.youtube.com/watch?v=354pybu91aQ&ab_channel=VisualPortfolio" + }, + "postTitle": "Portfolio 1 test post" + }, + { + "filename": "image-600x1920.jpeg", + "alt": "Alt of image 600 on 1920", + "caption": "Caption of image 600 on 1920", + "description": "Description of image 600 on 1920", + "imageSettings": { + "title": "Alternative title of 600 on 1920", + "description": "Alternative description of image 600 on 1920", + "format": "standard", + "url": "https://visualportfolio.co/" + }, + "postTitle": "Portfolio 2 test post" + }, + { + "filename": "image-800x600.png", + "alt": "Alt of image 800 on 600", + "caption": "Caption of image 800 on 600", + "description": "Description of image 800 on 600", + "imageSettings": { + "title": "Alternative title of 800 on 600", + "description": "Alternative description of image 800 on 600", + "format": "standard" + }, + "postTitle": "Portfolio 3 test post" + }, + { + "filename": "image-800x1200.jpeg", + "alt": "Alt of image 800 on 1200", + "caption": "Caption of image 800 on 1200", + "description": "Description of image 800 on 1200", + "imageSettings": { + "title": "Alternative title of 800 on 1200", + "description": "Alternative description of image 800 on 1200", + "format": "standard", + "url": "postLink" + }, + "postTitle": "Portfolio 4 test post" + }, + { + "filename": "image-1600x1200.jpeg", + "alt": "Alt of image 1600 on 1200", + "caption": "Caption of image 1600 on 1200", + "description": "Description of image 1600 on 1200", + "imageSettings": { + "title": "Alternative title of 1600 on 1200", + "description": "Alternative description of image 1600 on 1200" + }, + "postTitle": "Portfolio 5 test post" + }, + { + "filename": "image-1920x600.jpeg", + "alt": "Alt of image 1920 on 600", + "caption": "Caption of image 1920 on 600", + "description": "Description of image 1920 on 600", + "imageSettings": { + "title": "Alternative title of 1920 on 600", + "description": "Alternative description of image 1920 on 600", + "format": "video", + "videoUrl": "https://www.youtube.com/watch?v=354pybu91aQ&ab_channel=VisualPortfolio" + }, + "postTitle": "Portfolio 6 test post" + }, + { + "filename": "image-1920x1080.jpeg", + "alt": "Alt of image 1920 on 1080", + "caption": "Caption of image 1920 on 1080", + "title": "Image Title of 1920 on 1080", + "description": "Description of image 1920 on 1080", + "postTitle": "Portfolio 7 test post" + }, + { + "filename": "image-2000x2000.jpeg", + "alt": "Alt of image 2000 on 2000", + "caption": "Caption of image 2000 on 2000", + "title": "Image Title of 2000 on 2000", + "description": "Description of image 2000 on 2000", + "postTitle": "Portfolio 8 test post" + }, + { + "filename": "image-3840x2160.jpeg", + "alt": "Alt of image 3840 on 2160", + "caption": "Caption of image 3840 on 2160", + "title": "Image Title of 3840 on 2160", + "description": "Description of image 3840 on 2160", + "postTitle": "Portfolio 9 test post" + }, + { + "filename": "image-3840x2560.jpeg", + "alt": "Alt of image 3840 on 2560", + "caption": "Caption of image 3840 on 2560", + "title": "Image Title of 3840 on 2560", + "description": "Description of image 3840 on 2560", + "postTitle": "Portfolio 10 test post" + } +] diff --git a/tests/phpunit/unit/test-class-friendly-urls.php b/tests/phpunit/unit/test-class-friendly-urls.php index c0241dc9..80fe3162 100644 --- a/tests/phpunit/unit/test-class-friendly-urls.php +++ b/tests/phpunit/unit/test-class-friendly-urls.php @@ -53,6 +53,7 @@ public function get_predefined_options() { 'content_source' => 'post-based', 'posts_source' => 'current_query', ); + update_option( 'permalink_structure', '/%postname%/' ); return $block_options; }