Initial commit: CloudOps infrastructure platform

This commit is contained in:
root
2026-04-09 19:58:57 +02:00
commit 1166a52f26
7762 changed files with 839452 additions and 0 deletions

View File

@@ -0,0 +1,103 @@
<?php
namespace MauticPlugin\MauticSocialBundle\Tests\Functional\Controller;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\UserBundle\Entity\Role;
use Mautic\UserBundle\Entity\User;
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
class MonitoringControllerTest extends MauticMysqlTestCase
{
public const USERNAME = 'jhony';
public function testIndex(): void
{
$this->client->request('GET', '/s/monitoring');
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function testNew(): void
{
$this->client->request('GET', '/s/monitoring/new');
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function testEdit(): void
{
$this->client->request('GET', '/s/monitoring/edit/1');
$response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
}
public function testIndexWithoutPermission(): void
{
$this->createAndLoginUser();
$this->client->request('GET', '/s/monitoring');
$response = $this->client->getResponse();
$this->assertEquals(403, $response->getStatusCode());
}
public function testNewWithoutPermission(): void
{
$this->createAndLoginUser();
$this->client->request('GET', '/s/monitoring/new');
$response = $this->client->getResponse();
$this->assertEquals(403, $response->getStatusCode());
}
public function testEditWithoutPermission(): void
{
$this->createAndLoginUser();
$this->client->request('GET', '/s/monitoring/edit/1');
$response = $this->client->getResponse();
$this->assertEquals(403, $response->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($user);
$this->client->setServerParameter('PHP_AUTH_USER', self::USERNAME);
$this->client->setServerParameter('PHP_AUTH_PW', 'Maut1cR0cks!');
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('John');
$user->setLastName('Doe');
$user->setUsername(self::USERNAME);
$user->setEmail('john.doe@email.com');
$hasher = self::getContainer()->get('security.password_hasher_factory')->getPasswordHasher($user);
\assert($hasher instanceof PasswordHasherInterface);
$user->setPassword($hasher->hash('Maut1cR0cks!'));
$user->setRole($role);
$this->em->persist($user);
return $user;
}
}

View File

@@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MauticSocialBundle\Tests\Functional\Controller;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use MauticPlugin\MauticSocialBundle\Entity\Tweet;
use MauticPlugin\MauticSocialBundle\Entity\TweetRepository;
use MauticPlugin\MauticSocialBundle\Model\TweetModel;
use Symfony\Component\HttpFoundation\Request;
class TweetControllerTest extends MauticMysqlTestCase
{
private TweetRepository $tweetsRepo;
protected function setUp(): void
{
parent::setUp();
/** @var TweetModel $tweetsModel */
$tweetsModel = static::getContainer()->get('mautic.social.model.tweet');
$this->tweetsRepo = $tweetsModel->getRepository();
$tweet = new Tweet();
$tweet->setName('Tweet One')
->setText('Tweet One');
$tweetsModel->saveEntity($tweet);
}
public function testTweetListPage(): void
{
$this->client->request(Request::METHOD_GET, '/s/tweets');
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertStringContainsString('Tweet One', $response->getContent());
}
public function testCreateTweet(): void
{
$crawler = $this->client->request(Request::METHOD_GET, '/s/tweets/new');
$saveButton = $crawler->selectButton('Save & Close');
$form = $saveButton->form();
$name = 'The first tweet';
$form['twitter_tweet[name]']->setValue($name);
$form['twitter_tweet[text]']->setValue('Here is the first tweet');
$crawler = $this->client->submit($form);
$response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertSame(1, $this->tweetsRepo->count(['name' => $name]));
}
public function testEditAction(): void
{
$tweet = $this->tweetsRepo->findOneBy([]);
$crawler = $this->client->request('GET', '/s/tweets/edit/'.$tweet->getId());
$clientResponse = $this->client->getResponse();
$clientResponseContent = $clientResponse->getContent();
$this->assertTrue($clientResponse->isOk(), 'Return code must be 200.');
$this->assertStringContainsString('Edit tweet '.$tweet->getName(), $clientResponseContent, 'The return must contain \'Edit tweet\' text');
$form = $crawler->selectButton('Save & Close')->form();
$form['twitter_tweet[name]']->setValue('Updated tweet name');
$this->client->submit($form);
$this->assertSame(1, $this->tweetsRepo->count(['name' => 'Updated tweet name']));
}
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MauticSocialBundle\Tests\Functional;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use PHPUnit\Framework\Assert;
class SocialCommandsTest extends MauticMysqlTestCase
{
public function testSocialMonitoringCommand(): void
{
$commandTester = $this->testSymfonyCommand('mautic:social:monitoring');
Assert::assertSame(0, $commandTester->getStatusCode());
Assert::assertSame("No published monitors found. Make sure the id you supplied is published\n", $commandTester->getDisplay());
}
public function testTwitterHashtagsCommand(): void
{
$commandTester = $this->testSymfonyCommand('social:monitor:twitter:hashtags');
Assert::assertSame(1, $commandTester->getStatusCode());
Assert::assertSame("Twitter plugin not published!\n", $commandTester->getDisplay());
}
public function testTwitterMentionsCommand(): void
{
$commandTester = $this->testSymfonyCommand('social:monitor:twitter:mentions');
Assert::assertSame(1, $commandTester->getStatusCode());
Assert::assertSame("Twitter plugin not published!\n", $commandTester->getDisplay());
}
}

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MauticSocialBundle\Tests\Functional;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\PluginBundle\Entity\Integration;
use Mautic\PluginBundle\Entity\Plugin;
use PHPUnit\Framework\Assert;
class SocialMonitoringFunctionalTest extends MauticMysqlTestCase
{
public function testHideSocialMonitoring(): void
{
$crawler = $this->client->request('GET', '/s/config/edit');
Assert::assertStringNotContainsString('Social Settings', $crawler->filter('.list-group-tabs')->text());
Assert::assertStringNotContainsString('Social Monitoring', $crawler->filter('.sidebar-left .sidebar-content')->text());
$crawler = $this->client->request('GET', '/s/forms/new');
Assert::assertStringNotContainsString('Social Login', $crawler->filter('#fields-container select.form-builder-new-component')->text());
}
public function testShowSocialMonitoring(): void
{
$this->createIntegration();
$crawler = $this->client->request('GET', '/s/config/edit');
Assert::assertStringContainsString('Social Settings', $crawler->filter('.list-group-tabs')->text());
}
private function createIntegration(): Integration
{
$plugin = new Plugin();
$plugin->setName('Social Media');
$plugin->setBundle('MauticSocialBundle');
$this->em->persist($plugin);
$integration = new Integration();
$integration->setPlugin($plugin);
$integration->setIsPublished(true);
$integration->setName('Twitter');
$this->em->persist($integration);
$this->em->flush();
return $integration;
}
}