Skip to content

Commit

Permalink
Merge branch '5.1.x' of github.com:baserproject/basercms into 5.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Jul 1, 2024
2 parents 7f2803a + dc567b9 commit a660aaf
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 73 deletions.
3 changes: 1 addition & 2 deletions plugins/baser-core/src/Service/ThemesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,11 @@ public function add(array $postData): string
}
$name = $postData['file']->getClientFileName();
$postData['file']->moveTo(TMP . $name);
$srcDirName = basename($name, '.zip');
$zip = new BcZip();
if (!$zip->extract(TMP . $name, TMP)) {
throw new BcException(__d('baser_core', 'アップロードしたZIPファイルの展開に失敗しました。'));
}

$srcDirName = $zip->topArchiveName;
$dstName = $srcName = Inflector::camelize($srcDirName);
if (preg_match('/^(.+?)([0-9]+)$/', $srcName, $matches)) {
$baseName = $matches[1];
Expand Down
1 change: 1 addition & 0 deletions plugins/baser-core/src/View/Helper/BcXmlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class BcXmlHelper extends Helper
* @return string XML宣言
* @checked
* @noTodo
* @unitTest
*/
public function header($attrib = [])
{
Expand Down
21 changes: 18 additions & 3 deletions plugins/baser-core/tests/TestCase/View/Helper/BcXmlHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use BaserCore\TestSuite\BcTestCase;
use BaserCore\View\Helper\BcTextHelper;
use BaserCore\View\Helper\BcXmlHelper;
use Cake\View\View;

/**
* text helper library.
Expand All @@ -26,8 +28,7 @@ class BcXmlHelperTest extends BcTestCase
public function setUp(): void
{
parent::setUp();
// $View = new View();
// $this->BcXml = new BcXmlHelper($View);
$this->BcXml = new BcXmlHelper(new View());
}

/**
Expand All @@ -52,7 +53,6 @@ public function tearDown(): void
*/
public function testHeader($attrib, $agent, $expected)
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
$_SERVER['HTTP_USER_AGENT'] = $agent;

$result = $this->BcXml->header($attrib);
Expand Down Expand Up @@ -82,6 +82,21 @@ public static function headerDataProvider()
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1',
'<?xml version="1.0" encoding="SJIS" ?>'
],
[
'xml-stylesheet',
'Mozilla/5.0',
'<?xml-stylesheet ?>'
],
[
'stylesheet',
'Mozilla/5.0',
'<?xml stylesheet ?>'
],
[
[],
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
''
]
];
}

Expand Down
8 changes: 4 additions & 4 deletions plugins/bc-blog/src/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function index(
*
* ### URL例
* - カテゴリ別記事一覧: /news/archives/category/category-name
* - 作成者別記事一覧: /news/archives/author/author-name
* - 作成者別記事一覧: /news/archives/author/user-id
* - タグ別記事一覧: /news/archives/tag/tag-name
* - 年別記事一覧: /news/archives/date/2022
* - 月別記事一覧: /news/archives/date/2022/12
Expand Down Expand Up @@ -198,15 +198,15 @@ public function archives(

case 'author':
if (count($pass) > 2) $this->notFound();
$author = isset($pass[1])? $pass[1] : '';
$userId = isset($pass[1]) ? (int) $pass[1] : '';
$this->set($service->getViewVarsForArchivesByAuthor(
$this->paginate($blogPostsService->getIndexByAuthor($author, array_merge([
$this->paginate($blogPostsService->getIndexByAuthor($userId, array_merge([
'status' => 'publish',
'blog_content_id' => $blogContent->id,
'direction' => $blogContent->list_direction,
'draft' => false
], $this->getRequest()->getQueryParams())), ['limit' => $blogContent->list_count]),
$author,
$userId,
$blogContent
));
break;
Expand Down
28 changes: 3 additions & 25 deletions plugins/bc-blog/src/Service/BlogPostsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ protected function createIndexConditions(Query $query, array $params)
'site_id' => null,
'category' => null,
'keyword' => null,
'author' => null,
'tag' => null,
'year' => null,
'month' => null,
Expand Down Expand Up @@ -342,10 +341,6 @@ protected function createIndexConditions(Query $query, array $params)
if ($params['keyword']) {
$conditions = $this->createKeywordCondition($conditions, $params['keyword']);
}
// 作成者
if ($params['author']) {
$conditions = $this->createAuthorCondition($conditions, $params['author']);
}
return $query->where($conditions);
}

Expand Down Expand Up @@ -538,23 +533,6 @@ public function createYearMonthDayCondition($conditions, $year, $month, $day)
return $conditions;
}

/**
* 作成者の条件を作成する
*
* @param array $conditions
* @param string $author
* @return array
* @checked
* @noTodo
* @unitTest
*/
public function createAuthorCondition($conditions, $author)
{
$user = $this->BlogPosts->Users->find()->where(['Users.name' => $author])->first();
$conditions['BlogPosts.user_id'] = $user->id;
return $conditions;
}

/**
* 初期データ用のエンティティを取得
*
Expand Down Expand Up @@ -809,16 +787,16 @@ public function getIndexByCategory($category, array $options = [])
/**
* 著者別記事一覧を取得
*
* @param string $author
* @param int $userId
* @param array $options
* @return Query
* @checked
* @noTodo
* @unitTest
*/
public function getIndexByAuthor(string $author, array $options = [])
public function getIndexByAuthor(int $userId, array $options = [])
{
$options['author'] = $author;
$options['user_id'] = $userId;
return $this->getIndex($options);
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/bc-blog/src/Service/BlogPostsServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ public function getIndexByCategory($category, array $options = []);
/**
* 著者別記事一覧を取得
*
* @param string $author
* @param int $userId
* @param array $options
* @return Query
* @checked
* @noTodo
* @unitTest
*/
public function getIndexByAuthor(string $author, array $options = []);
public function getIndexByAuthor(int $userId, array $options = []);

/**
* タグ別記事一覧を取得
Expand Down
6 changes: 3 additions & 3 deletions plugins/bc-blog/src/Service/Front/BlogFrontService.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@ public function getCategoryCrumbs(string $baseUrl, int $categoryId, $isCategoryP
/**
* 著者別アーカイブ一覧の view 用変数を取得する
* @param ResultSet|PaginatedResultSet $posts
* @param string $author
* @param int $userId
* @param BlogContent $blogContent
* @return array
* @checked
* @noTodo
* @unitTest
*/
public function getViewVarsForArchivesByAuthor(ResultSet|PaginatedResultSet $posts, string $author, BlogContent $blogContent): array
public function getViewVarsForArchivesByAuthor(ResultSet|PaginatedResultSet $posts, int $userId, BlogContent $blogContent): array
{
$usersTable = TableRegistry::getTableLocator()->get('BaserCore.Users');
$author = $usersTable->find('available')->where(['Users.name' => $author])->first();
$author = $usersTable->find('available')->where(['Users.id' => $userId])->first();
if (!$author) {
throw new NotFoundException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ public function getCategoryCrumbs(string $baseUrl, int $categoryId, $isCategoryP

/**
* 著者別アーカイブ一覧の view 用変数を取得する
* @param ResultSet $posts
* @param string $author
* @param ResultSet|PaginatedResultSet $posts
* @param int $userId
* @return array
* @checked
* @noTodo
* @unitTest
*/
public function getViewVarsForArchivesByAuthor(ResultSet $posts, string $author, BlogContent $blogContent): array;
public function getViewVarsForArchivesByAuthor(ResultSet|PaginatedResultSet $posts, int $userId, BlogContent $blogContent): array;

/**
* タグ別アーカイブ一覧の view 用変数を取得する
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function test_archives()
$this->assertEquals('release', $vars['blogCategory']->name);
$this->assertEquals('post1', $vars['posts']->toArray()[0]->name);
//type = 'author'
$this->get('/news/archives/author/name');
$this->get('/news/archives/author/1');
$this->assertResponseOk();
$vars = $this->_controller->viewBuilder()->getVars();
$this->assertEquals('author', $vars['blogArchiveType']);
Expand Down
16 changes: 2 additions & 14 deletions plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,6 @@ public function testCreateYearMonthDayCondition()
$this->assertEquals("01", $result['DAY(BlogPosts.posted)']);
}

/**
* 作成者の条件を作成する
*/
public function testCreateAuthorCondition()
{
//データ 生成
UserFactory::make(['id' => 1, 'name' => 'test name', 'email' => '[email protected]'])->persist();
//戻り値を確認
$result = $this->BlogPostsService->createAuthorCondition([], "test name");
$this->assertEquals($result["BlogPosts.user_id"], 1);
}

/**
* 並び替え設定を生成する
*/
Expand Down Expand Up @@ -965,7 +953,7 @@ public function testGetIndexByAuthor()

// サービスメソッドを呼ぶ
// test author1 の記事を取得、id昇順
$result = $this->BlogPostsService->getIndexByAuthor('test author1', [
$result = $this->BlogPostsService->getIndexByAuthor(2, [
'direction' => 'ASC',
'order' => 'id',
]);
Expand All @@ -984,7 +972,7 @@ public function testGetIndexByAuthor()

// サービスメソッドを呼ぶ
// 記事が存在しない
$result = $this->BlogPostsService->getIndexByAuthor('test author3', []);
$result = $this->BlogPostsService->getIndexByAuthor(4, []);

// 戻り値を確認
// 指定した author の記事が存在しない
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public function test_getViewVarsForArchivesByAuthor()
// サービスメソッドを呼ぶ
$result = $this->BlogFrontService->getViewVarsForArchivesByAuthor(
$blogPostsService->getIndex([])->all(),
'name',
1,
$blogContentsService->get(1)
);

Expand All @@ -533,7 +533,7 @@ public function test_getViewVarsForArchivesByAuthor()
$this->expectException("Cake\Http\Exception\NotFoundException");
$this->BlogFrontService->getViewVarsForArchivesByAuthor(
$blogPostsService->getIndex([])->all(),
'author name test',
999,
$blogContentsService->get(1)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<?php foreach ($authors as $author): ?>
<?php
$class = ['bs-widget-list__item'];
if ($this->getRequest()->getPath() === $baseCurrentUrl . $author->name) {
if ($this->getRequest()->getPath() === $baseCurrentUrl . $author->id) {
$class[] = 'current';
}
if ($view_count) {
Expand All @@ -57,14 +57,10 @@
}
?>
<li class="<?php echo implode(' ', $class) ?>">
<?php if($author->name): ?>
<?php $this->BcBaser->link($title, $baseCurrentUrl . $author->name, [
'escape' => true,
'class' => 'bs-widget-list__item-title'
]) ?>
<?php else: ?>
<?php echo $title ?>
<?php endif ?>
<?php $this->BcBaser->link($title, $baseCurrentUrl . $author->id, [
'escape' => true,
'class' => 'bs-widget-list__item-title'
]) ?>
</li>
<?php endforeach; ?>
</ul>
Expand Down
4 changes: 4 additions & 0 deletions plugins/bc-uploader/src/View/Helper/UploaderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class UploaderHelper extends Helper
* @return void
* @checked
* @noTodo
* @unitTest
*/
public function beforeRender(Event $event, $viewFile)
{
Expand All @@ -66,6 +67,7 @@ public function beforeRender(Event $event, $viewFile)
* @return string imgタグ
* @checked
* @noTodo
* @unitTest
*/
public function file(UploaderFile $uploaderFile, array $options = [])
{
Expand Down Expand Up @@ -121,6 +123,7 @@ public function getFileUrl($fileName)
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function download(UploaderFile $uploaderFile, $linkText = '≫ ダウンロード')
{
Expand All @@ -135,6 +138,7 @@ public function download(UploaderFile $uploaderFile, $linkText = '≫ ダウン
* @param array $data
* @return bool
* @checked
* @unitTest
*/
public function isLimitSetting($data)
{
Expand Down
Loading

0 comments on commit a660aaf

Please sign in to comment.