Skip to content

Commit

Permalink
Improving test structure in application classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker authored and piotr-cz committed Oct 6, 2014
1 parent 2a95a15 commit 11fd6e3
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 25 deletions.
Expand Up @@ -48,6 +48,14 @@ class JApplicationAdministratorTest extends TestCaseDatabase
*/
protected $class;

/**
* Backup of the SERVER superglobal
*
* @var array
* @since 3.4
*/
protected $backupServer;

/**
* Data for fetchConfigurationData method.
*
Expand Down Expand Up @@ -75,6 +83,14 @@ public function setUp()
{
parent::setUp();

$this->saveFactoryState();

JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
JFactory::$session = $this->getMockSession();

$this->backupServer = $_SERVER;

$_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
$_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
$_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
Expand All @@ -87,12 +103,6 @@ public function setUp()
// Get a new JApplicationAdministrator instance.
$this->class = new JApplicationAdministrator(null, $config);
TestReflection::setValue('JApplicationCms', 'instances', array('administrator' => $this->class));

// We are coupled to Document and Language in JFactory.
$this->saveFactoryState();

JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
}

/**
Expand All @@ -109,6 +119,8 @@ protected function tearDown()
TestReflection::setValue('JEventDispatcher', 'instance', null);
TestReflection::setValue('JApplicationCms', 'instances', array());

$_SERVER = $this->backupServer;

$this->restoreFactoryState();

parent::tearDown();
Expand Down
Expand Up @@ -50,6 +50,14 @@ class JApplicationCmsTest extends TestCaseDatabase
*/
protected $class;

/**
* Backup of the SERVER superglobal
*
* @var array
* @since 3.4
*/
protected $backupServer;

/**
* Data for fetchConfigurationData method.
*
Expand Down Expand Up @@ -77,6 +85,14 @@ public function setUp()
{
parent::setUp();

$this->saveFactoryState();

JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
JFactory::$session = $this->getMockSession();

$this->backupServer = $_SERVER;

$_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
$_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
$_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
Expand All @@ -88,12 +104,6 @@ public function setUp()

// Get a new JApplicationCmsInspector instance.
$this->class = new JApplicationCmsInspector(null, $config);

// We are coupled to Document and Language in JFactory.
$this->saveFactoryState();

JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
}

/**
Expand All @@ -113,6 +123,8 @@ protected function tearDown()
JApplicationCmsInspector::$headersSent = false;
JApplicationCmsInspector::$connectionAlive = true;

$_SERVER = $this->backupServer;

$this->restoreFactoryState();

parent::tearDown();
Expand Down
Expand Up @@ -48,6 +48,14 @@ class JApplicationSiteTest extends TestCaseDatabase
*/
protected $class;

/**
* Backup of the SERVER superglobal
*
* @var array
* @since 3.4
*/
protected $backupServer;

/**
* Data for fetchConfigurationData method.
*
Expand Down Expand Up @@ -75,6 +83,14 @@ public function setUp()
{
parent::setUp();

$this->saveFactoryState();

JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
JFactory::$session = $this->getMockSession();

$this->backupServer = $_SERVER;

$_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
$_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
$_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
Expand All @@ -87,12 +103,6 @@ public function setUp()
// Get a new JApplicationSite instance.
$this->class = new JApplicationSite(null, $config);
TestReflection::setValue('JApplicationCms', 'instances', array('site' => $this->class));

// We are coupled to Document and Language in JFactory.
$this->saveFactoryState();

JFactory::$document = $this->getMockDocument();
//JFactory::$language = $this->getMockLanguage();
}

/**
Expand All @@ -109,6 +119,8 @@ protected function tearDown()
TestReflection::setValue('JEventDispatcher', 'instance', null);
TestReflection::setValue('JApplicationCms', 'instances', array());

$_SERVER = $this->backupServer;

$this->restoreFactoryState();

parent::tearDown();
Expand Down
Expand Up @@ -37,6 +37,8 @@ protected function setUp()
{
parent::setUp();

$this->saveFactoryState();

// Create the class object to be tested.
$this->class = new JApplicationBaseInspector;
}
Expand All @@ -54,6 +56,8 @@ protected function tearDown()
// Reset the dispatcher instance.
TestReflection::setValue('JEventDispatcher', 'instance', null);

$this->restoreFactoryState();

parent::tearDown();
}

Expand Down
Expand Up @@ -50,6 +50,14 @@ class JApplicationWebTest extends TestCase
*/
protected $class;

/**
* Backup of the SERVER superglobal
*
* @var array
* @since 3.4
*/
protected $backupServer;

/**
* Data for detectRequestUri method.
*
Expand Down Expand Up @@ -95,19 +103,20 @@ public function setUp()
{
parent::setUp();

$this->saveFactoryState();

JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();

$this->backupServer = $_SERVER;

$_SERVER['HTTP_HOST'] = self::TEST_HTTP_HOST;
$_SERVER['HTTP_USER_AGENT'] = self::TEST_USER_AGENT;
$_SERVER['REQUEST_URI'] = self::TEST_REQUEST_URI;
$_SERVER['SCRIPT_NAME'] = '/index.php';

// Get a new JApplicationWebInspector instance.
$this->class = new JApplicationWebInspector;

// We are only coupled to Document and Language in JFactory.
$this->saveFactoryState();

JFactory::$document = $this->getMockDocument();
JFactory::$language = $this->getMockLanguage();
}

/**
Expand All @@ -120,8 +129,9 @@ public function setUp()
*/
protected function tearDown()
{
// Reset the dispatcher instance.
// Reset the dispatcher and session instances.
TestReflection::setValue('JEventDispatcher', 'instance', null);
TestReflection::setValue('JSession', 'instance', null);

// Reset some web inspector static settings.
JApplicationWebInspector::$headersSent = false;
Expand Down

0 comments on commit 11fd6e3

Please sign in to comment.