Пример #1
0
 /**
  * testMakeLikeArrayWithValidPatterns()
  *
  * Tests whether the LIKE clause produced by LinkFilter::makeLikeArray($pattern, $protocol)
  * will find one of the URL indexes produced by wfMakeUrlIndexes($url)
  *
  * @dataProvider provideValidPatterns
  *
  * @param string $protocol Protocol, e.g. 'http://' or 'mailto:'
  * @param string $pattern Search pattern to feed to LinkFilter::makeLikeArray
  * @param string $url URL to feed to wfMakeUrlIndexes
  * @param bool $shouldBeFound Should the URL be found? (defaults true)
  */
 function testMakeLikeArrayWithValidPatterns($protocol, $pattern, $url, $shouldBeFound = true)
 {
     $indexes = wfMakeUrlIndexes($url);
     $likeArray = LinkFilter::makeLikeArray($pattern, $protocol);
     $this->assertTrue($likeArray !== false, "LinkFilter::makeLikeArray('{$pattern}', '{$protocol}') returned false on a valid pattern");
     $regex = $this->createRegexFromLIKE($likeArray);
     $debugmsg = "Regex: '" . $regex . "'\n";
     $debugmsg .= count($indexes) . " index(es) created by wfMakeUrlIndexes():\n";
     $matches = 0;
     foreach ($indexes as $index) {
         $matches += preg_match($regex, $index);
         $debugmsg .= "\t'{$index}'\n";
     }
     if ($shouldBeFound) {
         $this->assertTrue($matches > 0, "Search pattern '{$protocol}{$pattern}' does not find url '{$url}' \n{$debugmsg}");
     } else {
         $this->assertFalse($matches > 0, "Search pattern '{$protocol}{$pattern}' should not find url '{$url}' \n{$debugmsg}");
     }
 }
Пример #2
0
 /**
  * Get an array of externallinks insertions. Skips the names specified in $existing
  * @param array $existing
  * @return array
  */
 private function getExternalInsertions($existing = array())
 {
     $arr = array();
     $diffs = array_diff_key($this->mExternals, $existing);
     foreach ($diffs as $url => $dummy) {
         foreach (wfMakeUrlIndexes($url) as $index) {
             $arr[] = array('el_id' => $this->mDb->nextSequenceValue('externallinks_el_id_seq'), 'el_from' => $this->mId, 'el_to' => $url, 'el_index' => $index);
         }
     }
     return $arr;
 }
Пример #3
0
 /**
  * @dataProvider provideMakeUrlIndexes()
  * @covers ::wfMakeUrlIndexes
  */
 public function testMakeUrlIndexes($url, $expected)
 {
     $index = wfMakeUrlIndexes($url);
     $this->assertEquals($expected, $index, "wfMakeUrlIndexes(\"{$url}\")");
 }
Пример #4
0
 /**
  * Get an array of externallinks insertions. Skips the names specified in $existing
  * @private
  */
 function getExternalInsertions($existing = array())
 {
     $arr = array();
     $diffs = array_diff_key($this->mExternals, $existing);
     foreach ($diffs as $url => $dummy) {
         foreach (wfMakeUrlIndexes($url) as $index) {
             $arr[] = array('el_from' => $this->mId, 'el_to' => $url, 'el_index' => $index);
         }
     }
     return $arr;
 }