Browse Source
Fix "Object of class DateTime could not be converted to int"
Fix "Object of class DateTime could not be converted to int"
Signed-off-by: Joas Schilling <coding@schilljs.com>pull/1134/head
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
2 changed files with 103 additions and 2 deletions
@ -0,0 +1,96 @@ |
|||
<?php |
|||
declare(strict_types=1); |
|||
/** |
|||
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com> |
|||
* |
|||
* @license GNU AGPL version 3 or any later version |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Affero General Public License as |
|||
* published by the Free Software Foundation, either version 3 of the |
|||
* License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Affero General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Affero General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
* |
|||
*/ |
|||
|
|||
namespace OCA\Spreed\Tests\php\Chat; |
|||
|
|||
use OCA\Spreed\Chat\AutoComplete\Sorter; |
|||
use OCA\Spreed\Chat\CommentsManager; |
|||
use PHPUnit\Framework\MockObject\MockObject; |
|||
|
|||
class SorterTest extends \Test\TestCase { |
|||
|
|||
/** @var CommentsManager|MockObject */ |
|||
protected $commentsManager; |
|||
|
|||
/** @var string */ |
|||
protected $userId; |
|||
|
|||
/** @var Sorter */ |
|||
protected $sorter; |
|||
|
|||
protected $user1 = [ |
|||
'label' => 'Seattle', |
|||
'value' => [ |
|||
'shareType' => 'user', |
|||
'shareWith' => 'seattle', |
|||
], |
|||
]; |
|||
|
|||
protected $user2 = [ |
|||
'label' => 'New York', |
|||
'value' => [ |
|||
'shareType' => 'user', |
|||
'shareWith' => 'new_york', |
|||
], |
|||
]; |
|||
|
|||
public function setUp() { |
|||
parent::setUp(); |
|||
|
|||
$this->commentsManager = $this->createMock(CommentsManager::class); |
|||
$this->sorter = new Sorter($this->commentsManager); |
|||
} |
|||
|
|||
public function testGetId() { |
|||
$this->assertSame('talk_chat_participants', $this->sorter->getId()); |
|||
} |
|||
|
|||
public function dataSort(): array { |
|||
return [ |
|||
'no user posted' => [['users' => [$this->user1, $this->user2]], [], ['users' => [$this->user1, $this->user2]]], |
|||
'second user posted' => [['users' => [$this->user1, $this->user2]], ['new_york' => new \DateTime('2000-01-01')], ['users' => [$this->user2, $this->user1]]], |
|||
'second user posted later' => [['users' => [$this->user1, $this->user2]], ['seattle' => new \DateTime('2017-01-01'), 'new_york' => new \DateTime('2018-01-01')], ['users' => [$this->user2, $this->user1]]], |
|||
'second user posted earlier' => [['users' => [$this->user1, $this->user2]], ['seattle' => new \DateTime('2018-01-01'), 'new_york' => new \DateTime('2017-01-01')], ['users' => [$this->user1, $this->user2]]], |
|||
'no users' => [['groups' => [$this->user1, $this->user2]], null, ['groups' => [$this->user1, $this->user2]]], |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* @dataProvider dataSort |
|||
* |
|||
* @param array $toSort |
|||
* @param array $comments |
|||
* @param array $expected |
|||
*/ |
|||
public function testSort($toSort, $comments, $expected) { |
|||
$this->commentsManager->expects(isset($toSort['users']) ? $this->once() : $this->never()) |
|||
->method('getLastCommentDateByActor') |
|||
->with('chat', 23, 'comment', 'users', $this->anything()) |
|||
->willReturn($comments); |
|||
|
|||
$this->sorter->sort($toSort, [ |
|||
'itemType' => 'chat', |
|||
'itemId' => 23, |
|||
]); |
|||
$this->assertSame($expected, $toSort); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue