public function testRunDiagnostic() { ZurmoRedBean::exec("SHOW TABLES"); $countBefore = ZurmoRedBean::getCell("SELECT FOUND_ROWS();"); $content = $this->runControllerWithNoExceptionsAndGetContent('configuration/default/runDiagnostic'); $this->assertContains("Failed Required Services", $content); $this->assertContains("<span class=\"fail\">FAIL</span>", $content); $this->assertContains("Zurmo runs only on Apache 2.2.1 and higher or Microsoft-IIS 5.0.0 or higher web servers.", $content); $this->assertContains("\$_SERVER does not have HTTP_HOST, SERVER_NAME, SERVER_PORT, HTTP_ACCEPT, HTTP_USER_AGENT", $content); $criticalFailureCount = substr_count($content, "<span class=\"fail\">FAIL</span>"); $this->assertThat(true, $this->logicalOr($this->equalTo(2, $criticalFailureCount), $this->equalTo(3, $criticalFailureCount))); if ($criticalFailureCount === 3) { $this->assertTrue(strpos($content, "The application.log runtime file is writable.<br />\n" . "The /minScript/cache runtime directory is not writable.<br />\n" . "The debug.php file is present.") !== false || strpos($content, "Host Info/Script Url is incorrectly configured.") !== false); } $this->assertFileExists(realpath(INSTANCE_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'perInstance.php')); $this->assertFileExists(realpath(INSTANCE_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'debug.php')); ZurmoRedBean::exec("SHOW TABLES"); $countAfter = ZurmoRedBean::getCell("SELECT FOUND_ROWS();"); $this->assertEquals($countBefore, $countAfter); }
public function testSavingNewParentAccountSavesCorrectly() { $oldMetadata = Account::getMetadata(); $newMetadata = $oldMetadata; $newMetadata['Account']['rules'][] = array('type', 'default', 'value' => 'Customer'); Account::setMetadata($newMetadata); $account = new Account(); $account->name = 'Account'; $account->type->value = 'Customer'; $account->account = $account; $saved = $account->save(); $this->assertTrue($saved); $account->account = null; $saved = $account->save(); $this->assertTrue($saved); $count = ZurmoRedBean::getCell('select count(*) from account'); $this->assertEquals(1, $count); Account::setMetadata($oldMetadata); $this->assertTrue($account->delete()); }
protected static function fastContainsUserByGroupId($groupId, $userId) { assert('is_int($groupId) && $groupId > 0'); // Not Coding Standard assert('is_int($userId) && $userId > 0'); // Not Coding Standard return ZurmoRedBean::getCell("select group_contains_user({$groupId}, {$userId});") == 1; }
public static function getUserLeaderboardCount($type) { $sql = self::makeUserLeaderboardCountSqlQuery($type); $count = ZurmoRedBean::getCell($sql); if ($count === null || is_array($count) && count($count) == 0) { $count = 0; } return $count; }
public function testSetMemberCalledCurrencyToACurrencyDoesntMakeARowOfNulls() { $opportunity = new Opportunity(); $opportunity->name = 'Thingo'; $opportunity->stage->value = 'Starting Up'; $opportunity->closeDate = '2008-10-05'; $opportunity->amount->value = 69.0; $opportunity->amount->currency->code = 'BTC'; $opportunity->amount->currency->rateToBase = 1.0; $this->assertTrue($opportunity->save()); $opportunity->delete(); $this->assertEquals(1, ZurmoRedBean::getCell('select count(*) from currency')); $currency = Currency::getByCode('BTC'); $currency->delete(); $currency->forget(); $this->assertEquals(0, ZurmoRedBean::getCell('select count(*) from currency')); }
/** * @param $sql * @return string */ public static function callProcedureWithoutOuts($sql) { try { return ZurmoRedBean::getCell("call {$sql};"); } catch (RedBean_Exception_SQL $e) { self::createStoredFunctionsAndProcedures(); self::createActualPermissionsCacheTable(); self::createNamedSecurableActualPermissionsCacheTable(); self::createActualRightsCacheTable(); return ZurmoRedBean::getCell("call {$sql};"); } }
/** * Resolve the correct order for a savedWorkflow. If it is a new savedWorkflow then set the order to max * plus 1. 'Max' is a calculation of the existing workflows that are for the specific moduleClassName. * If the workflow is an existing workflow, then if moduleClassName has changed, the 'max' plus 1 should be * used. Otherwise if it is new and the moduleClassName has not changed, then leave it alone * @param SavedWorkflow $savedWorkflow * @param bool $isBeingCopied * @throws NotSupportedException if the moduleClassName has not been defined yet */ public static function resolveOrder(SavedWorkflow $savedWorkflow, $isBeingCopied = false) { assert('is_bool($isBeingCopied)'); if ($savedWorkflow->moduleClassName == null) { throw new NotSupportedException(); } $q = DatabaseCompatibilityUtil::getQuote(); $sql = "select max({$q}order{$q}) maxorder from " . SavedWorkflow::getTableName(); $sql .= " where moduleclassname = '" . $savedWorkflow->moduleClassName . "'"; if ($isBeingCopied || $savedWorkflow->id < 0 || array_key_exists('moduleClassName', $savedWorkflow->originalAttributeValues)) { $maxOrder = ZurmoRedBean::getCell($sql); $savedWorkflow->order = (int) $maxOrder + 1; } }
/** * @depends testExampleStoredProcedure */ public function testExampleStoredFunction() { try { ZurmoRedBean::exec("drop function get_wukka_integer2"); } catch (Exception $e) { } ZurmoRedBean::exec("\n create function get_wukka_integer2(the_string varchar(255))\n returns int(11)\n begin\n declare the_integer int(11);\n select wukka.integer\n into the_integer\n from wukka\n where wukka.string = the_string;\n return the_integer;\n end\n "); $this->assertEquals(666, ZurmoRedBean::getCell("select get_wukka_integer2('yyy')")); }
public function doesNotAlreadyExist($attribute, $params) { if ($this->id < 0) { $query = 'SELECT COUNT(*) FROM ' . static::getTableName(); $query .= ' WHERE contact_id=' . $this->contact->id . ' AND marketinglist_id=' . $this->marketingList->id; if (ZurmoRedBean::getCell($query)) { $this->addError($attribute, Zurmo::t('MarketingListsModule', 'Member already exists')); return false; } } return true; }
/** * @depends testCreationAndModificationTimes */ public function testExtraItemsCreatedOnModelInstantiation() { $countBefore = intval(ZurmoRedBean::getCell("select count(*) from item;")); $account = new Account(); $countAfter = intval(ZurmoRedBean::getCell("select count(*) from item;")); $this->assertEquals($countBefore, $countAfter); }
/** * @param $modelClassName * @param $joinTablesAdapter null or instance of joinTablesAdapter. * @param $modelClassName Pass only when getting it at runtime gets the wrong name. */ public static function getCount(RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter = null, $where = null, $modelClassName = null, $selectDistinct = false) { assert('$where === null || is_string($where)'); assert('$modelClassName === null || is_string($modelClassName) && $modelClassName != ""'); if ($modelClassName === null) { $modelClassName = get_called_class(); } if ($joinTablesAdapter == null) { $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName); } $tableName = $modelClassName::getTableName(); $sql = static::makeSubsetOrCountSqlQuery($tableName, $joinTablesAdapter, null, null, $where, null, true, $selectDistinct); $count = ZurmoRedBean::getCell($sql); if ($count === null || empty($count)) { $count = 0; } return intval($count); }
public function testPermissionsCachingBasics() { if (!SECURITY_OPTIMIZED) { return; } $accounts = Account::getAll(); $account = $accounts[0]; $user = User::getByUsername('bobby'); $this->assertNotEquals($account->owner->id, $user->id); $account->addPermissions($user, Permission::READ); $this->assertTrue($account->save()); $securableItemId = $account->getClassId('SecurableItem'); $permitableId = $user->getClassId('Permitable'); ZurmoRedBean::exec("call get_securableitem_cached_actual_permissions_for_permitable({$securableItemId}, {$permitableId}, @allow_permissions, @deny_permissions)"); $allow_permissions = intval(ZurmoRedBean::getCell('select @allow_permissions')); $deny_permissions = intval(ZurmoRedBean::getCell('select @deny_permissions')); $this->assertEquals(Permission::NONE, $allow_permissions); $this->assertEquals(Permission::NONE, $deny_permissions); ZurmoDatabaseCompatibilityUtil::callProcedureWithoutOuts("cache_securableitem_actual_permissions_for_permitable({$securableItemId}, {$permitableId}, 1, 0)"); ZurmoRedBean::exec("call get_securableitem_cached_actual_permissions_for_permitable({$securableItemId}, {$permitableId}, @allow_permissions, @deny_permissions)"); $allow_permissions = intval(ZurmoRedBean::getCell('select @allow_permissions')); $deny_permissions = intval(ZurmoRedBean::getCell('select @deny_permissions')); $this->assertEquals(Permission::READ, $allow_permissions); $this->assertEquals(Permission::NONE, $deny_permissions); ZurmoDatabaseCompatibilityUtil::callProcedureWithoutOuts("clear_cache_securableitem_actual_permissions({$securableItemId})"); ZurmoRedBean::exec("call get_securableitem_cached_actual_permissions_for_permitable({$securableItemId}, {$permitableId}, @allow_permissions, @deny_permissions)"); $allow_permissions = intval(ZurmoRedBean::getCell('select @allow_permissions')); $deny_permissions = intval(ZurmoRedBean::getCell('select @deny_permissions')); $this->assertEquals(Permission::NONE, $allow_permissions); $this->assertEquals(Permission::NONE, $deny_permissions); $account->removeAllPermissions(); $this->assertTrue($account->save()); $this->assertEquals(Permission::NONE, $account->getEffectivePermissions($user)); $this->assertEquals(array(Permission::NONE, Permission::NONE), $account->getExplicitActualPermissions($user)); $this->assertEquals(array(Permission::NONE, Permission::NONE), $account->getInheritedActualPermissions($user)); }
protected static function getCell($query, $expectingAtLeastOne = true) { $result = ZurmoRedBean::getCell($query); if (!isset($result) || $result < 1 && $expectingAtLeastOne) { throw new NotSupportedException("Query: " . PHP_EOL . $query); } return intval($result); }
/** * See the yii documentation. This function is made public for unit testing. * @return int|string */ public function calculateTotalItemCount() { $selectQueryAdapter = $this->makeSelectQueryAdapter(); $sql = $this->makeSqlQueryForFetchingTotalItemCount($selectQueryAdapter, true); $count = ZurmoRedBean::getCell($sql); if ($count === null || empty($count)) { $count = 0; } return $count; }
/** * Get the row count in a given table. * @param string $tableName * @return integer */ public static function getCount($tableName, $where = null) { if ($where === null) { return ZurmoRedBean::$writer->count($tableName); } else { $sql = 'select count(id) count from ' . $tableName; $sql .= ' where ' . $where; $count = ZurmoRedBean::getCell($sql); if ($count === null) { $count = 0; } return $count; } }
protected static function getAccountMungeRowCount() { return intval(ZurmoRedBean::getCell('select count(*) from account_read')); }
public static function getNextLayoutId() { return max(2, (int) ZurmoRedBean::getCell('select max(layoutId) + 1 from dashboard')); }