Completed
Push — master ( 3f2ac7...f065be )
by Dylan
02:41
created
code/extenstions/SEOToolboxControllerExtension.php 2 patches
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
     private $excludeTags    = array();
19 19
     private $maxLinks       = 0;
20 20
 
21
-    public function index(){
21
+    public function index() {
22 22
         $this->addAutomatedLinks();
23 23
 
24 24
         // If we have a crawl request check the CrawlID so we're sure we didn't hit another SS site running our module
25
-        if( $crawl_id = $this->owner->request->getHeader('X-Crawl-Id') ){
26
-            return( $crawl_id == GlobalAutoLinkSettings::get_current()->CrawlID )
25
+        if ($crawl_id = $this->owner->request->getHeader('X-Crawl-Id')) {
26
+            return($crawl_id == GlobalAutoLinkSettings::get_current()->CrawlID)
27 27
                 ? $this->crawl_response()
28 28
                 : $this->owner->redirect(SEOTestSiteTreeController::getPermissionDeniedPage()->Link());
29 29
         }
@@ -31,15 +31,15 @@  discard block
 block discarded – undo
31 31
         return array();
32 32
     }
33 33
 
34
-    private function crawl_response(){
34
+    private function crawl_response() {
35 35
         // Encoded version to detect which fields are being used
36 36
         $customize = array();
37 37
         $dbFields  = Config::inst()->get($this->owner->ClassName, 'db');
38
-        if(is_array($dbFields)) {
39
-            foreach ( $dbFields as $field => $type) {
38
+        if (is_array($dbFields)) {
39
+            foreach ($dbFields as $field => $type) {
40 40
                 if (strtolower($type) == 'htmltext') {
41 41
                     $data = ($this->owner->hasMethod($field)) ? $this->owner->$field() : $this->owner->$field;
42
-                    if($data){
42
+                    if ($data) {
43 43
                         $tmp = new HTMLText('tmp');
44 44
                         $tmp->setValue($data);
45 45
                         $data = base64_encode($tmp->forTemplate());
@@ -90,31 +90,31 @@  discard block
 block discarded – undo
90 90
      *
91 91
      * @return void
92 92
      */
93
-    public function addAutomatedLinks(){
94
-        if( GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage' ) {
93
+    public function addAutomatedLinks() {
94
+        if (GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage') {
95 95
             $this->getSettings();
96
-            if( !$this->addLinks ) {
96
+            if (!$this->addLinks) {
97 97
                 return;
98 98
             }
99 99
 
100
-            foreach( $this->getSettings()->IncludeInFields() as $field ){
100
+            foreach ($this->getSettings()->IncludeInFields() as $field) {
101 101
                 // Check that the field provided by user exists in this object, is of type HTMLText and has content
102
-                if( AutomatedLink::isFieldParsable( $this->owner->data(), $field ) ){
102
+                if (AutomatedLink::isFieldParsable($this->owner->data(), $field)) {
103 103
 
104 104
                     // Create dummy object so we can parse the HTML
105
-                    $dummy = new HTMLText( $field );
106
-                    $dummy->setValue( $this->owner->$field );
105
+                    $dummy = new HTMLText($field);
106
+                    $dummy->setValue($this->owner->$field);
107 107
                     // Create DOMDocument Object
108
-                    $content = mb_convert_encoding( $dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding );
108
+                    $content = mb_convert_encoding($dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding);
109 109
                     $dom = AutomatedLink::constructDOMDocument($content);
110 110
 
111 111
                     // Check current link count and if it's already exceeded do nothing
112
-                    $this->linkCount += (int) $dom->getElementsByTagName( 'a' )->length;
113
-                    if( $this->linkCount >= $this->maxLinks ) {
112
+                    $this->linkCount += (int) $dom->getElementsByTagName('a')->length;
113
+                    if ($this->linkCount >= $this->maxLinks) {
114 114
                         return;
115 115
                     }
116 116
 
117
-                    $parsed = $this->parseField( $dom, $field );
117
+                    $parsed = $this->parseField($dom, $field);
118 118
                     $this->owner->data()->$field = $parsed;
119 119
                     $this->owner->$field         = $parsed;
120 120
                 }
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
      * @param array $hash_tags
131 131
      * @return array
132 132
      */
133
-    private function hashTags( DOMDocument $html, $hash_tags ){
133
+    private function hashTags(DOMDocument $html, $hash_tags) {
134 134
         $excluded = array();
135
-        foreach( $hash_tags as $eTag ){
136
-            while( $tags = $html->getElementsByTagName( $eTag ) ){
137
-                if( !$tags->length ) break 1;
138
-                $tag	= $tags->item(0);
139
-                $value  = $html->saveHTML( $tag );
140
-                $key    = (string) crc32( $value );
135
+        foreach ($hash_tags as $eTag) {
136
+            while ($tags = $html->getElementsByTagName($eTag)) {
137
+                if (!$tags->length) break 1;
138
+                $tag = $tags->item(0);
139
+                $value  = $html->saveHTML($tag);
140
+                $key    = (string) crc32($value);
141 141
 
142 142
                 // Convert back children nodes of this node if they were already hashed
143
-                $excluded[$key] = str_replace( array_keys( $excluded ), array_values( $excluded ), $value );
143
+                $excluded[$key] = str_replace(array_keys($excluded), array_values($excluded), $value);
144 144
 
145
-                $tag->parentNode->replaceChild( $html->createTextNode( $key ), $tag );
145
+                $tag->parentNode->replaceChild($html->createTextNode($key), $tag);
146 146
             }
147 147
         }
148 148
 
@@ -157,38 +157,38 @@  discard block
 block discarded – undo
157 157
      * @param string $content
158 158
      * @return array
159 159
      */
160
-    public function addLinkToContent(AutomatedLink $link, &$content){
160
+    public function addLinkToContent(AutomatedLink $link, &$content) {
161 161
         $links  = array();
162
-        $max    = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX;
163
-        $escape = (string) preg_quote( $link->Phrase, '/' );
164
-        $regex  = (string) ( $link->CaseSensitive ) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i";
162
+        $max    = (int) ($link->MaxLinksPerPage > 0) ? $link->MaxLinksPerPage : PHP_INT_MAX;
163
+        $escape = (string) preg_quote($link->Phrase, '/');
164
+        $regex  = (string) ($link->CaseSensitive) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i";
165 165
 
166 166
         // Count the matches
167
-        preg_match_all( $regex, $content, $count );
168
-        $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0;
169
-        if( $count < 1 ) $links;
167
+        preg_match_all($regex, $content, $count);
168
+        $count = (is_array($count) && isset($count[0])) ? count($count[0]) : 0;
169
+        if ($count < 1) $links;
170 170
 
171
-        if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) {
171
+        if (isset($this->maxLinksPerPage[$link->ID])) {
172 172
             $max -= $this->maxLinksPerPage[$link->ID];
173
-        } else {
173
+        }else {
174 174
             $this->maxLinksPerPage[$link->ID] = 0;
175 175
         }
176 176
 
177
-        for( $x = 0; $x < $count; $x++ ){
177
+        for ($x = 0; $x < $count; $x++) {
178 178
             // Stop adding links if we reached the link or page limit
179
-            if( $x >= $max || $this->linkCount >= $this->maxLinks ) break;
179
+            if ($x >= $max || $this->linkCount >= $this->maxLinks) break;
180 180
 
181 181
             // Check if there is anything else to replace else stop
182
-            preg_match( $regex, $content, $match );
183
-            if( !is_array( $match ) || !count( $match ) ) break;
182
+            preg_match($regex, $content, $match);
183
+            if (!is_array($match) || !count($match)) break;
184 184
 
185
-            if( !$html = (string) $link->getHTML( $match[0] ) ) continue;
186
-            $key            = (string) crc32( $html );
187
-            $links[ $key ]  = (string) $html;
185
+            if (!$html = (string) $link->getHTML($match[0])) continue;
186
+            $key            = (string) crc32($html);
187
+            $links[$key]  = (string) $html;
188 188
 
189
-            $content = preg_replace( $regex, $key, $content, 1 );
189
+            $content = preg_replace($regex, $key, $content, 1);
190 190
             $this->linkCount++;
191
-            $this->maxLinksPerPage[ $link->ID ]++;
191
+            $this->maxLinksPerPage[$link->ID]++;
192 192
         }
193 193
 
194 194
         return $links;
@@ -201,24 +201,24 @@  discard block
 block discarded – undo
201 201
      * @param String $field
202 202
      * @return string
203 203
      */
204
-    private function parseField( DOMDocument $html, $field ){
205
-        $this->owner->extend( 'beforeParseField', $html, $field );
204
+    private function parseField(DOMDocument $html, $field) {
205
+        $this->owner->extend('beforeParseField', $html, $field);
206 206
 
207 207
         // Remove Tags from Content we wown't be using
208 208
         $excluded   = $this->hashTags($html, $this->excludeTags);
209
-        $body       = (string)$html->saveHTML( $html->getElementsByTagName('body')->item(0) );
210
-        $content    = preg_replace( array( '/\<body\>/is', '/\<\/body\>/is' ), '', $body, 1 );
209
+        $body       = (string) $html->saveHTML($html->getElementsByTagName('body')->item(0));
210
+        $content    = preg_replace(array('/\<body\>/is', '/\<\/body\>/is'), '', $body, 1);
211 211
 
212
-        foreach( AutomatedLink::get()->sort('Priority') as $link){
213
-            if( $this->linkCount < $this->maxLinks && $link->canBeAdded( $this->owner, $field ) ) {
212
+        foreach (AutomatedLink::get()->sort('Priority') as $link) {
213
+            if ($this->linkCount < $this->maxLinks && $link->canBeAdded($this->owner, $field)) {
214 214
                 $links = $this->addLinkToContent($link, $content);
215
-                if( is_array($links) && count($links) > 0 ) {
216
-                    $excluded = $excluded + $links;
215
+                if (is_array($links) && count($links) > 0) {
216
+                    $excluded = $excluded+$links;
217 217
                 }
218 218
             }
219 219
         }
220 220
 
221 221
         // Re-add the excluded Tags
222
-        return str_replace( array_keys( $excluded ), array_values( $excluded ), $content );
222
+        return str_replace(array_keys($excluded), array_values($excluded), $content);
223 223
     }
224 224
 }
Please login to merge, or discard this patch.
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -73,12 +73,16 @@  discard block
 block discarded – undo
73 73
     private function getSettings() {
74 74
         if ($this->settings === null) {
75 75
             $this->settings = GlobalAutoLinkSettings::get_current();
76
-            if (!$this->settings) return $this->addLinks = false;
76
+            if (!$this->settings) {
77
+                return $this->addLinks = false;
78
+            }
77 79
 
78 80
             $this->excludeTags = (array) $this->settings->ExcludeTags();
79 81
             $this->maxLinks = (int) ($this->settings->MaxLinksPerPage) ? $this->settings->MaxLinksPerPage : PHP_INT_MAX;
80 82
 
81
-            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) $this->addLinks = false;
83
+            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) {
84
+                $this->addLinks = false;
85
+            }
82 86
         }
83 87
 
84 88
         return $this->settings;
@@ -134,7 +138,9 @@  discard block
 block discarded – undo
134 138
         $excluded = array();
135 139
         foreach( $hash_tags as $eTag ){
136 140
             while( $tags = $html->getElementsByTagName( $eTag ) ){
137
-                if( !$tags->length ) break 1;
141
+                if( !$tags->length ) {
142
+                    break 1;
143
+                }
138 144
                 $tag	= $tags->item(0);
139 145
                 $value  = $html->saveHTML( $tag );
140 146
                 $key    = (string) crc32( $value );
@@ -166,7 +172,9 @@  discard block
 block discarded – undo
166 172
         // Count the matches
167 173
         preg_match_all( $regex, $content, $count );
168 174
         $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0;
169
-        if( $count < 1 ) $links;
175
+        if( $count < 1 ) {
176
+            $links;
177
+        }
170 178
 
171 179
         if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) {
172 180
             $max -= $this->maxLinksPerPage[$link->ID];
@@ -176,13 +184,19 @@  discard block
 block discarded – undo
176 184
 
177 185
         for( $x = 0; $x < $count; $x++ ){
178 186
             // Stop adding links if we reached the link or page limit
179
-            if( $x >= $max || $this->linkCount >= $this->maxLinks ) break;
187
+            if( $x >= $max || $this->linkCount >= $this->maxLinks ) {
188
+                break;
189
+            }
180 190
 
181 191
             // Check if there is anything else to replace else stop
182 192
             preg_match( $regex, $content, $match );
183
-            if( !is_array( $match ) || !count( $match ) ) break;
193
+            if( !is_array( $match ) || !count( $match ) ) {
194
+                break;
195
+            }
184 196
 
185
-            if( !$html = (string) $link->getHTML( $match[0] ) ) continue;
197
+            if( !$html = (string) $link->getHTML( $match[0] ) ) {
198
+                continue;
199
+            }
186 200
             $key            = (string) crc32( $html );
187 201
             $links[ $key ]  = (string) $html;
188 202
 
Please login to merge, or discard this patch.
code/controllers/SEOTestSiteTreeController.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
         Requirements::clear();
17 17
 
18
-        if (!Member::currentUser()  || !Permission::check('CMS_ACCESS_SEOToolboxAdmin')){
18
+        if (!Member::currentUser() || !Permission::check('CMS_ACCESS_SEOToolboxAdmin')) {
19 19
             return $this->redirect(Security::login_url().'?BackURL=/seotest');
20 20
         }
21 21
 
@@ -151,9 +151,9 @@  discard block
 block discarded – undo
151 151
      * @param string $data
152 152
      * @return array
153 153
      */
154
-    private function getHTMLFieldsData($data){
154
+    private function getHTMLFieldsData($data) {
155 155
         preg_match_all('/\[\*\*\[(.*?)\]\*\*\[(.*?)\]\*\*\]/im', $data, $matches);
156
-        foreach( $matches[2] as $key => $field_text ){
156
+        foreach ($matches[2] as $key => $field_text) {
157 157
             $matches[2][$key] = base64_decode($field_text);
158 158
             $matches[3][$key] = preg_replace('/[\s]+/mu', ' ', strip_tags($matches[2][$key]));
159 159
         }
@@ -168,38 +168,38 @@  discard block
 block discarded – undo
168 168
      * @param (null|string) $agent
169 169
      * @return array
170 170
      */
171
-    public function loadPage($url, $agent=null){
171
+    public function loadPage($url, $agent = null) {
172 172
         $crawl_id = GlobalAutoLinkSettings::get_current()->CrawlID;
173 173
         $ch = curl_init();
174
-        curl_setopt( $ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url );
175
-        curl_setopt( $ch, CURLOPT_HEADER, true );
176
-        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
177
-        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
178
-        curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
179
-        curl_setopt( $ch, CURLOPT_USERAGENT, $agent );
180
-        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
181
-        curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
182
-        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
183
-        curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'X-Crawl-Id: '.$crawl_id ) );
184
-        $data = curl_exec( $ch );
174
+        curl_setopt($ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url);
175
+        curl_setopt($ch, CURLOPT_HEADER, true);
176
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
177
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
178
+        curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
179
+        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
180
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
181
+        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
182
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
183
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Crawl-Id: '.$crawl_id));
184
+        $data = curl_exec($ch);
185 185
 
186 186
         $fetched        = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_PATH);
187
-        $header_size    = curl_getinfo( $ch, CURLINFO_HEADER_SIZE );
188
-        $header 	    = explode( "\r\n\r\n", substr( $data, 0, $header_size ) );
189
-        array_pop( $header ); // Remove last element as it will always be empty
190
-        $header = array_pop( $header );
191
-        $body   = preg_replace('/[\s]+/mu', ' ', substr( $data, $header_size ));
187
+        $header_size    = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
188
+        $header = explode("\r\n\r\n", substr($data, 0, $header_size));
189
+        array_pop($header); // Remove last element as it will always be empty
190
+        $header = array_pop($header);
191
+        $body   = preg_replace('/[\s]+/mu', ' ', substr($data, $header_size));
192 192
 
193
-        curl_close( $ch );
193
+        curl_close($ch);
194 194
 
195
-        if( !strpos( $header, ' 200 ' ) ) {
196
-            return array( 'headers' => false, 'body' => false );
195
+        if (!strpos($header, ' 200 ')) {
196
+            return array('headers' => false, 'body' => false);
197 197
         }
198 198
 
199 199
         $field_data = $this->getHTMLFieldsData($body);
200 200
         $body = str_replace($field_data[0], $field_data[2], $body);
201 201
 
202
-        return array( 'headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched );
202
+        return array('headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched);
203 203
     }
204 204
 
205 205
     /**
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -113,8 +113,9 @@
 block discarded – undo
113 113
                 $phrases = array_merge($phrases, $matches[$commands['find_pos']]);
114 114
             }
115 115
 
116
-            if (isset($commands['replace']))
117
-                $html = preg_replace($commands['replace'], ' ', $html);
116
+            if (isset($commands['replace'])) {
117
+                            $html = preg_replace($commands['replace'], ' ', $html);
118
+            }
118 119
         }
119 120
 
120 121
         // Remove the empty elements
Please login to merge, or discard this patch.
_config.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@
 block discarded – undo
6 6
  *
7 7
  */
8 8
 
9
-define( 'SEOTOOLBOX_DIR', str_replace( Director::baseFolder().'/', '', __DIR__ ) );
9
+define('SEOTOOLBOX_DIR', str_replace(Director::baseFolder().'/', '', __DIR__));
10 10
 
11 11
 Config::inst()->update('SEOToolboxAdmin', 'menu_icon', SEOTOOLBOX_DIR.'/code/admin/icon/seotoolbox-icon.png');
12
-Config::inst()->update('LeftAndMain','extra_requirements_javascript', array(SEOTOOLBOX_DIR.'/js/seo_page_analyzer.js'));
13
-Config::inst()->update('LeftAndMain','extra_requirements_css', array(SEOTOOLBOX_DIR.'/css/seo_page_analyzer.css'));
12
+Config::inst()->update('LeftAndMain', 'extra_requirements_javascript', array(SEOTOOLBOX_DIR.'/js/seo_page_analyzer.js'));
13
+Config::inst()->update('LeftAndMain', 'extra_requirements_css', array(SEOTOOLBOX_DIR.'/css/seo_page_analyzer.css'));
14 14
 
15 15
 CMSMenu::add_link('seotest', 'Run Crawler', '/seotest', 9, array('target' => '_blank'));
16 16
 Requirements::customCSS('.icon.icon-16.icon-seotest{background:url('.SEOTOOLBOX_DIR.'/code/admin/icon/crawl-icon.png)}');
17 17
 
18
-if(Director::is_cli()){
18
+if (Director::is_cli()) {
19 19
     Config::inst()->update('Director', 'environment_type', 'dev');
20 20
 }
Please login to merge, or discard this patch.
tests/AutomatedLinkTest.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
79 79
      * Renders the passed $page and returns all links found if any
80 80
      *
81 81
      * @param SiteTree $page
82
-     * @return DOMNameList
82
+     * @return DOMNodeList
83 83
      */
84 84
     public static function getLinksFromPage(SiteTree $page){
85 85
         $dom = self::getPageDOM($page);
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
     /**
14 14
      * Test that links are included in the content field
15 15
      */
16
-    public function testInsertion(){
17
-        $this->objFromFixture('AutomatedLink','link');
16
+    public function testInsertion() {
17
+        $this->objFromFixture('AutomatedLink', 'link');
18 18
         $page   = $this->createPage('<p>Checking if phrase is replaced</p>');
19 19
         $link   = $this->getLinkFromPage($page);
20 20
         $this->assertTrue($link->nodeValue === 'phrase', 'Link wasn\'t created');
@@ -23,41 +23,41 @@  discard block
 block discarded – undo
23 23
     /**
24 24
      * Test the individual properties of the automated link
25 25
      */
26
-    public function testProperties(){
27
-        $this->objFromFixture('AutomatedLink','link2');
26
+    public function testProperties() {
27
+        $this->objFromFixture('AutomatedLink', 'link2');
28 28
 
29 29
         $page   = self::createPage('<p>Checking if properties is with correct props</p>');
30 30
         $link   = self::getLinkFromPage($page);
31 31
 
32
-        $this->assertTrue( $link->nodeValue === 'properties', 'Phrase did not match' );
33
-        $this->assertTrue( $link->getAttribute('title') === 'test title', 'Title did not match' );
34
-        $this->assertTrue( $link->getAttribute('href') === '#test-anchor', 'Anchor did not match' );
35
-        $this->assertTrue( $link->getAttribute('target') === '_blank', 'Target did not match' );
36
-        $this->assertTrue( $link->getAttribute('rel') === 'nofollow', 'Rel did not match' );
32
+        $this->assertTrue($link->nodeValue === 'properties', 'Phrase did not match');
33
+        $this->assertTrue($link->getAttribute('title') === 'test title', 'Title did not match');
34
+        $this->assertTrue($link->getAttribute('href') === '#test-anchor', 'Anchor did not match');
35
+        $this->assertTrue($link->getAttribute('target') === '_blank', 'Target did not match');
36
+        $this->assertTrue($link->getAttribute('rel') === 'nofollow', 'Rel did not match');
37 37
     }
38 38
 
39 39
     /**
40 40
      * Test that the default properties match what we expect
41 41
      */
42
-    public function testDefaultProperties(){
43
-        $this->objFromFixture('AutomatedLink','link3');
42
+    public function testDefaultProperties() {
43
+        $this->objFromFixture('AutomatedLink', 'link3');
44 44
 
45 45
         $page   = self::createPage('<p>Checking if default is correct</p>');
46 46
         $link   = self::getLinkFromPage($page);
47 47
         $auto   = AutomatedLink::get()->find('Phrase', 'default');
48 48
 
49
-        $this->assertTrue( $link->nodeValue === 'default', 'Phrase did not match' );
50
-        $this->assertTrue( $link->getAttribute('title') === '', 'Title did not match' );
51
-        $this->assertTrue( $link->getAttribute('href') === '#', 'href did not match' );
52
-        $this->assertTrue( $link->getAttribute('target') === '', 'Target did not match' );
53
-        $this->assertTrue( $link->getAttribute('rel') === '', 'Rel did not match' );
54
-        $this->assertTrue( (int) $link->getAttribute('data-id') === $auto->ID, 'data-id did not match' );
49
+        $this->assertTrue($link->nodeValue === 'default', 'Phrase did not match');
50
+        $this->assertTrue($link->getAttribute('title') === '', 'Title did not match');
51
+        $this->assertTrue($link->getAttribute('href') === '#', 'href did not match');
52
+        $this->assertTrue($link->getAttribute('target') === '', 'Target did not match');
53
+        $this->assertTrue($link->getAttribute('rel') === '', 'Rel did not match');
54
+        $this->assertTrue((int) $link->getAttribute('data-id') === $auto->ID, 'data-id did not match');
55 55
     }
56 56
 
57 57
     /**
58 58
      * Test that the default properties match what we expect
59 59
      */
60
-    public function testLimitFilter(){
60
+    public function testLimitFilter() {
61 61
         $page   = self::createPage('<p>Checking if default is created only twice. default default</p>');
62 62
         $dom    = self::getPageDOM($page);
63 63
         $links  = $dom->getElementsByTagName('a');
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     /**
68 68
      * Test that the default properties match what we expect
69 69
      */
70
-    public function testDisableFilter(){
70
+    public function testDisableFilter() {
71 71
         GlobalAutoLinkSettings::$enabled = false;
72 72
         $page   = self::createPage('<p>Checking if default is created at all when automated links are disabled.</p>');
73 73
         $links  = self::getLinksFromPage($page);
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      * @param SiteTree $page
82 82
      * @return DOMNameList
83 83
      */
84
-    public static function getLinksFromPage(SiteTree $page){
84
+    public static function getLinksFromPage(SiteTree $page) {
85 85
         $dom = self::getPageDOM($page);
86 86
         return $dom->getElementsByTagName('a');
87 87
     }
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
      * @param SiteTree $page
95 95
      * @return DOMDocument
96 96
      */
97
-    public static function getLinkFromPage(SiteTree $page){
97
+    public static function getLinkFromPage(SiteTree $page) {
98 98
         $links = self::getLinksFromPage($page);
99
-        return ( $links->length != 1 ) ? new DOMElement() : $links->item(0);
99
+        return ($links->length != 1) ? new DOMElement() : $links->item(0);
100 100
     }
101 101
 
102 102
     /**
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
      * @param string|null $content
106 106
      * @return Page
107 107
      */
108
-    public static function createPage($content=null){
109
-        $page = Page::create(array( 'Content' => $content ));
108
+    public static function createPage($content = null) {
109
+        $page = Page::create(array('Content' => $content));
110 110
         $page->write();
111 111
         return $page;
112 112
     }
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      * @param Page $page
118 118
      * @return DOMDocument
119 119
      */
120
-    public static function getPageDOM(Page $page){
120
+    public static function getPageDOM(Page $page) {
121 121
         $controller = Page_Controller::create($page);
122 122
         $controller->invokeWithExtensions('addAutomatedLinks');
123 123
         return AutomatedLink::constructDOMDocument($controller->Content);
Please login to merge, or discard this patch.
tests/GlobalAutoLinkSettingsTest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
     /**
14 14
      * Test Max Links per page
15 15
      */
16
-    public function testMaxLinksPerPage(){
17
-        $this->objFromFixture('AutomatedLink','link');
18
-        $this->objFromFixture('AutomatedLink','link2');
19
-        $this->objFromFixture('AutomatedLink','link3');
16
+    public function testMaxLinksPerPage() {
17
+        $this->objFromFixture('AutomatedLink', 'link');
18
+        $this->objFromFixture('AutomatedLink', 'link2');
19
+        $this->objFromFixture('AutomatedLink', 'link3');
20 20
 
21 21
         $settings = GlobalAutoLinkSettings::get()->first();
22 22
         $settings->MaxLinksPerPage = 1;
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
     /**
31 31
      * Test that links are not created inside of exclude tags
32 32
      */
33
-    public function testExcludeTags(){
33
+    public function testExcludeTags() {
34 34
         $settings = GlobalAutoLinkSettings::get()->first();
35 35
         $settings->MaxLinksPerPage = 0;
36 36
         $settings->write();
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     /**
46 46
      * Test that links are included in all the specified fields
47 47
      */
48
-    public function testIncludeIn(){
48
+    public function testIncludeIn() {
49 49
         $settings = GlobalAutoLinkSettings::get()->first();
50 50
         $settings->IncludeIn = 'Content, Introduction';
51 51
         $settings->write();
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 /**
83 83
  * Simple test page to test settings
84 84
  */
85
-class TestPage extends Page implements TestOnly{
85
+class TestPage extends Page implements TestOnly {
86 86
     private static $db = array(
87 87
         'Introduction' => 'HTMLText'
88 88
     );
Please login to merge, or discard this patch.