Skip to content

Commit

Permalink
Merge branch 'patch-1' of https://github.com/onurkose/framework into …
Browse files Browse the repository at this point in the history
…onurkose-patch-1
  • Loading branch information
taylorotwell committed Feb 24, 2020
2 parents a05b9dc + 0d144a3 commit 520188c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public function isGuardedChannel($channel)
*/
public function normalizeChannelName($channel)
{
if ($this->isGuardedChannel($channel)) {
return Str::startsWith($channel, 'private-')
? Str::replaceFirst('private-', '', $channel)
: Str::replaceFirst('presence-', '', $channel);
foreach (['private-encrypted-', 'private-', 'presence-'] as $prefix) {
if (Str::startsWith($channel, $prefix)) {
return Str::replaceFirst($prefix, '', $channel);
}
}

return $channel;
Expand Down
17 changes: 17 additions & 0 deletions src/Illuminate/Broadcasting/PrivateEncryptedChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Illuminate\Broadcasting;

class PrivateEncryptedChannel extends Channel
{
/**
* Create a new channel instance.
*
* @param string $name
* @return void
*/
public function __construct($name)
{
parent::__construct('private-encrypted-'.$name);
}
}
37 changes: 17 additions & 20 deletions tests/Broadcasting/UsePusherChannelsNamesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,30 @@

use Illuminate\Broadcasting\Broadcasters\Broadcaster;
use Illuminate\Broadcasting\Broadcasters\UsePusherChannelConventions;
use Mockery as m;
use PHPUnit\Framework\TestCase;

class UsePusherChannelConventionsTest extends TestCase
{
/**
* @var \Illuminate\Broadcasting\Broadcasters\RedisBroadcaster
* @dataProvider channelsProvider
*/
public $broadcaster;

protected function setUp(): void
public function testChannelNameNormalization($requestChannelName, $normalizedName)
{
parent::setUp();
$broadcaster = new FakeBroadcasterUsingPusherChannelsNames();

$this->broadcaster = new FakeBroadcasterUsingPusherChannelsNames();
$this->assertSame(
$normalizedName,
$broadcaster->normalizeChannelName($requestChannelName)
);
}

protected function tearDown(): void
public function testChannelNameNormalizationSpecialCase()
{
m::close();
}
$broadcaster = new FakeBroadcasterUsingPusherChannelsNames();

/**
* @dataProvider channelsProvider
*/
public function testChannelNameNormalization($requestChannelName, $normalizedName)
{
$this->assertEquals(
$normalizedName,
$this->broadcaster->normalizeChannelName($requestChannelName)
$this->assertSame(
'private-123',
$broadcaster->normalizeChannelName('private-encrypted-private-123')
);
}

Expand All @@ -42,16 +36,19 @@ public function testChannelNameNormalization($requestChannelName, $normalizedNam
*/
public function testIsGuardedChannel($requestChannelName, $_, $guarded)
{
$this->assertEquals(
$broadcaster = new FakeBroadcasterUsingPusherChannelsNames();

$this->assertSame(
$guarded,
$this->broadcaster->isGuardedChannel($requestChannelName)
$broadcaster->isGuardedChannel($requestChannelName)
);
}

public function channelsProvider()
{
$prefixesInfos = [
['prefix' => 'private-', 'guarded' => true],
['prefix' => 'private-encrypted-', 'guarded' => true],
['prefix' => 'presence-', 'guarded' => true],
['prefix' => '', 'guarded' => false],
];
Expand Down

0 comments on commit 520188c

Please sign in to comment.