From 5446c18d953473f6230f269bdfd7227c42e4963e Mon Sep 17 00:00:00 2001 From: core23 Date: Sun, 15 Jan 2017 11:28:45 +0100 Subject: [PATCH] Check for empty seo title when setting a default one --- Page/Service/DefaultPageService.php | 2 +- Tests/Page/Service/DefaultPageServiceTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Page/Service/DefaultPageService.php b/Page/Service/DefaultPageService.php index 6619b292a..35759a023 100644 --- a/Page/Service/DefaultPageService.php +++ b/Page/Service/DefaultPageService.php @@ -73,7 +73,7 @@ protected function updateSeoPage(PageInterface $page) return; } - if ($page->getTitle()) { + if (!$this->seoPage->getTitle()) { $this->seoPage->setTitle($page->getTitle() ?: $page->getName()); } diff --git a/Tests/Page/Service/DefaultPageServiceTest.php b/Tests/Page/Service/DefaultPageServiceTest.php index 978cc8d2b..cd7d7beca 100644 --- a/Tests/Page/Service/DefaultPageServiceTest.php +++ b/Tests/Page/Service/DefaultPageServiceTest.php @@ -60,7 +60,8 @@ public function testExecute() // mock a page instance $page = $this->getMock('Sonata\PageBundle\Model\PageInterface'); - $page->expects($this->exactly(2))->method('getTitle')->will($this->returnValue('page title')); + $this->seoPage->expects($this->once())->method('getTitle')->will($this->returnValue(null)); + $page->expects($this->once())->method('getTitle')->will($this->returnValue('page title')); $page->expects($this->atLeastOnce())->method('getMetaDescription')->will($this->returnValue('page meta description')); $page->expects($this->atLeastOnce())->method('getMetaKeyword')->will($this->returnValue('page meta keywords')); $page->expects($this->once())->method('getTemplateCode')->will($this->returnValue('template code'));