本文整理汇总了PHP中PHPUnit_Util_XML类的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_XML类的具体用法?PHP PHPUnit_Util_XML怎么用?PHP PHPUnit_Util_XML使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPUnit_Util_XML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertTourTips
/**
* Assert function to determine if tips rendered to the page
* have a corresponding page element.
*
* @param array $tips
* A list of tips which provide either a "data-id" or "data-class".
*
* @code
* // Basic example.
* $this->assertTourTips();
*
* // Advanced example. The following would be used for multipage or
* // targeting a specific subset of tips.
* $tips = array();
* $tips[] = array('data-id' => 'foo');
* $tips[] = array('data-id' => 'bar');
* $tips[] = array('data-class' => 'baz');
* $this->assertTourTips($tips);
* @endcode
*/
public function assertTourTips($tips = array())
{
// Get the rendered tips and their data-id and data-class attributes.
if (empty($tips)) {
// Tips are rendered as <li> elements inside <ol id="tour">.
$rendered_tips = $this->xpath('//ol[@id = "tour"]//li[starts-with(@class, "tip")]');
foreach ($rendered_tips as $rendered_tip) {
$attributes = (array) $rendered_tip->attributes();
$tips[] = $attributes['@attributes'];
}
}
// If the tips are still empty we need to fail.
if (empty($tips)) {
$this->fail('Could not find tour tips on the current page.');
} else {
// Check for corresponding page elements.
$total = 0;
$modals = 0;
foreach ($tips as $tip) {
if (!empty($tip['data-id'])) {
$elements = \PHPUnit_Util_XML::cssSelect('#' . $tip['data-id'], TRUE, $this->content, TRUE);
$this->assertTrue(!empty($elements) && count($elements) === 1, format_string('Found corresponding page element for tour tip with id #%data-id', array('%data-id' => $tip['data-id'])));
} elseif (!empty($tip['data-class'])) {
$elements = \PHPUnit_Util_XML::cssSelect('.' . $tip['data-class'], TRUE, $this->content, TRUE);
$this->assertFalse(empty($elements), format_string('Found corresponding page element for tour tip with class .%data-class', array('%data-class' => $tip['data-class'])));
} else {
// It's a modal.
$modals++;
}
$total++;
}
$this->pass(format_string('Total %total Tips tested of which %modals modal(s).', array('%total' => $total, '%modals' => $modals)));
}
}
示例2: assertNotTag
/**
* Note: we are overriding this method to remove the deprecated error
* @see https://tracker.moodle.org/browse/MDL-47129
*
* @param array $matcher
* @param string $actual
* @param string $message
* @param boolean $ishtml
*
* @deprecated 3.0
*/
public static function assertNotTag($matcher, $actual, $message = '', $ishtml = true)
{
$dom = PHPUnit_Util_XML::load($actual, $ishtml);
$tags = self::findNodes($dom, $matcher, $ishtml);
$matched = count($tags) > 0 && $tags[0] instanceof DOMNode;
self::assertFalse($matched, $message);
}
示例3: findElementContent
private function findElementContent($html, $matcher)
{
$el = \PHPUnit_Util_XML::findNodes(dom_import_simplexml(simplexml_load_string($html))->ownerDocument, $matcher);
if ($el === false) {
return false;
}
return $el[0]->textContent;
}
示例4: testPrepareString
/**
* @dataProvider charProvider
*/
public function testPrepareString($char)
{
$e = null;
$escapedString = PHPUnit_Util_XML::prepareString($char);
$xml = "<?xml version='1.0' encoding='UTF-8' ?><tag>{$escapedString}</tag>";
$dom = new DomDocument('1.0', 'UTF-8');
try {
$dom->loadXML($xml);
} catch (Exception $e) {
}
$this->assertNull($e, sprintf('PHPUnit_Util_XML::prepareString("\\x%02x") should not crash DomDocument', ord($char)));
}
示例5: testToOptionArray
public function testToOptionArray()
{
$this->dispatch('backend/admin/system_config/edit/section/admin');
$dom = PHPUnit_Util_XML::load($this->getResponse()->getBody(), true);
$select = $dom->getElementById('admin_startup_menu_item_id');
$this->assertNotEmpty($select, 'Startup Page select missed');
$options = $select->getElementsByTagName('option');
$optionsCount = $options->length;
$this->assertGreaterThan(0, $optionsCount, 'There must be present menu items at the admin backend');
$this->assertEquals('Dashboard', $options->item(0)->nodeValue, 'First element is not Dashboard');
$this->assertContains('Configuration', $options->item($optionsCount - 1)->nodeValue);
}
示例6: testGenerateClover
/**
* @dataProvider getReporterProvider
*
* @param string[] $coverageFiles
*/
public function testGenerateClover(array $coverageFiles)
{
$filename1 = $this->copyCoverageFile($coverageFiles[0], $this->targetDir);
$filename2 = $this->copyCoverageFile($coverageFiles[1], $this->targetDir);
$coverageMerger = new CoverageMerger();
$coverageMerger->addCoverageFromFile($filename1);
$coverageMerger->addCoverageFromFile($filename2);
$target = $this->targetDir . '/coverage.xml';
static::assertFileNotExists($target);
$coverageMerger->getReporter()->clover($target);
static::assertFileExists($target);
$reportXml = \PHPUnit_Util_XML::loadFile($target);
static::assertInstanceOf('DomDocument', $reportXml, 'Incorrect clover report xml was generated');
}
示例7: doXmlTag
/**
* @param array $options
* @param DOMDocument $actual
* @return boolean
* @since Method available since Release 3.3.0
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
*/
protected static function doXmlTag(array $options, DOMDocument $actual)
{
$tags = PHPUnit_Util_XML::findNodes($actual, $options);
return count($tags) > 0 && $tags[0] instanceof DOMNode;
}
示例8: addSkippedTest
/**
* Skipped test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
* @since Method available since Release 3.0.0
*/
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
if ($this->logIncompleteSkipped) {
$error = $this->document->createElement('error');
$error->setAttribute('type', get_class($e));
$error->appendChild($this->document->createCDATASection(PHPUnit_Util_XML::convertToUtf8("Skipped Test\n" . PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE))));
$this->currentTestCase->appendChild($error);
$this->testSuiteErrors[$this->testSuiteLevel]++;
} else {
$this->attachCurrentTestCase = FALSE;
}
}
示例9: loadFile
/**
* @param $filename
* @param bool|false $isHtml
* @param bool|false $xinclude
* @param bool|false $strict
*
* @return \DOMDocument
*/
public function loadFile($filename, $isHtml = false, $xinclude = false, $strict = false)
{
return \PHPUnit_Util_XML::loadFile($filename, $isHtml, $xinclude, $strict);
}
示例10: process
/**
* @param PHPUnit_Framework_TestResult $result
*/
public function process(PHPUnit_Framework_TestResult $result)
{
$sutData = $result->getCodeCoverageInformation();
$sutFiles = PHPUnit_Util_CodeCoverage::getSummary($sutData, TRUE);
$allData = $result->getCodeCoverageInformation(FALSE);
$allFiles = PHPUnit_Util_CodeCoverage::getSummary($allData, TRUE);
$testFiles = array_diff(array_keys($allFiles), array_keys($sutFiles));
foreach (array_keys($allFiles) as $key) {
if (!@in_array($key, $testFiles)) {
unset($allFiles[$key]);
}
}
$allCommonPath = PHPUnit_Util_Filesystem::reducePaths($allFiles);
$sutCommonPath = PHPUnit_Util_Filesystem::reducePaths($sutFiles);
$testFiles = $allFiles;
unset($allData);
unset($allFiles);
unset($sutData);
$testToCoveredLinesMap = array();
$time = time();
foreach ($sutFiles as $filename => $data) {
$fullPath = $sutCommonPath . DIRECTORY_SEPARATOR . $filename;
if (file_exists($fullPath)) {
$fullPath = realpath($fullPath);
$document = new DOMDocument('1.0', 'UTF-8');
$document->formatOutput = TRUE;
$coveredFile = $document->createElement('coveredFile');
$coveredFile->setAttribute('fullPath', $fullPath);
$coveredFile->setAttribute('shortenedPath', $filename);
$coveredFile->setAttribute('generated', $time);
$coveredFile->setAttribute('phpunit', PHPUnit_Runner_Version::id());
$document->appendChild($coveredFile);
$lines = file($fullPath, FILE_IGNORE_NEW_LINES);
$lineNum = 1;
foreach ($lines as $line) {
if (isset($data[$lineNum])) {
if (is_array($data[$lineNum])) {
$count = count($data[$lineNum]);
} else {
$count = $data[$lineNum];
}
} else {
$count = -3;
}
$xmlLine = $coveredFile->appendChild($document->createElement('line'));
$xmlLine->setAttribute('lineNumber', $lineNum);
$xmlLine->setAttribute('executed', $count);
$xmlLine->appendChild($document->createElement('body', htmlspecialchars(PHPUnit_Util_XML::convertToUtf8($line), ENT_COMPAT, 'UTF-8')));
if (isset($data[$lineNum]) && is_array($data[$lineNum])) {
$xmlTests = $document->createElement('tests');
$xmlLine->appendChild($xmlTests);
foreach ($data[$lineNum] as $test) {
$xmlTest = $xmlTests->appendChild($document->createElement('test'));
if ($test instanceof PHPUnit_Framework_TestCase) {
$xmlTest->setAttribute('name', $test->getName());
$xmlTest->setAttribute('status', $test->getStatus());
if ($test->hasFailed()) {
$xmlTest->appendChild($document->createElement('message', htmlspecialchars(PHPUnit_Util_XML::convertToUtf8($test->getStatusMessage()), ENT_COMPAT, 'UTF-8')));
}
$class = new ReflectionClass($test);
$testFullPath = $class->getFileName();
$testShortenedPath = str_replace($allCommonPath, '', $testFullPath);
$methodName = $test->getName(FALSE);
if ($class->hasMethod($methodName)) {
$method = $class->getMethod($methodName);
$startLine = $method->getStartLine();
$xmlTest->setAttribute('class', $class->getName());
$xmlTest->setAttribute('fullPath', $testFullPath);
$xmlTest->setAttribute('shortenedPath', $testShortenedPath);
$xmlTest->setAttribute('line', $startLine);
if (!isset($testToCoveredLinesMap[$testFullPath][$startLine])) {
$testToCoveredLinesMap[$testFullPath][$startLine] = array();
}
if (!isset($testToCoveredLinesMap[$testFullPath][$startLine][$fullPath])) {
$testToCoveredLinesMap[$testFullPath][$startLine][$fullPath] = array('coveredLines' => array($lineNum), 'shortenedPath' => $filename);
} else {
$testToCoveredLinesMap[$testFullPath][$startLine][$fullPath]['coveredLines'][] = $lineNum;
}
}
}
}
}
$lineNum++;
}
$document->save(sprintf('%s%s.xml', $this->directory, PHPUnit_Util_Filesystem::getSafeFilename(str_replace(DIRECTORY_SEPARATOR, '_', $filename))));
}
}
foreach ($testFiles as $filename => $data) {
$fullPath = $allCommonPath . DIRECTORY_SEPARATOR . $filename;
if (file_exists($fullPath)) {
$document = new DOMDocument('1.0', 'UTF-8');
$document->formatOutput = TRUE;
$testFile = $document->createElement('testFile');
$testFile->setAttribute('fullPath', $fullPath);
$testFile->setAttribute('shortenedPath', $filename);
$testFile->setAttribute('generated', $time);
$testFile->setAttribute('phpunit', PHPUnit_Runner_Version::id());
//.........这里部分代码省略.........
示例11: __construct
private function __construct($testCase, $html)
{
$this->testCase = $testCase;
$this->doc = PHPUnit_Util_XML::load($html, true);
$this->domxpath = new DOMXPath($this->doc);
}
示例12: notEqualValues
protected function notEqualValues()
{
// cyclic dependencies
$book1 = new Book();
$book1->author = new Author('Terry Pratchett');
$book1->author->books[] = $book1;
$book2 = new Book();
$book2->author = new Author('Terry Pratch');
$book2->author->books[] = $book2;
$book3 = new Book();
$book3->author = 'Terry Pratchett';
$book4 = new stdClass();
$book4->author = 'Terry Pratchett';
$object1 = new SampleClass(4, 8, 15);
$object2 = new SampleClass(16, 23, 42);
$object3 = new SampleClass(4, 8, 15);
$storage1 = new SplObjectStorage();
$storage1->attach($object1);
$storage2 = new SplObjectStorage();
$storage2->attach($object3);
// same content, different object
// cannot use $filesDirectory, because neither setUp() nor
// setUpBeforeClass() are executed before the data providers
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'foo.xml';
return array(array('a', 'b'), array('a', 'A'), array('9E6666666', '9E7777777'), array(1, 2), array(2, 1), array(2.3, 4.2), array(2.3, 4.2, 0.5), array(array(2.3), array(4.2), 0.5), array(array(array(2.3)), array(array(4.2)), 0.5), array(new Struct(2.3), new Struct(4.2), 0.5), array(array(new Struct(2.3)), array(new Struct(4.2)), 0.5), array(NAN, NAN), array(array(), array(0 => 1)), array(array(0 => 1), array()), array(array(0 => NULL), array()), array(array(0 => 1, 1 => 2), array(0 => 1, 1 => 3)), array(array('a', 'b' => array(1, 2)), array('a', 'b' => array(2, 1))), array(new SampleClass(4, 8, 15), new SampleClass(16, 23, 42)), array($object1, $object2), array($book1, $book2), array($book3, $book4), array(fopen($file, 'r'), fopen($file, 'r')), array($storage1, $storage2), array(PHPUnit_Util_XML::load('<root></root>'), PHPUnit_Util_XML::load('<bar/>')), array(PHPUnit_Util_XML::load('<foo attr1="bar"/>'), PHPUnit_Util_XML::load('<foo attr1="foobar"/>')), array(PHPUnit_Util_XML::load('<foo> bar </foo>'), PHPUnit_Util_XML::load('<foo />')), array(PHPUnit_Util_XML::load('<foo xmlns="urn:myns:bar"/>'), PHPUnit_Util_XML::load('<foo xmlns="urn:notmyns:bar"/>')), array(PHPUnit_Util_XML::load('<foo> bar </foo>'), PHPUnit_Util_XML::load('<foo> bir </foo>')), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/New_York'))), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 03:13:35', new DateTimeZone('America/New_York')), 3500), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 05:13:35', new DateTimeZone('America/New_York')), 3500), array(new DateTime('2013-03-29', new DateTimeZone('America/New_York')), new DateTime('2013-03-30', new DateTimeZone('America/New_York'))), array(new DateTime('2013-03-29', new DateTimeZone('America/New_York')), new DateTime('2013-03-30', new DateTimeZone('America/New_York')), 43200), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago'))), array(new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/New_York')), new DateTime('2013-03-29 04:13:35', new DateTimeZone('America/Chicago')), 3500), array(new DateTime('2013-03-30', new DateTimeZone('America/New_York')), new DateTime('2013-03-30', new DateTimeZone('America/Chicago'))), array(new DateTime('2013-03-29T05:13:35-0600'), new DateTime('2013-03-29T04:13:35-0600')), array(new DateTime('2013-03-29T05:13:35-0600'), new DateTime('2013-03-29T05:13:35-0500')), array(new SampleClass(4, 8, 15), FALSE), array(FALSE, new SampleClass(4, 8, 15)), array(array(0 => 1, 1 => 2), FALSE), array(FALSE, array(0 => 1, 1 => 2)), array(array(), new stdClass()), array(new stdClass(), array()), array(0, 'Foobar'), array('Foobar', 0), array(3, acos(8)), array(acos(8), 3));
}
示例13: process
/**
* @param PHPUnit_Framework_TestResult $result
*/
public function process(PHPUnit_Framework_TestResult $result, $minLines = 5, $minMatches = 70)
{
$codeCoverage = $result->getCodeCoverageInformation();
$summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage);
$files = array_keys($summary);
$metrics = new PHPUnit_Util_Metrics_Project($files, $summary, TRUE, $minLines, $minMatches);
$document = new DOMDocument('1.0', 'UTF-8');
$document->formatOutput = TRUE;
$cpd = $document->createElement('pmd-cpd');
$cpd->setAttribute('version', 'PHPUnit ' . PHPUnit_Runner_Version::id());
$document->appendChild($cpd);
foreach ($metrics->getDuplicates() as $duplicate) {
$xmlDuplication = $cpd->appendChild($document->createElement('duplication'));
$xmlDuplication->setAttribute('lines', $duplicate['numLines']);
$xmlDuplication->setAttribute('tokens', $duplicate['numTokens']);
$xmlFile = $xmlDuplication->appendChild($document->createElement('file'));
$xmlFile->setAttribute('path', $duplicate['fileA']->getPath());
$xmlFile->setAttribute('line', $duplicate['firstLineA']);
$xmlFile = $xmlDuplication->appendChild($document->createElement('file'));
$xmlFile->setAttribute('path', $duplicate['fileB']->getPath());
$xmlFile->setAttribute('line', $duplicate['firstLineB']);
$xmlDuplication->appendChild($document->createElement('codefragment', PHPUnit_Util_XML::prepareString(join('', array_slice($duplicate['fileA']->getLines(), $duplicate['firstLineA'] - 1, $duplicate['numLines'])))));
}
$this->write($document->saveXML());
$this->flush();
}
示例14: testTranslationFileIsValid
/**
* @dataProvider provideTranslationFiles
*/
public function testTranslationFileIsValid($filePath)
{
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
}
示例15: testLoadBoolean
/**
* @expectedException PHPUnit_Framework_Exception
* @expectedExceptionMessage Could not load XML from boolean
*/
public function testLoadBoolean()
{
PHPUnit_Util_XML::load(false);
}