Since: 21.02.2013
Author: Vitaliy Demidov (vitaliy@scalr.com)
Inheritance: extends TestCase
Example #1
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     if (!$this->getUser()->isScalrAdmin()) {
         $this->markTestSkipped();
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     if (!$this->getUser()->canManageAcl() && !$this->getUser()->isTeamOwner()) {
         $this->markTestSkipped('Specified test user is not allowed to manage environments.');
     }
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Tests\TestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     if (!\Scalr::getContainer()->analytics->enabled) {
         $this->markTestSkipped("Cost analytics has not been enabled in the configuration.");
     }
 }
Example #4
0
 /**
  * {@inheritdoc}
  * @see PHPUnit_Framework_TestCase::tearDown()
  */
 public function tearDown()
 {
     if (\Scalr::getContainer()->initialized('user')) {
         \Scalr::getContainer()->release('user');
     }
     unset($this->logger);
     parent::tearDown();
 }
Example #5
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     $this->skipIfPlatformDisabled(\SERVER_PLATFORMS::EC2);
 }
Example #6
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
 }
Example #7
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     $this->testCategoryName = 'testrolecategory';
     $this->invalidCategoryName = 'Invalid-category!';
 }
Example #8
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     $this->testMetricName = 'testmetric' . $this->getInstallationId();
 }
Example #9
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::setUp()
  */
 protected function setUp()
 {
     parent::setUp();
     $this->testCertName = 'tescert' . $this->getInstallationId();
 }
Example #10
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests\WebTestCase::tearDown()
  */
 protected function tearDown()
 {
     $this->builder = null;
     parent::tearDown();
 }
Example #11
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::getRequest()
  */
 protected function getRequest($requestType, $requestClass, $uri, array $parameters = array(), $method = 'GET', array $server = array(), array $files = array())
 {
     $mock = $this->getMock('Scalr_UI_Request', array('restrictAccess', 'isAllowed'), array(), '', false);
     $me = $this;
     $user = $this->getUser();
     //Sets an ID of the environment.
     $user->getPermissions()->setEnvironmentId($this->getEnvironment()->id);
     $mock = parent::getRequest($requestType, $mock, $uri, $parameters, $method, $server, $files);
     $lfGetMessage = function ($prefix, $resourceId, $permissionId = null) {
         $rm = Acl::getResourcesMnemonic();
         return sprintf($prefix . '("%s", %s)', isset($rm[$resourceId]) ? $rm[$resourceId] : $resourceId, $permissionId ? '"' . $permissionId . '"' : 'null');
     };
     $mock->expects($this->any())->method('restrictAccess')->will($this->returnCallback(function ($resourceId, $permissionId = null) use($mock, $me, $lfGetMessage) {
         if (is_string($resourceId)) {
             $sName = 'Scalr\\Acl\\Acl::RESOURCE_' . strtoupper($resourceId);
             if (defined($sName)) {
                 $resourceId = constant($sName);
             } else {
                 throw new \InvalidArgumentException(sprintf('Cannot find ACL resource %s by specified symbolic name %s.', $sName, $resourceId));
             }
         }
         if (!$mock->isAllowed($resourceId, $permissionId)) {
             throw new Exception\AclAccessDeniedException($lfGetMessage('request->restrictAccess', $resourceId, $permissionId));
         }
         if (($catch = $me->getCatchOnlyPermission()) === null || $catch[0] == $resourceId && (isset($catch[1]) ? $catch[1] : null) == $permissionId) {
             throw new Exception\AclAccessGrantedException($lfGetMessage('request->restrictAccess', $resourceId, $permissionId));
         }
     }));
     $mock->expects($this->any())->method('isAllowed')->will($this->returnCallback(function ($resourceId, $permissionId = null) use($mock, $me, $lfGetMessage) {
         //Owner is allowed for everything
         if ($mock->getUser()->getType() == \Scalr_Account_User::TYPE_ACCOUNT_OWNER) {
             $ret = true;
         } else {
             if (is_string($resourceId)) {
                 $sName = 'Scalr\\Acl\\Acl::RESOURCE_' . strtoupper($resourceId);
                 if (defined($sName)) {
                     $resourceId = constant($sName);
                 } else {
                     throw new \InvalidArgumentException(sprintf('Cannot find ACL resource %s by specified symbolic name %s.', $sName, $resourceId));
                 }
             }
             $ret = (bool) $mock->getAclRoles()->isAllowed($resourceId, $permissionId);
         }
         if (($catch = $me->getCatchOnlyPermission()) === null || $catch[0] == $resourceId && (isset($catch[1]) ? $catch[1] : null) == $permissionId) {
             if ($ret) {
                 throw new Exception\AclAccessGrantedException($lfGetMessage('request->isAllowed', $resourceId, $permissionId));
             } else {
                 throw new Exception\AclAccessDeniedException($lfGetMessage('request->isAllowed', $resourceId, $permissionId));
             }
         }
         return $ret;
     }));
     if (($catch = $this->getCatchOnlyPermission()) !== null && count($catch) > 1 && $catch[0] == Acl::RESOURCE_FARMS && $catch[1] == Acl::PERM_FARMS_NOT_OWNED_FARMS) {
         //Mocking the user object of the request to catch hasAccessFarm calls
         /* @var $usermock \Scalr_Account_User */
         $usermock = $this->getMock('Scalr_Account_User', null);
         $usermock->loadById($this->getUser()->id);
         //Creates permissions mock
         $permissions = $this->getMock('Scalr_Permissions', array('hasAccessFarm'), array($usermock));
         //Injects permissions object to user mock.
         $refPerm = new \ReflectionProperty('Scalr_Account_User', 'permissions');
         $refPerm->setAccessible(true);
         $refPerm->setValue($usermock, $permissions);
         //Preparing stub for the method
         $permissions->expects($this->any())->method('hasAccessFarm')->will($this->returnCallback(function ($dbFarm) use($user) {
             $ret = $user->getPermissions()->hasAccessFarm($dbFarm);
             if ($ret) {
                 throw new Exception\AclAccessGrantedException(sprintf('user->permissions->hasAccessFarm(%d)', $dbFarm->ID));
             } else {
                 throw new Exception\AclAccessDeniedException(sprintf('user->permissions->hasAccessFarm(%d)', $dbFarm->ID));
             }
         }));
         //Injecting user mock to request mock.
         $refUser = new \ReflectionProperty('Scalr_UI_Request', 'user');
         $refUser->setAccessible(true);
         $refUser->setValue($mock, $usermock);
     }
     return $mock;
 }
Example #12
0
 /**
  * {@inheritdoc}
  * @see PHPUnit_Framework_TestCase::tearDown()
  */
 public function tearDown()
 {
     \Scalr::getContainer()->user = null;
     unset($this->logger);
     parent::tearDown();
 }
Example #13
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::tearDown(
  */
 protected function tearDown()
 {
     $this->module = null;
     parent::tearDown();
 }
Example #14
0
 /**
  * {@inheritdoc}
  * @see Scalr\Tests.WebTestCase::tearDown()
  */
 protected function tearDown()
 {
     parent::tearDown();
 }
Example #15
0
 public function getFixturesDirectory()
 {
     return parent::getFixturesDirectory() . '/Upgrade/MysqlDiff';
 }