Skip to content

Commit

Permalink
remove static methods and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehrke authored and MorrisJobke committed Sep 23, 2015
1 parent 8a3f853 commit 4d68e05
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 145 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# test coverage
tests/clover.xml
34 changes: 16 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ language: php

# list any PHP version you want to test against
php:
# using major version aliases

# aliased to a recent 5.3.x version
- 5.3
# aliased to a recent 5.4.x version
- 5.4
# aliased to a recent 5.5.x version
- 5.5
# aliased to a recent 5.5.x version
- 5.6
Expand All @@ -21,18 +15,22 @@ php:
# - DB=mysql
# - DB=pgsql

# execute any number of scripts before the test run, custom env's are available as variables
#before_script:
# - if [[ "$DB" == "pgsql" ]]; then psql -c "DROP DATABASE IF EXISTS hello_world_test;" -U postgres; fi
# - if [[ "$DB" == "pgsql" ]]; then psql -c "create database hello_world_test;" -U postgres; fi
# - if [[ "$DB" == "mysql" ]]; then mysql -e "create database IF NOT EXISTS hello_world_test;" -uroot; fi
env:
matrix:
- DB=sqlite

before_install:
- wget https://github.com/raw/owncloud/administration/master/travis-ci/before_install.sh
- bash ./before_install.sh firstrunwizard master $DB
- cd ../core
- php occ app:enable firstrunwizard

# omitting "script:" will default to phpunit
# use the $DB env variable to determine the phpunit.xml to use
#script: phpunit --configuration phpunit_$DB.xml --coverage-text
script: ant test
before_script:
- cd apps/firstrunwizard

# configure notifications (email, IRC, campfire etc)
#notifications:
# irc: "irc.freenode.org#travis"
script:
- cd tests
- phpunit --configuration phpunit.xml

allow_failures:
- php: hhvm
52 changes: 28 additions & 24 deletions ajax/disable.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
<?php

/**
* ownCloud - firstrunwizard application
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
* ownCloud - firstrunwizard application
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\FirstRunWizard;

OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('firstrunwizard');
OCP\JSON::callCheck();
use OCP\JSON;

\OCA_FirstRunWizard\Config::disable();
JSON::checkLoggedIn();
JSON::checkAppEnabled('firstrunwizard');
JSON::callCheck();

$config = \OC::$server->getConfig();
$userSession = \OC::$server->getUserSession();
$firstRunConfig = new Config($config, $userSession);

$firstRunConfig->disable();
52 changes: 28 additions & 24 deletions ajax/enable.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
<?php

/**
* ownCloud - firstrunwizard application
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
* ownCloud - firstrunwizard application
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\FirstRunWizard;

OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('firstrunwizard');
OCP\JSON::callCheck();
use OCP\JSON;

\OCA_FirstRunWizard\Config::enable();
JSON::checkLoggedIn();
JSON::checkAppEnabled('firstrunwizard');
JSON::callCheck();

$config = \OC::$server->getConfig();
$userSession = \OC::$server->getUserSession();
$firstRunConfig = new Config($config, $userSession);

$firstRunConfig->enable();
19 changes: 11 additions & 8 deletions appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* ownCloud - firstrunwizard App
*
Expand All @@ -20,16 +19,20 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\FirstRunWizard;

use OCP\Util;

OC::$CLASSPATH['OCA_FirstRunWizard\Config'] = 'firstrunwizard/lib/firstrunwizard.php';
Util::addStyle('firstrunwizard', 'colorbox');
Util::addScript('firstrunwizard', 'jquery.colorbox');
Util::addScript('firstrunwizard', 'firstrunwizard');

OCP\Util::addStyle( 'firstrunwizard', 'colorbox');
OCP\Util::addScript( 'firstrunwizard', 'jquery.colorbox');
OCP\Util::addScript( 'firstrunwizard', 'firstrunwizard');
Util::addStyle('firstrunwizard', 'firstrunwizard');

OCP\Util::addStyle('firstrunwizard', 'firstrunwizard');
$config = \OC::$server->getConfig();
$userSession = \OC::$server->getUserSession();
$firstRunConfig = new Config($config, $userSession);

if(\OCP\User::isLoggedIn() and \OCA_FirstRunWizard\Config::isEnabled()){
OCP\Util::addScript( 'firstrunwizard', 'activate');
if ($userSession->isLoggedIn() && $firstRunConfig->isEnabled()) {
Util::addScript( 'firstrunwizard', 'activate');
}
76 changes: 76 additions & 0 deletions lib/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* ownCloud - firstrunwizard App
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\FirstRunWizard;

use OCP\IConfig;
use OCP\IUserSession;

class Config {

protected $config;

protected $userSession;

/**
* @param IConfig $config
* @param IUserSession $userSession
*/
public function __construct(IConfig $config, IUserSession $userSession) {
$this->config = $config;
$this->userSession = $userSession;
}

/**
* @brief Disable the FirstRunWizard
*/
public function enable() {
$user = $this->userSession->getUser();
if ($user) {
$this->config->setUserValue($user->getUID(), 'firstrunwizard', 'show', 1);
}
}

/**
* @brief Enable the FirstRunWizard
*/
public function disable() {
$user = $this->userSession->getUser();
if ($user) {
$this->config->setUserValue($user->getUID(), 'firstrunwizard', 'show', 0);
}
}

/**
* @brief Check if the FirstRunWizard is enabled or not
* @return bool
*/
public function isEnabled() {
$user = $this->userSession->getUser();
if ($user) {
$conf = $this->config->getUserValue($user->getUID(), 'firstrunwizard', 'show', 1);
return (intval($conf) === 1);
} else {
return false;
}
}
}
54 changes: 0 additions & 54 deletions lib/firstrunwizard.php

This file was deleted.

39 changes: 35 additions & 4 deletions lib/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,50 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\FirstRunWizard;

use OCP\App\IAppManager;
use OCP\Defaults;
use OCP\IConfig;

class Util {

protected $appManager;

protected $config;

protected $defaults;

/**
* @param IAppManager $appManager
* @param IConfig $config
* @param Defaults $defaults
*/
public function __construct(IAppManager $appManager, IConfig $config, Defaults $defaults) {
$this->appManager = $appManager;
$this->config = $config;
$this->defaults = $defaults;
}

/**
* mimic \OC_Util::getEditionString()
* @return string
*/
public static function getEdition() {
if (\OC::$server->getAppManager()->isEnabledForUser('enterprise_key')) {
return "Enterprise";
public function getEdition() {
if ($this->appManager->isEnabledForUser('enterprise_key')) {
return 'Enterprise';
}
return '';
}

/**
* @return array
*/
public function getSyncClientUrls() {
return array(
'desktop' => $this->config->getSystemValue('customclient_desktop', $this->defaults->getSyncClientUrl()),
'android' => $this->config->getSystemValue('customclient_android', $this->defaults->getAndroidClientUrl()),
'ios' => $this->config->getSystemValue('customclient_ios', $this->defaults->getiOSClientUrl())
);
}
}
Loading

0 comments on commit 4d68e05

Please sign in to comment.