mirror of
https://github.com/e107inc/e107.git
synced 2025-08-09 08:06:38 +02:00
Merge pull request #4984 from Deltik/hotfix/4982
news: Fix category link in both breadcrumb and menu
This commit is contained in:
@@ -129,13 +129,13 @@ class core_news_url extends eUrlConfig
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
if(!vartrue($params['id']))
|
||||
if(!vartrue($params['category_id']))
|
||||
{
|
||||
$url .= 'default.0.'.$page;
|
||||
}
|
||||
else
|
||||
{
|
||||
$url .= 'list.'.$params['id'].'.'.$page; // 'category_id' would break news_categories_menu.
|
||||
$url .= 'list.'.$params['category_id'].'.'.$page;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@@ -999,7 +999,7 @@ class e_news_category_item extends e_front_model
|
||||
public function sc_news_category_url($parm = '')
|
||||
{
|
||||
|
||||
$url = e107::getUrl()->create('news/list/category', array('id' => $this->getId(), 'name' => $this->cat('sef')));
|
||||
$url = e107::getUrl()->create('news/list/category', array($this->getFieldIdName() => $this->getId(), 'name' => $this->cat('sef')));
|
||||
switch($parm)
|
||||
{
|
||||
case 'link':
|
||||
|
@@ -107,7 +107,7 @@ class news_front
|
||||
|
||||
$itemName = e107::getParser()->toHTML($this->currentRow['news_title'],true, 'TITLE');
|
||||
|
||||
$breadcrumb[] = array('text'=> $categoryName, 'url'=>e107::getUrl()->create('news/list/category', array('id'=>$this->currentRow['news_category'])));
|
||||
$breadcrumb[] = array('text'=> $categoryName, 'url'=>e107::getUrl()->create('news/list/category', $this->currentRow));
|
||||
$breadcrumb[] = array('text'=> $itemName, 'url'=> null);
|
||||
break;
|
||||
|
||||
|
124
e107_tests/tests/unit/plugins/news/PluginNewsTest.php
Normal file
124
e107_tests/tests/unit/plugins/news/PluginNewsTest.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
|
||||
class PluginNewsTest extends \Codeception\Test\Unit
|
||||
{
|
||||
|
||||
/**
|
||||
* @see https://github.com/e107inc/e107/issues/4982
|
||||
*/
|
||||
public function testCategoryListDefaultSef()
|
||||
{
|
||||
include_once "e107_core/url/news/url.php";
|
||||
$eUrlConfig = new core_news_url();
|
||||
$output = $eUrlConfig->create(
|
||||
["list", "category"],
|
||||
["category_id" => 579773, "name" => "regression"],
|
||||
["full" => false, "amp" => "&", "equal" => "=", "encode" => true, "lan" => null]);
|
||||
$this->assertEquals("news.php?list.579773.0", $output);
|
||||
}
|
||||
|
||||
public function testNewsFrontCategoryUrl()
|
||||
{
|
||||
$payload = $this->simulateShowNewsItem();
|
||||
$this->testNewsFrontCategoryUrlSef(
|
||||
$payload,
|
||||
"core",
|
||||
"/news.php?list.{$payload['category_id']}.0"
|
||||
);
|
||||
}
|
||||
|
||||
public function testNewsFrontCategoryUrlCoreSef()
|
||||
{
|
||||
$payload = $this->simulateShowNewsItem();
|
||||
$this->testNewsFrontCategoryUrlSef(
|
||||
$payload,
|
||||
"core/sef",
|
||||
"/news/category/{$payload['category_id']}/{$payload['category_sef']}"
|
||||
);
|
||||
}
|
||||
|
||||
public function testNewsFrontCategoryUrlCoreSefFull()
|
||||
{
|
||||
$payload = $this->simulateShowNewsItem();
|
||||
$this->testNewsFrontCategoryUrlSef(
|
||||
$payload,
|
||||
"core/sef_full",
|
||||
"/news/category/{$payload['category_sef']}"
|
||||
);
|
||||
}
|
||||
|
||||
public function testNewsFrontCategoryUrlCoreSefNoid()
|
||||
{
|
||||
$payload = $this->simulateShowNewsItem();
|
||||
$this->testNewsFrontCategoryUrlSef(
|
||||
$payload,
|
||||
"core/sef_noid",
|
||||
"/news/category/{$payload['category_sef']}.html"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $payload array
|
||||
* @param $sefType string
|
||||
* @param $expected string
|
||||
* @return void
|
||||
*/
|
||||
private function testNewsFrontCategoryUrlSef($payload, $sefType, $expected)
|
||||
{
|
||||
$urlConfig = $oldUrlConfig = e107::getConfig()->get('url_config', array());
|
||||
$urlConfig["news"] = $sefType;
|
||||
e107::getConfig()->set('url_config', $urlConfig);
|
||||
$router = new eRouter();
|
||||
$router->loadConfig(true);
|
||||
$oldRouter = e107::getUrl()->front()->getRouter();
|
||||
try
|
||||
{
|
||||
e107::getUrl()->front()->setRouter($router);
|
||||
$output = e107::getUrl()->create('news/list/category', $payload);
|
||||
$this->assertEquals($expected, $output);
|
||||
}
|
||||
finally
|
||||
{
|
||||
e107::getUrl()->front()->setRouter($oldRouter);
|
||||
e107::getConfig()->set('url_config', $oldUrlConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function simulateShowNewsItem()
|
||||
{
|
||||
$rowCount = e107::getDb()->select("news", "news_id");
|
||||
$this->assertGreaterThanOrEqual(
|
||||
1,
|
||||
$rowCount,
|
||||
"This integration test requires at least one news item in the database"
|
||||
);
|
||||
$rows = e107::getDb()->rows();
|
||||
include_once e_PLUGIN . "news/news.php";
|
||||
$news = new news_front();
|
||||
|
||||
$reflection = new ReflectionClass($news);
|
||||
$property = $reflection->getProperty("subAction");
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($news, current($rows)["news_id"]);
|
||||
|
||||
$method = $reflection->getMethod("renderViewTemplate");
|
||||
$method->setAccessible(true);
|
||||
try
|
||||
{
|
||||
$method->invoke($news);
|
||||
}
|
||||
catch(ReflectionException $e)
|
||||
{
|
||||
$this->fail("ReflectionException: " . $e->getMessage());
|
||||
}
|
||||
|
||||
$property = $reflection->getProperty("currentRow");
|
||||
$property->setAccessible(true);
|
||||
|
||||
return $property->getValue($news);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user