Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
test_invalid_links.inc
1 <?php
28 {
29 
30 
37  public static function getName()
38  {
39  return 'Invalid Matrix Links Test';
40 
41  }//end getName()
42 
43 
50  public static function getDescription()
51  {
52  return 'A test to check for invalid Matrix links in content areas';
53 
54  }//end getDescription()
55 
56 
66  public static function test(&$messages, &$errors)
67  {
68  $status = TRUE;
69  $am = $GLOBALS['SQ_SYSTEM']->am;
70  $content_types = $am->getTypeAssetids('content_type', FALSE);
71  $pattern = '/\\.\\/\\?a=([0-9]+)/';
72  $count = 0;
73 
74  foreach ($content_types as $content_type) {
75  $error_in_content_type = FALSE;
76  $asset = $am->getAsset($content_type, '', TRUE);
77  if (is_null($asset)) {
78  $status = FALSE;
79  $count++;
80  $errors[] = 'Content Type #'.$content_type.' could not be loaded';
81  }//end if
82 
83  $html = $asset->attr('html');
84  preg_match_all($pattern, $html, $assetids);
85  foreach ($assetids[1] as $assetid) {
86  $link_asset = $am->getAsset($assetid, '', TRUE);
87  if (is_null($link_asset)) {
88  $status = FALSE;
89  if (!$error_in_content_type) $count++;
90  $error_in_content_type = TRUE;
91  $errors[] = 'A link to Asset #'.$assetid.' was found on Content Type #'.$content_type;
92  } else {
93  $am->forgetAsset($link_asset, TRUE);
94  }//end if
95  }//end foreach
96  $am->forgetAsset($asset, TRUE);
97  }//end foreach
98 
99  $errors = array_unique($errors);
100  if (!$status && !empty($count)) {
101  $messages[] = 'There are '.$count.' content types with problems found';
102  }//end if
103 
104  return $status;
105 
106  }//end test()
107 
108 }//end class
109 ?>