Skip to content

Commit

Permalink
General Test detached from patterns.test
Browse files Browse the repository at this point in the history
  • Loading branch information
shakty committed Apr 12, 2012
1 parent cf86f40 commit c8fc59f
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 162 deletions.
1 change: 1 addition & 0 deletions patterns.info
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ php = 5.2

; Core
files[] = tests/patterns.test
files[] = tests/general/general.test
files[] = tests/parser/parser.test
files[] = tests/importing/importing.test

Expand Down
149 changes: 149 additions & 0 deletions tests/general/general.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php

/**
* @file
* General SimpleTests for Patterns. Also, a Pattern running base class which uses QuickRun.
*/

class PatternsGeneralTestCase extends PatternRunTestCase {
public static function getInfo() {
return array(
'name' => 'General test',
'description' => 'Tests privileges, enabling a pattern, the editor.',
'group' => 'Patterns',
);
}

public function setUp($user_modules = array(), $first = FALSE) {

$modules = array('patterns_yamlparser');

// Enable any modules required for the tests.
parent::setUp($modules);

// TODO: how to ensure that Spyc is installed?

// Create users.
$this->adm_user = $this->drupalCreateUser(array('administer site configuration'));
$this->pat_user = $this->drupalCreateUser(array('administer patterns'));
$this->std_user = $this->drupalCreateUser(array());


}

function testSpyc() {
// Login the site administrator.
$this->drupalLogin($this->adm_user);

$this->drupalGet('admin/reports/status');
$this->assertResponse(200);
if ($this->spycAvailable()) {
$this->assertRaw('Spyc library (YAML parser)</td><td class="status-value">0.5', t('Spyc 0.5 is installed and detected.'));
}
else {
$this->assertRaw('Spyc library (YAML parser)</td><td class="status-value">' . t('Missing'), t('Spyc 0.5 is not detected and the proper error message is shown.'));
}
}

/**
* Login users, load the Patterns list page.
*/
function testPatterns() {
// Login the patterns administrator.
$this->drupalLogin($this->pat_user);
$this->verifyAccess(200);

// Login a regular user.
$this->drupalLogin($this->std_user);
$this->verifyAccess(403);
}

/**
* Verify the logged in user has the desired access to the various menu nodes.
*
* @param integer $response HTTP response code.
*/
private function verifyAccess($response = 200) {
// View patterns list.
$this->drupalGet('admin/patterns');
$this->assertResponse($response);
if ($response == 200) {
$this->checkPage();
//$this->assertTitle('Patterns | Drupal');
$this->assertUniqueText(t('Commands'), t('Patterns commands loaded'));
$this->assertUniqueText(t('No patterns available.'), t('No patterns found (correctly!)'));
$this->assertUniqueText(t('Removed Patterns'), t('Patterns trash bin loaded'));
}
}

private function checkPage() {
// TODO: regexp?
// TODO: do this better?
$this->assertNoText(t('Error'), t('There should be no errors.'));
$this->assertNoText(t('Warning'), t('There should be no warnings.'));
$this->assertNoText(t('Notice'), t('There should be no notices.'));
}

private function spycAvailable() {
$path = libraries_get_path('spyc') . '/spyc.php';
if (!file_exists($path)) {
return FALSE;
}
return TRUE;
}

}

/*
// TODO: Temporarily disabled until we find a better way of doing this.



// Enabling form for the first pattern.
$this->drupalGet('admin/patterns/enable/1');
$this->assertResponse($response);
if ($response == 200) {
$this->checkPage();

// Some assertions.
$name = "Enable/disable modules";
$this->assertRaw(t('Proceed with running pattern %pattern?', array('%pattern' => $name)));

// Fill the form.
$edit = array();
$edit['mode'] = 'php';

// Post the form.
$this->drupalPost('admin/patterns/enable/1', $edit, t('Confirm'));
$this->assertResponse($response);

// Some assertions.
// TODO: make this more general.
$this->assertUniqueText(t('Pattern "@pattern" ran successfully.', array('@pattern' => $name)), t('Valid pattern runs without errors.'));
$this->assertNoText(t('Error(s) while processing pattern:'), t('Valid pattern does not produce errors.'));
$this->assertRaw('Enabled</td><td><label><strong>' . $name);
}

// Use the editor.
// $this->assertTitle('Patterns');
$this->drupalGet('admin/patterns/edit/2');
$this->assertResponse($response);
if ($response == 200) {
//$this->assertTitle('Edit Pattern');
// TODO: Get path.
// $filepath =
// $this->assertRaw(t('Path') . ':</td><td>' . $filepath);
$this->assertRaw('<td>' . t('Enabled') . ':</td><td>' . t('No') . t('</td>'));
// TODO: Why can't I use PatternRunTestCase::loadPattern('variables.yaml') ? Maybe because the class is abstract?
$filename = 'block_delete.yaml';
$patternfile = file_get_contents(drupal_get_path('module', 'patterns') . '/patterns/' . $filename);
$this->assertRaw('class="form-textarea">' . $patternfile);

// TODO
//// Try validating.
//$values = array('pattern' => $patternfile);
//$this->drupalPost('patterns/validate', $values, array('path' => 'patterns/validate', ));


}
*/
164 changes: 2 additions & 162 deletions tests/patterns.test
Original file line number Diff line number Diff line change
@@ -1,164 +1,4 @@
<?php
/**
* @file
* General SimpleTests for Patterns. Also, a Pattern running base class which uses QuickRun.
*/

class PatternsPrivilegesTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'General test',
'description' => 'Tests privileges, enabling a pattern, the editor.',
'group' => 'Patterns',
);
}

public function setUp($user_modules = array(), $first = FALSE) {

$modules = array('patterns');
if (!empty($user_modules)) {
if (!is_array($user_modules)) {
$user_modules = array($user_modules);
}
$modules = array_merge($modules, $user_modules);
$modules = array_unique($modules);
}

// Enable any modules required for the tests.
parent::setUp($modules);

if (!$first) {
// 'patterns_first_install' => PATTERNS_FIRST_INSTALL in
// includes/variables.inc (may be not yet loaded)
variable_set('patterns_first_install', FALSE);
// TODO: Can we set the flag FIRST_INSTALL to FALSE before enabling patterns
// so that we don't need to rebuild the menu
menu_rebuild();
}

// TODO: how to ensure that Spyc is installed?

// Create users.
$this->adm_user = $this->drupalCreateUser(array('administer site configuration'));
$this->pat_user = $this->drupalCreateUser(array('administer patterns'));
$this->std_user = $this->drupalCreateUser(array());


}

function testSpyc() {
// Login the site administrator.
$this->drupalLogin($this->adm_user);

$this->drupalGet('admin/reports/status');
$this->assertResponse(200);
if ($this->spycAvailable()) {
$this->assertRaw('Spyc library (YAML parser)</td><td class="status-value">0.5', t('Spyc 0.5 is installed and detected.'));
}
else {
$this->assertRaw('Spyc library (YAML parser)</td><td class="status-value">' . t('Missing'), t('Spyc 0.5 is not detected and the proper error message is shown.'));
}
}

private function spycAvailable() {
$path = libraries_get_path('spyc') . '/spyc.php';
if (!file_exists($path)) {
return FALSE;
}
return TRUE;
}

/**
* Login users, load the Patterns list page.
*/
function testPatterns() {
// Login the patterns administrator.
$this->drupalLogin($this->pat_user);
$this->verifyAccess(200);

// Login a regular user.
$this->drupalLogin($this->std_user);
$this->verifyAccess(403);
}

/**
* Verify the logged in user has the desired access to the various menu nodes.
*
* @param integer $response HTTP response code.
*/
private function verifyAccess($response = 200) {
// View patterns list.
$this->drupalGet('admin/patterns');
$this->assertResponse($response);
if ($response == 200) {
$this->checkPage();

$this->assertUniqueText(t('Looking for patterns files under the following locations:'), t('Patterns list was displayed'));
//$this->assertTitle('Patterns');
}
/*
// TODO: Temporarily disabled until we find a better way of doing this.



// Enabling form for the first pattern.
$this->drupalGet('admin/patterns/enable/1');
$this->assertResponse($response);
if ($response == 200) {
$this->checkPage();

// Some assertions.
$name = "Enable/disable modules";
$this->assertRaw(t('Proceed with running pattern %pattern?', array('%pattern' => $name)));

// Fill the form.
$edit = array();
$edit['mode'] = 'php';

// Post the form.
$this->drupalPost('admin/patterns/enable/1', $edit, t('Confirm'));
$this->assertResponse($response);

// Some assertions.
// TODO: make this more general.
$this->assertUniqueText(t('Pattern "@pattern" ran successfully.', array('@pattern' => $name)), t('Valid pattern runs without errors.'));
$this->assertNoText(t('Error(s) while processing pattern:'), t('Valid pattern does not produce errors.'));
$this->assertRaw('Enabled</td><td><label><strong>' . $name);
}

// Use the editor.
// $this->assertTitle('Patterns');
$this->drupalGet('admin/patterns/edit/2');
$this->assertResponse($response);
if ($response == 200) {
//$this->assertTitle('Edit Pattern');
// TODO: Get path.
// $filepath =
// $this->assertRaw(t('Path') . ':</td><td>' . $filepath);
$this->assertRaw('<td>' . t('Enabled') . ':</td><td>' . t('No') . t('</td>'));
// TODO: Why can't I use PatternRunTestCase::loadPattern('variables.yaml') ? Maybe because the class is abstract?
$filename = 'block_delete.yaml';
$patternfile = file_get_contents(drupal_get_path('module', 'patterns') . '/patterns/' . $filename);
$this->assertRaw('class="form-textarea">' . $patternfile);

// TODO
//// Try validating.
//$values = array('pattern' => $patternfile);
//$this->drupalPost('patterns/validate', $values, array('path' => 'patterns/validate', ));


}
*/
}

private function checkPage() {
// TODO: regexp?
// TODO: do this better?
$this->assertNoText(t('Error'), t('There should be no errors.'));
$this->assertNoText(t('Warning'), t('There should be no warnings.'));
$this->assertNoText(t('Notice'), t('There should be no notices.'));
}
}

/**
* Abstract base class for testing pattern component behavior.
Expand All @@ -177,7 +17,7 @@ abstract class PatternRunTestCase extends DrupalWebTestCase {
/**
* Setups the testing environment.
*
* Loads the patterns module plus all the those that are
* Loads the patterns and libraries modules plus all those that are
* passed as parameters; skips the Patterns splash screen.
*
* @param array $user_modules The array of modules to enable
Expand All @@ -187,7 +27,7 @@ abstract class PatternRunTestCase extends DrupalWebTestCase {
*/
public function setUp($user_modules = array(), $first = FALSE) {

$modules = array('patterns');
$modules = array('patterns', 'libraries');
if (!empty($user_modules)) {
if (!is_array($user_modules)) {
$user_modules = array($user_modules);
Expand Down

0 comments on commit c8fc59f

Please sign in to comment.