forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '5.0' into 5.0.4-to-5.x
- Loading branch information
Showing
23 changed files
with
572 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
app/bundles/LeadBundle/Tests/Functional/Controller/CompanyControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Mautic\LeadBundle\Tests\Functional\Controller; | ||
|
||
use Mautic\CoreBundle\Test\MauticMysqlTestCase; | ||
use Mautic\UserBundle\Entity\Role; | ||
use Mautic\UserBundle\Entity\User; | ||
|
||
class CompanyControllerTest extends MauticMysqlTestCase | ||
{ | ||
public const USERNAME = 'jhony'; | ||
|
||
public function testMergeAction(): void | ||
{ | ||
$this->client->request('GET', '/s/companies/merge/1'); | ||
$clientResponse = $this->client->getResponse(); | ||
$this->assertEquals(200, $clientResponse->getStatusCode()); | ||
} | ||
|
||
public function testMergeActionWithoutPermission(): void | ||
{ | ||
$this->createAndLoginUser(); | ||
$this->client->request('GET', '/s/companies/merge/1'); | ||
$clientResponse = $this->client->getResponse(); | ||
$this->assertEquals(403, $clientResponse->getStatusCode()); | ||
} | ||
|
||
private function createAndLoginUser(): User | ||
{ | ||
// Create non-admin role | ||
$role = $this->createRole(); | ||
// Create non-admin user | ||
$user = $this->createUser($role); | ||
|
||
$this->em->flush(); | ||
$this->em->detach($role); | ||
|
||
$this->loginUser(self::USERNAME); | ||
$this->client->setServerParameter('PHP_AUTH_USER', self::USERNAME); | ||
$this->client->setServerParameter('PHP_AUTH_PW', 'mautic'); | ||
|
||
return $user; | ||
} | ||
|
||
private function createRole(bool $isAdmin = false): Role | ||
{ | ||
$role = new Role(); | ||
$role->setName('Role'); | ||
$role->setIsAdmin($isAdmin); | ||
|
||
$this->em->persist($role); | ||
|
||
return $role; | ||
} | ||
|
||
private function createUser(Role $role): User | ||
{ | ||
$user = new User(); | ||
$user->setFirstName('Jhony'); | ||
$user->setLastName('Doe'); | ||
$user->setUsername(self::USERNAME); | ||
$user->setEmail('[email protected]'); | ||
$encoder = self::$container->get('security.encoder_factory')->getEncoder($user); | ||
$user->setPassword($encoder->encodePassword('mautic', null)); | ||
$user->setRole($role); | ||
|
||
$this->em->persist($user); | ||
|
||
return $user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,15 @@ | |
use Mautic\LeadBundle\Command\ContactScheduledExportCommand; | ||
use Mautic\LeadBundle\Entity\ContactExportScheduler; | ||
use Mautic\LeadBundle\Entity\Lead; | ||
use Mautic\UserBundle\Entity\Role; | ||
use Mautic\UserBundle\Entity\User; | ||
use PHPUnit\Framework\Assert; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
class LeadControllerTest extends MauticMysqlTestCase | ||
{ | ||
public const USERNAME = 'jhony'; | ||
/** | ||
* @var array<string> | ||
*/ | ||
|
@@ -101,4 +104,83 @@ private function checkContactExportScheduler(int $count): array | |
|
||
return $allRows; | ||
} | ||
|
||
public function testAccessContactQuickAddWithPermission(): void | ||
{ | ||
$this->setAdminUser(); | ||
$this->client->request(Request::METHOD_GET, '/s/contacts/quickAdd'); | ||
$this->assertResponseStatusCodeSame(200, (string) $this->client->getResponse()->getStatusCode()); | ||
} | ||
|
||
private function setAdminUser(): void | ||
{ | ||
$this->loginUser('admin'); | ||
$this->client->setServerParameter('PHP_AUTH_USER', 'admin'); | ||
$this->client->setServerParameter('PHP_AUTH_PW', 'mautic'); | ||
} | ||
|
||
public function testAccessContactQuickAddWithNoPermission(): void | ||
{ | ||
$this->createAndLoginUser(); | ||
$this->client->request(Request::METHOD_GET, '/s/contacts/quickAdd'); | ||
$this->assertResponseStatusCodeSame(403, (string) $this->client->getResponse()->getStatusCode()); | ||
} | ||
|
||
public function testAccessContactBatchOwnersNoPermission(): void | ||
{ | ||
$this->createAndLoginUser(); | ||
$this->client->request(Request::METHOD_GET, '/s/contacts/batchOwners'); | ||
$this->assertResponseStatusCodeSame(403, (string) $this->client->getResponse()->getStatusCode()); | ||
} | ||
|
||
public function testAccessContactBatchOwnersPermission(): void | ||
{ | ||
$this->setAdminUser(); | ||
$this->client->request(Request::METHOD_GET, '/s/contacts/batchOwners'); | ||
$this->assertResponseStatusCodeSame(200, (string) $this->client->getResponse()->getStatusCode()); | ||
} | ||
|
||
private function createAndLoginUser(): User | ||
{ | ||
// Create non-admin role | ||
$role = $this->createRole(); | ||
// Create non-admin user | ||
$user = $this->createUser($role); | ||
|
||
$this->em->flush(); | ||
$this->em->detach($role); | ||
|
||
$this->loginUser(self::USERNAME); | ||
$this->client->setServerParameter('PHP_AUTH_USER', self::USERNAME); | ||
$this->client->setServerParameter('PHP_AUTH_PW', 'mautic'); | ||
|
||
return $user; | ||
} | ||
|
||
private function createRole(bool $isAdmin = false): Role | ||
{ | ||
$role = new Role(); | ||
$role->setName('Role'); | ||
$role->setIsAdmin($isAdmin); | ||
|
||
$this->em->persist($role); | ||
|
||
return $role; | ||
} | ||
|
||
private function createUser(Role $role): User | ||
{ | ||
$user = new User(); | ||
$user->setFirstName('Jhony'); | ||
$user->setLastName('Doe'); | ||
$user->setUsername(self::USERNAME); | ||
$user->setEmail('[email protected]'); | ||
$encoder = self::$container->get('security.encoder_factory')->getEncoder($user); | ||
$user->setPassword($encoder->encodePassword('mautic', null)); | ||
$user->setRole($role); | ||
|
||
$this->em->persist($user); | ||
|
||
return $user; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.