File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
55and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
66
7+ ## [ 0.6.8] - 2020-03-11
8+ ### Fixed
9+ - Fix issue #84 where WordPress only uses the last part of a URL slug to match pages in WordPress. Frontend now validates
10+ the full page URL when returning content.
11+
712## [ 0.6.7] - 2020-02-28
813### Fixed
914- Fix issue #82 with WordPress returning multiple page when get page by slug
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ Framework to build an efficient front-end website with content from a Headless C
77[ ![ Build Status] ( https://travis-ci.org/studio24/frontend.svg?branch=master )] ( https://travis-ci.org/studio24/frontend )
88[ ![ version] [ version-badge ]] [ CHANGELOG ] [ ![ license] [ license-badge ]] [ LICENSE ]
99
10- [ version-badge ] : https://img.shields.io/badge/version-0.6.5 -blue.svg
10+ [ version-badge ] : https://img.shields.io/badge/version-0.6.8 -blue.svg
1111
1212## Status
1313
Original file line number Diff line number Diff line change @@ -271,8 +271,12 @@ public function getPageByUrl(string $url)
271271 $ data = null ;
272272
273273 if ($ results ->getPagination ()->getTotalResults () === 1 ) {
274- $ data = $ results ->getResponseData ()[0 ];
274+ $ item = $ results ->getResponseData ()[0 ];
275275
276+ $ pageUrlParts = parse_url ($ item ['link ' ]);
277+ if (rtrim ($ pageUrlParts ['path ' ], '/ ' ) === rtrim ($ parts ['path ' ], '/ ' )) {
278+ $ data = $ item ;
279+ }
276280 } else {
277281 // WP may return multiple results since does a LIKE search on slug on API request
278282 foreach ($ results ->getResponseData () as $ item ) {
Original file line number Diff line number Diff line change @@ -432,8 +432,7 @@ public function testFlexibleContent()
432432 }
433433 }
434434
435-
436- public function testInvalidPageUrl ()
435+ protected function initPageUrlTest (): Wordpress
437436 {
438437 // Create a mock and queue two responses
439438 $ mock = new MockHandler ([
@@ -463,14 +462,30 @@ public function testInvalidPageUrl()
463462 $ api ->setContentModel ($ contentModel );
464463 $ api ->setContentType ('news ' );
465464
465+ return $ api ;
466+ }
467+
468+ public function testInvalidPageUrl1 ()
469+ {
470+ $ api = $ this ->initPageUrlTest ();
471+
466472 // Test it!
467- $ this -> expectExceptionCode ( 400 );
468- $ page = $ api -> getPageByUrl ( ' /made/up/hello-world/ ' );
473+ $ page = $ api -> getPageByUrl ( ' /2017/05/23/hello-world/ ' );
474+ $ this -> assertEquals ( " Hello world! " , $ page -> getTitle () );
469475
470- $ this ->expectExceptionCode ( 404 );
476+ $ this ->expectException (NotFoundException::class );
471477 $ page = $ api ->getPageByUrl ('/made/up/url/ ' );
472478 }
473479
480+ public function testSimilarPageUrl ()
481+ {
482+ $ api = $ this ->initPageUrlTest ();
483+
484+ // Test it!
485+ $ this ->expectException (NotFoundException::class);
486+ $ page = $ api ->getPageByUrl ('/made-up/folders/hello-world/ ' );
487+ }
488+
474489 public function testMissingPageImageAuthorTaxonomy ()
475490 {
476491 $ mock = new MockHandler ([
You can’t perform that action at this time.
0 commit comments