at the end of the day, it was inevitable
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace UserBundle\Entity\Notification\Schedule;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Class DailyNotificationScheduleTest
|
||||
*/
|
||||
class DailyNotificationScheduleTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDate()
|
||||
{
|
||||
$schedule = DailyNotificationSchedule::create()
|
||||
->setDays(DailyNotificationSchedule::DAYS_ALL)
|
||||
->setTime(DailyNotificationSchedule::TIME_30_M);
|
||||
|
||||
$start = new \DateTime();
|
||||
$start->setTime($start->format('H'), $start->format('i'), 0);
|
||||
$end = clone $start;
|
||||
$end->modify('+ 1 day');
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
/** @var \DateTime $date */
|
||||
$checkStart = clone $start;
|
||||
foreach ($dates as $date) {
|
||||
$this->assertSame(
|
||||
$checkStart->modify('+ 30 minute')->format('c'),
|
||||
$date->format('c')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDateWeekends()
|
||||
{
|
||||
$schedule = DailyNotificationSchedule::create()
|
||||
->setDays(DailyNotificationSchedule::DAYS_WEEKENDS)
|
||||
->setTime(DailyNotificationSchedule::TIME_4_H);
|
||||
|
||||
$start = new \DateTime();
|
||||
$start->modify('first friday');
|
||||
$start->setTime(23, 0, 0);
|
||||
$end = clone $start;
|
||||
$end->modify('+ 1 day');
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
/** @var \DateTime $date */
|
||||
$checkStart = clone $start;
|
||||
foreach ($dates as $date) {
|
||||
$this->assertSame(
|
||||
$checkStart->modify('+ 4 hour')->format('c'),
|
||||
$date->format('c')
|
||||
);
|
||||
$this->assertLessThanOrEqual((int) $date->format('N'), 5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDateWeekdays()
|
||||
{
|
||||
$schedule = DailyNotificationSchedule::create()
|
||||
->setDays(DailyNotificationSchedule::DAYS_WEEKDAYS)
|
||||
->setTime(DailyNotificationSchedule::TIME_1_H);
|
||||
|
||||
$start = new \DateTime();
|
||||
$start->modify('first sunday');
|
||||
$start->setTime(23, 0, 0);
|
||||
$end = clone $start;
|
||||
$end->modify('+ 1 day');
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
/** @var \DateTime $date */
|
||||
$checkStart = clone $start;
|
||||
foreach ($dates as $date) {
|
||||
$this->assertSame(
|
||||
$checkStart->modify('+ 1 hour')->format('c'),
|
||||
$date->format('c')
|
||||
);
|
||||
$this->assertGreaterThan((int) $date->format('N'), 5);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDateWithSpecifiedDates()
|
||||
{
|
||||
$schedule = DailyNotificationSchedule::create()
|
||||
->setDays(DailyNotificationSchedule::DAYS_ALL)
|
||||
->setTime(DailyNotificationSchedule::TIME_15_M);
|
||||
|
||||
$start = new \DateTime();
|
||||
$start
|
||||
->setDate(2017, 6, 9)
|
||||
->setTime(0, 0, 0);
|
||||
$end = clone $start;
|
||||
$end->modify('+ 30 minutes');
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
$this->assertCount(2, $dates);
|
||||
$this->assertSame('2017-06-09 00:15:00', $dates[0]->format('Y-m-d H:i:s'));
|
||||
$this->assertSame('2017-06-09 00:30:00', $dates[1]->format('Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace UserBundle\Entity\Notification\Schedule;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Class MonthlyNotificationScheduleTest
|
||||
*
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class MonthlyNotificationScheduleTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDate()
|
||||
{
|
||||
$schedule = MonthlyNotificationSchedule::create()
|
||||
->setDay(5)
|
||||
->setHour(12)
|
||||
->setMinute(35);
|
||||
|
||||
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
|
||||
$end = date_create()->modify('last day of next month')->setTime(0, 0, 0);
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
$this->assertCount(2, $dates);
|
||||
|
||||
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('first day of this month')->modify('4 day')->format('Y-m-d'));
|
||||
$this->assertSame(5, (int) $dates[0]->format('j'));
|
||||
$this->assertSame(12, (int) $dates[0]->format('H'));
|
||||
$this->assertSame(35, (int) $dates[0]->format('i'));
|
||||
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('first day of next month')->modify('4 day')->format('Y-m-d'));
|
||||
$this->assertSame(5, (int) $dates[1]->format('j'));
|
||||
$this->assertSame(12, (int) $dates[1]->format('H'));
|
||||
$this->assertSame(35, (int) $dates[1]->format('i'));
|
||||
|
||||
$schedule = MonthlyNotificationSchedule::create()
|
||||
->setDay(2)
|
||||
->setHour(8)
|
||||
->setMinute(50);
|
||||
|
||||
$start = date_create()->modify('first day of this month')->modify('1 day')->setTime(0, 0, 0);
|
||||
$end = date_create()->modify('next month')->modify('first day of next month')->modify('1 day')->setTime(0, 0, 0);
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
$this->assertCount(3, $dates);
|
||||
|
||||
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('first day of this month')->modify('1 day')->format('Y-m-d'));
|
||||
$this->assertSame(2, (int) $dates[0]->format('j'));
|
||||
$this->assertSame(8, (int) $dates[0]->format('H'));
|
||||
$this->assertSame(50, (int) $dates[0]->format('i'));
|
||||
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('first day of next month')->modify('1 day')->format('Y-m-d'));
|
||||
$this->assertSame(2, (int) $dates[1]->format('j'));
|
||||
$this->assertSame(8, (int) $dates[1]->format('H'));
|
||||
$this->assertSame(50, (int) $dates[1]->format('i'));
|
||||
$this->assertSame($dates[2]->format('Y-m-d'), date_create()->modify('next month')->modify('first day of next month')->modify('1 day')->format('Y-m-d'));
|
||||
$this->assertSame(2, (int) $dates[2]->format('j'));
|
||||
$this->assertSame(8, (int) $dates[2]->format('H'));
|
||||
$this->assertSame(50, (int) $dates[2]->format('i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDateLast()
|
||||
{
|
||||
$schedule = MonthlyNotificationSchedule::create()
|
||||
->setDay(MonthlyNotificationSchedule::DAY_LAST)
|
||||
->setHour(12)
|
||||
->setMinute(35);
|
||||
|
||||
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
|
||||
$end = date_create()->modify('last day of next month')->setTime(0, 0, 0);
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
$this->assertCount(2, $dates);
|
||||
|
||||
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('last day of this month')->format('Y-m-d'));
|
||||
$this->assertSame(12, (int) $dates[0]->format('H'));
|
||||
$this->assertSame(35, (int) $dates[0]->format('i'));
|
||||
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('last day of next month')->format('Y-m-d'));
|
||||
$this->assertSame(12, (int) $dates[1]->format('H'));
|
||||
$this->assertSame(35, (int) $dates[1]->format('i'));
|
||||
|
||||
$schedule = MonthlyNotificationSchedule::create()
|
||||
->setDay(MonthlyNotificationSchedule::DAY_LAST)
|
||||
->setHour(2)
|
||||
->setMinute(15);
|
||||
|
||||
$start = date_create()->modify('last day of this month')->setTime(0, 0, 0);
|
||||
$end = date_create()->modify('first day of next month')->setTime(0, 0, 0);
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
$this->assertCount(1, $dates);
|
||||
|
||||
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('last day of this month')->format('Y-m-d'));
|
||||
$this->assertSame(2, (int) $dates[0]->format('H'));
|
||||
$this->assertSame(15, (int) $dates[0]->format('i'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace UserBundle\Entity\Notification\Schedule;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Class WeeklyNotificationSchedule
|
||||
*
|
||||
* @ORM\Entity
|
||||
*/
|
||||
class WeeklyNotificationScheduleTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDate()
|
||||
{
|
||||
$schedule = WeeklyNotificationSchedule::create()
|
||||
->setPeriod(WeeklyNotificationSchedule::PERIOD_SECOND)
|
||||
->setDay(WeeklyNotificationSchedule::DAY_FRIDAY)
|
||||
->setHour(12)
|
||||
->setMinute(35);
|
||||
|
||||
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
|
||||
$end = date_create()->modify('second friday of next month')->setTime(0, 0, 0);
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
$this->assertCount(2, $dates);
|
||||
|
||||
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('second friday of this month')->format('Y-m-d'));
|
||||
$this->assertSame(12, (int) $dates[0]->format('H'));
|
||||
$this->assertSame(35, (int) $dates[0]->format('i'));
|
||||
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('second friday of next month')->format('Y-m-d'));
|
||||
$this->assertSame(12, (int) $dates[1]->format('H'));
|
||||
$this->assertSame(35, (int) $dates[1]->format('i'));
|
||||
|
||||
|
||||
$schedule = WeeklyNotificationSchedule::create()
|
||||
->setPeriod(WeeklyNotificationSchedule::PERIOD_FIRST)
|
||||
->setDay(WeeklyNotificationSchedule::DAY_TUESDAY);
|
||||
|
||||
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
|
||||
$end = date_create()->modify('second friday of next month')->setTime(0, 0, 0);
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
$this->assertCount(2, $dates);
|
||||
|
||||
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('first tuesday of this month')->format('Y-m-d'));
|
||||
$this->assertSame(0, (int) $dates[0]->format('H'));
|
||||
$this->assertSame(0, (int) $dates[0]->format('i'));
|
||||
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('first tuesday of next month')->format('Y-m-d'));
|
||||
$this->assertSame(0, (int) $dates[1]->format('H'));
|
||||
$this->assertSame(0, (int) $dates[1]->format('i'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDateEvery()
|
||||
{
|
||||
$schedule = WeeklyNotificationSchedule::create()
|
||||
->setPeriod(WeeklyNotificationSchedule::PERIOD_EVERY)
|
||||
->setDay(WeeklyNotificationSchedule::DAY_MONDAY)
|
||||
->setHour(10)
|
||||
->setMinute(45);
|
||||
|
||||
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
|
||||
$end = date_create()->modify('last day of next month')->setTime(0, 0, 0);
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
/** @var \DateTime $date */
|
||||
foreach ($dates as $date) {
|
||||
$this->assertSame(
|
||||
1,
|
||||
(int) $date->format('N')
|
||||
);
|
||||
$this->assertSame(10, (int) $date->format('H'));
|
||||
$this->assertSame(45, (int) $date->format('i'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testComputeDateLast()
|
||||
{
|
||||
$schedule = WeeklyNotificationSchedule::create()
|
||||
->setPeriod(WeeklyNotificationSchedule::PERIOD_LAST)
|
||||
->setDay(WeeklyNotificationSchedule::DAY_SUNDAY)
|
||||
->setHour(10)
|
||||
->setMinute(45);
|
||||
|
||||
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
|
||||
$end = date_create()->modify('next month')->modify('last day of next month')->setTime(0, 0, 0);
|
||||
|
||||
$dates = $schedule->computeDates($start, $end);
|
||||
|
||||
$this->assertCount(3, $dates);
|
||||
|
||||
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('last sunday of this month')->format('Y-m-d'));
|
||||
$this->assertSame(10, (int) $dates[0]->format('H'));
|
||||
$this->assertSame(45, (int) $dates[0]->format('i'));
|
||||
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('last sunday of next month')->format('Y-m-d'));
|
||||
$this->assertSame(10, (int) $dates[1]->format('H'));
|
||||
$this->assertSame(45, (int) $dates[1]->format('i'));
|
||||
$this->assertSame($dates[2]->format('Y-m-d'), date_create()->modify('next month')->modify('last sunday of next month')->format('Y-m-d'));
|
||||
$this->assertSame(10, (int) $dates[2]->format('H'));
|
||||
$this->assertSame(45, (int) $dates[2]->format('i'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace UserBundle\Entity\Recipient;
|
||||
|
||||
use Tests\AppTestCase;
|
||||
use UserBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* Class PersonRecipientTest
|
||||
*
|
||||
* @package UserBundle\Entity
|
||||
*/
|
||||
class PersonRecipientTest extends AppTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PersonRecipient
|
||||
*/
|
||||
private $recipient;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetFirstNameWithoutAssignedUser()
|
||||
{
|
||||
$this->recipient->setFirstName('first name');
|
||||
|
||||
$this->assertEquals('first name', $this->recipient->getFirstName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetFirstNameWithAssignedUser()
|
||||
{
|
||||
$user = new User();
|
||||
$this->recipient
|
||||
->setAssociatedUser($user)
|
||||
->setFirstName('first name');
|
||||
|
||||
$this->assertEquals('first name', $this->recipient->getFirstName());
|
||||
$this->assertEquals('first name', $user->getFirstName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLastNameWithoutAssignedUser()
|
||||
{
|
||||
$this->recipient->setLastName('last name');
|
||||
|
||||
$this->assertEquals('last name', $this->recipient->getLastName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLastNameWithAssignedUser()
|
||||
{
|
||||
$user = new User();
|
||||
$this->recipient
|
||||
->setAssociatedUser($user)
|
||||
->setLastName('last name');
|
||||
|
||||
$this->assertEquals('last name', $this->recipient->getLastName());
|
||||
$this->assertEquals('last name', $user->getLastName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetEmailWithoutAssignedUser()
|
||||
{
|
||||
$this->recipient->setEmail('test@test.test');
|
||||
|
||||
$this->assertEquals('test@test.test', $this->recipient->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetEmailWithAssignedUser()
|
||||
{
|
||||
$user = new User();
|
||||
$this->recipient
|
||||
->setAssociatedUser($user)
|
||||
->setEmail('test@test.test');
|
||||
|
||||
$this->assertEquals('test@test.test', $this->recipient->getEmail());
|
||||
$this->assertEquals('test@test.test', $user->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->recipient = new PersonRecipient();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace UserBundle\Entity\Traits;
|
||||
|
||||
use Tests\AppTestCase;
|
||||
use UserBundle\Enum\AppLimitEnum;
|
||||
|
||||
/**
|
||||
* Class LimitAwareTraitTest
|
||||
*
|
||||
* @package UserBundle\Entity\Traits
|
||||
*/
|
||||
class LimitAwareTraitTest extends AppTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var LimitAwareTrait
|
||||
*/
|
||||
private $trait;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testLimitValue()
|
||||
{
|
||||
/** @var AppLimitEnum $value */
|
||||
foreach (AppLimitEnum::getValues() as $value) {
|
||||
$this->trait->setLimitValue($value, 1);
|
||||
$this->assertEquals(1, $this->trait->getLimitValue($value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->trait = $this->getMockForTrait(LimitAwareTrait::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
|
||||
namespace UserBundle\Entity;
|
||||
|
||||
use Tests\AppTestCase;
|
||||
use UserBundle\Entity\Recipient\PersonRecipient;
|
||||
use UserBundle\Entity\Subscription\AbstractSubscription;
|
||||
use UserBundle\Entity\Subscription\PersonalSubscription;
|
||||
use UserBundle\Enum\AppLimitEnum;
|
||||
use UserBundle\Enum\AppPermissionEnum;
|
||||
|
||||
/**
|
||||
* Class UserTest
|
||||
*
|
||||
* @package UserBundle\Entity
|
||||
*/
|
||||
class UserTest extends AppTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Plan|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $plan;
|
||||
|
||||
/**
|
||||
* @var AbstractSubscription|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $subscription;
|
||||
|
||||
/**
|
||||
* @var User|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testIsAllowedTo()
|
||||
{
|
||||
$this->plan->setAnalytics(true);
|
||||
$this->assertTrue($this->user->isAllowedTo(AppPermissionEnum::analytics()));
|
||||
|
||||
$this->plan->setAnalytics(false);
|
||||
$this->assertFalse($this->user->isAllowedTo(AppPermissionEnum::analytics()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testUseLimit()
|
||||
{
|
||||
/** @var AppLimitEnum $value */
|
||||
foreach (AppLimitEnum::getValues() as $value) {
|
||||
$this->plan->setLimitValue($value, 4);
|
||||
$this->subscription->setLimitValue($value, 1);
|
||||
|
||||
$this->user->useLimit($value);
|
||||
$this->assertEquals(2, $this->user->getUsedLimit($value));
|
||||
$this->user->useLimit($value, 2);
|
||||
$this->assertEquals(4, $this->user->getUsedLimit($value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testReleaseLimit()
|
||||
{
|
||||
/** @var AppLimitEnum $value */
|
||||
foreach (AppLimitEnum::getValues() as $value) {
|
||||
$this->subscription->setLimitValue($value, 4);
|
||||
|
||||
$this->user->releaseLimit($value);
|
||||
$this->assertEquals(3, $this->user->getUsedLimit($value));
|
||||
$this->user->releaseLimit($value, 2);
|
||||
$this->assertEquals(1, $this->user->getUsedLimit($value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \AppBundle\Exception\LimitExceedException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUseLimitExceed()
|
||||
{
|
||||
$this->plan->setSearchesPerDay(4);
|
||||
$this->subscription->setSearchesPerDay(3);
|
||||
|
||||
$this->user->useLimit(AppLimitEnum::searches(), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetRestrictions()
|
||||
{
|
||||
$limits = [];
|
||||
/** @var AppLimitEnum $value */
|
||||
foreach (AppLimitEnum::getValues() as $value) {
|
||||
$limit = mt_rand(5, 10);
|
||||
$current = mt_rand(0, $limit);
|
||||
|
||||
$limits[$value->getValue()] = [
|
||||
'limit' => $limit,
|
||||
'current' => $current,
|
||||
];
|
||||
|
||||
$this->plan->setLimitValue($value, $limit);
|
||||
$this->subscription->setLimitValue($value, $current);
|
||||
}
|
||||
|
||||
$permissions = [];
|
||||
/** @var AppPermissionEnum $value */
|
||||
foreach (AppPermissionEnum::getValues() as $value) {
|
||||
$allow = (boolean) mt_rand(0, 1);
|
||||
|
||||
$permissions[$value->getValue()] = $allow;
|
||||
$this->plan->setPermission($value, $allow);
|
||||
}
|
||||
|
||||
$restrictions = $this->user->getRestrictions();
|
||||
|
||||
$this->assertCount(2, $restrictions);
|
||||
$this->assertArrayHasKey('limits', $restrictions);
|
||||
$this->assertArrayHasKey('permissions', $restrictions);
|
||||
$this->assertEquals($limits, $restrictions['limits']);
|
||||
$this->assertEquals($permissions, $restrictions['permissions']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setFirstNameWithoutRecipient()
|
||||
{
|
||||
$this->user->setFirstName('first name');
|
||||
|
||||
$this->assertEquals('first name', $this->user->getFirstName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setFirstNameWithRecipient()
|
||||
{
|
||||
$recipient = new PersonRecipient();
|
||||
|
||||
$this->user
|
||||
->setRecipient($recipient)
|
||||
->setFirstName('first name');
|
||||
|
||||
$this->assertEquals('first name', $this->user->getFirstName());
|
||||
$this->assertEquals('first name', $recipient->getFirstName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setLastNameWithoutRecipient()
|
||||
{
|
||||
$this->user->setLastName('last name');
|
||||
|
||||
$this->assertEquals('last name', $this->user->getLastName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setLastNameWithRecipient()
|
||||
{
|
||||
$recipient = new PersonRecipient();
|
||||
|
||||
$this->user
|
||||
->setRecipient($recipient)
|
||||
->setLastName('last name');
|
||||
|
||||
$this->assertEquals('last name', $this->user->getLastName());
|
||||
$this->assertEquals('last name', $recipient->getLastName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setEmailWithoutRecipient()
|
||||
{
|
||||
$this->user->setEmail('test@test.test');
|
||||
|
||||
$this->assertEquals('test@test.test', $this->user->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setEmailWithRecipient()
|
||||
{
|
||||
$recipient = new PersonRecipient();
|
||||
|
||||
$this->user
|
||||
->setRecipient($recipient)
|
||||
->setEmail('test@test.test');
|
||||
|
||||
$this->assertEquals('test@test.test', $this->user->getEmail());
|
||||
$this->assertEquals('test@test.test', $recipient->getEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->plan = new Plan();
|
||||
$this->subscription = new PersonalSubscription();
|
||||
$this->subscription->setPlan($this->plan);
|
||||
|
||||
$this->user = new User();
|
||||
$this->user->setBillingSubscription($this->subscription);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user