Esempio n. 1
0
 public function testClassesForFolder()
 {
     //$baseFolder = Director::baseFolder() . '/' . FRAMEWORK_DIR . '/tests/_ClassInfoTest';
     //$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);
     $classes = ClassInfo::classes_for_folder(FRAMEWORK_DIR . '/tests');
     $this->assertContains('classinfotest', $classes, 'ClassInfo::classes_for_folder() returns classes matching the filename');
     $this->assertContains('classinfotest_baseclass', $classes, 'ClassInfo::classes_for_folder() returns additional classes not matching the filename');
 }
 function testClassesForFolder()
 {
     //$baseFolder = Director::baseFolder() . '/' . SAPPHIRE_DIR . '/tests/_ClassInfoTest';
     //$manifestInfo = ManifestBuilder::get_manifest_info($baseFolder);
     $classes = ClassInfo::classes_for_folder('sapphire/tests');
     $this->assertContains('classinfotest', $classes, 'ClassInfo::classes_for_folder() returns classes matching the filename');
     // $this->assertContains(
     // 			'ClassInfoTest_BaseClass',
     // 			$classes,
     // 			'ClassInfo::classes_for_folder() returns additional classes not matching the filename'
     // 		);
 }
 /**
  * Run tests for one or more "modules".
  * A module is generally a toplevel folder, e.g. "mysite" or "sapphire".
  * 
  * @param String $nameStr
  * @return Array
  */
 protected static function get_module_tests($namesStr)
 {
     $tests = array();
     $names = explode(',', $namesStr);
     foreach ($names as $name) {
         $classesForModule = ClassInfo::classes_for_folder($name);
         if ($classesForModule) {
             foreach ($classesForModule as $class) {
                 if (class_exists($class) && is_subclass_of($class, 'SapphireTest')) {
                     $tests[] = $class;
                 }
             }
         }
     }
     return $tests;
 }
Esempio n. 4
0
	/**
	 * Run tests for one or more "modules".
	 * A module is generally a toplevel folder, e.g. "mysite" or "framework".
	 * 
	 * @param String $nameStr
	 * @return Array
	 */
	protected static function get_module_tests($namesStr) {
		require_once(dirname(__FILE__) . '/bootstrap.php');
		
		$tests = array();
		$names = explode(',', $namesStr);
		foreach($names as $name) {
			$classesForModule = ClassInfo::classes_for_folder($name);
			if($classesForModule) foreach($classesForModule as $class) {
				if(class_exists($class) && is_subclass_of($class, 'SapphireTest')) {
					$tests[] = $class;
				}
			}
		}

		return $tests;
	}
Esempio n. 5
0
 /**
  * Run tests for one or more "modules".
  * A module is generally a toplevel folder, e.g. "mysite" or "sapphire".
  */
 function module($request, $coverage = false)
 {
     ManifestBuilder::load_test_manifest();
     $classNames = array();
     $moduleNames = explode(',', $request->param('ModuleName'));
     foreach ($moduleNames as $moduleName) {
         $classesForModule = ClassInfo::classes_for_folder($moduleName);
         if ($classesForModule) {
             foreach ($classesForModule as $class) {
                 if (class_exists($class) && is_subclass_of($class, 'SapphireTest')) {
                     $classNames[] = $class;
                 }
             }
         }
     }
     $this->runTests($classNames, $coverage);
 }
 /**
  * Find all test classes in a directory and return an array of them.
  * @param string $directory To search in
  * @param array $ignore Ignore these test classes if they are found.
  * @return array
  */
 protected function getTestsInDirectory($directory, $ignore = array())
 {
     $classes = ClassInfo::classes_for_folder($directory);
     return $this->filterTestClasses($classes, $ignore);
 }
Esempio n. 7
0
 /**
  * Run tests for one or more "modules".
  * A module is generally a toplevel folder, e.g. "mysite" or "framework".
  */
 public function module($request, $coverage = false)
 {
     self::use_test_manifest();
     $classNames = array();
     $moduleNames = explode(',', $request->param('ModuleName'));
     $ignored = array('functionaltest', 'phpsyntaxtest');
     foreach ($moduleNames as $moduleName) {
         $classesForModule = ClassInfo::classes_for_folder($moduleName);
         if ($classesForModule) {
             foreach ($classesForModule as $className) {
                 if (class_exists($className) && is_subclass_of($className, 'SapphireTest')) {
                     if (!in_array($className, $ignored)) {
                         $classNames[] = $className;
                     }
                 }
             }
         }
     }
     $this->runTests($classNames, $coverage);
 }
 /**
  * extracts other E-commerce Classes
  * @todo: retrieve description
  */
 protected function AllEcommerceClasses()
 {
     $otherClasses = ClassInfo::classes_for_folder("ecommerce");
     foreach ($otherClasses as $otherClass) {
         $this->definitions["AllEcommerceClasses"][$otherClass] = "";
         $this->defaults["AllEcommerceClasses"][$otherClass] = "";
         $this->configs["AllEcommerceClasses"][$otherClass] = "<a href=\"/dev/viewcode/" . $otherClass . "\" target=\"_blank\">view</a>";
     }
 }
 /**
  * Run tests for one or more "modules".
  * A module is generally a toplevel folder, e.g. "mysite" or "framework".
  * 
  * @OVERRIDE
  * 
  * Over-ridden to allow selection of specific test type if specified on the command line
  * 
  */
 public function module($request, $coverage = false)
 {
     self::use_test_manifest();
     $classNames = array();
     $moduleNames = explode(',', $request->param('ModuleName'));
     $testClassParent = $request->getVar('test_type');
     if (!$testClassParent) {
         $testClassParent = 'SapphireTest';
     }
     $ignored = array('functionaltest', 'phpsyntaxtest');
     foreach ($moduleNames as $moduleName) {
         $classesForModule = ClassInfo::classes_for_folder($moduleName);
         $this->moduleList[] = Director::baseFolder() . DIRECTORY_SEPARATOR . $moduleName;
         if ($classesForModule) {
             foreach ($classesForModule as $className) {
                 if (class_exists($className) && is_subclass_of($className, $testClassParent)) {
                     if (!in_array($className, $ignored)) {
                         $classNames[] = $className;
                     }
                 }
             }
         }
     }
     $this->runTests($classNames, $coverage);
 }
 /**
  * Generates a GraphViz dot template
  *
  * @return String a dot compatible data format
  */
 public function dot()
 {
     $opt = array();
     $opt['location'] = $this->paramDefault('location', 'mysite');
     $opt['ancestry'] = $this->paramDefault('ancestry', 1, 'numeric');
     $opt['relations'] = $this->paramDefault('relations', 1, 'numeric');
     $opt['fields'] = $this->paramDefault('fields', 1, 'numeric');
     $opt['include_root'] = $this->paramDefault('include-root', 0, 'numeric');
     $opt['exclude'] = $this->paramDefault('exclude');
     $opt['group'] = $this->paramDefault('group', 0, 'numeric');
     $opt['rankdir'] = $this->paramDefault('rankdir');
     if (!in_array($opt['rankdir'], array('LR', 'TB', 'BT', 'RL'))) {
         $opt['rankdir'] = 'TB';
     }
     $renderClasses = array();
     //Get all DataObject subclasses
     $dataClasses = ClassInfo::subclassesFor('DataObject');
     //Remove DataObject itself
     array_shift($dataClasses);
     //Get all classes in a specific folder(s)
     $folders = explode(",", $opt['location']);
     $folderClasses = array();
     foreach ($folders as $folder) {
         if (!empty($folder)) {
             $folderClasses[$folder] = ClassInfo::classes_for_folder($folder);
         }
     }
     $excludeArray = explode(",", $opt['exclude']);
     //Get the intersection of the two - grouped by the folder
     foreach ($dataClasses as $key => $dataClass) {
         foreach ($folderClasses as $folder => $classList) {
             foreach ($classList as $folderClass) {
                 if (strtolower($dataClass) == strtolower($folderClass)) {
                     //Remove all excluded classes
                     if (!in_array($dataClass, $excludeArray)) {
                         $renderClasses[$folder][$dataClass] = $dataClass;
                     }
                 }
             }
         }
     }
     if (count($renderClasses) == 0) {
         user_error("No classes that extend DataObject found in location: " . Convert::raw2xml($opt['location']));
     }
     $folders = new ArrayList();
     foreach ($renderClasses as $folderName => $classList) {
         $folder = new DataObject();
         $folder->Name = $folderName;
         $folder->Group = $opt['group'] == 1;
         $classes = new ArrayList();
         foreach ($classList as $className) {
             //Create a singleton of the class, to use for has_one,etc  instance methods
             $singleton = singleton($className);
             //Create a blank DO to use for rendering on the template
             $class = new DataObject();
             $class->ClassName = $className;
             //Get all the data fields for the class
             //fields = 0 - No fields
             //fields = 1 - only uninherited fields
             //fields = 2 - inherited fields
             $fields = new ArrayList();
             if ($opt['fields'] > 0) {
                 if ($opt['fields'] > 1) {
                     $dataFields = $singleton->inheritedDatabaseFields();
                 } else {
                     $dataFields = DataObject::custom_database_fields($className);
                 }
                 $fields = self::formatDataFields($dataFields, $fields);
             }
             $class->FieldList = $fields;
             if ($opt['relations'] > 1) {
                 $config = Config::INHERITED;
             } else {
                 $config = Config::UNINHERITED;
             }
             $hasOneArray = Config::inst()->get($className, 'has_one', $config);
             $hasManyArray = Config::inst()->get($className, 'has_many', $config);
             $manyManyArray = Config::inst()->get($className, 'many_many', $config);
             //TODO - what's the difference between:
             /*
             $hasOneArray = Config::inst()->get($className, 'has_one');
             $hasManyArray = Config::inst()->get($className, 'has_many');
             $manyManyArray = Config::inst()->get($className, 'many_many');
             
             //and
             
             $hasOneArray = $singleton->has_one();
             $hasManyArray = $singleton->has_many();
             $manyManyArray = $singleton->many_many();
             //Note - has_() calls are verbose - they retrieve relations all the way down to base class
             // ?? eg; for SiteTree, BackLinkTracking is a belongs_many_many
             */
             //$belongsToArray = $singleton->belongs_to();
             //print_r(ClassInfo::ancestry($className));
             //print_r($singleton->getClassAncestry());
             //Add parent class to HasOne
             //Remove the default "Parent" because thats the final parent, rather than the immediate parent
             unset($hasOneArray["Parent"]);
             $classAncestry = ClassInfo::ancestry($className);
             //getClassAncestry returns an array ordered from root to called class - to get parent, reverse and remove top element (called class)
             $classAncestry = array_reverse($classAncestry);
             array_shift($classAncestry);
             $parentClass = reset($classAncestry);
             $hasOneArray["Parent"] = $parentClass;
             //Ensure DataObject is not shown if include-root = 0
             if ($opt['include_root'] == 0 && $parentClass == "DataObject") {
                 unset($hasOneArray["Parent"]);
             }
             //if ancestry = 0, remove the "Parent" relation in has_one
             if ($opt['ancestry'] == 0 && isset($hasOneArray["Parent"])) {
                 unset($hasOneArray["Parent"]);
             }
             //if relations = 0, remove all but the parent relation
             if ($opt['relations'] == 0) {
                 $parent = isset($hasOneArray["Parent"]) ? $hasOneArray["Parent"] : null;
                 if ($parent) {
                     $hasOneArray = array();
                     $hasOneArray["Parent"] = $parent;
                 } else {
                     $hasOneArray = null;
                 }
                 $hasManyArray = null;
                 $manyManyArray = null;
             }
             $class->HasOneList = self::relationObject($hasOneArray, $excludeArray);
             $class->HasManyList = self::relationObject($hasManyArray, $excludeArray);
             $class->ManyManyList = self::relationObject($manyManyArray, $excludeArray, $class->ClassName);
             $classes->push($class);
         }
         $folder->Classes = $classes;
         $folders->push($folder);
     }
     $this->customise(array("Rankdir" => $opt['rankdir'], "Folders" => $folders));
     // Defend against source_file_comments
     Config::nest();
     Config::inst()->update('SSViewer', 'source_file_comments', false);
     // Render the output
     $output = $this->renderWith("Silvergraph");
     // Restore the original configuration
     Config::unnest();
     //Set output as plain text, and strip excess empty lines
     $this->response->addHeader("Content-type", "text/plain");
     $output = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", $output);
     return $output;
 }