Skip to content

Commit b150839

Browse files
authored
Merge pull request #164 from iMattPro/tests
Update tests
2 parents 3d52da0 + c415566 commit b150839

38 files changed

Lines changed: 135 additions & 123 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ matrix:
1717
env: DB=mysqli
1818
- php: 7.3
1919
env: DB=mysqli
20-
- php: 7.4snapshot
20+
- php: 7.4
2121
env: DB=mysqli
2222
- php: nightly
2323
env: DB=mysqli

entity/page.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,12 @@ public function set_content($content)
624624
/**
625625
* Check if bbcode is enabled on the content
626626
*
627-
* @return bool
627+
* @return int
628628
* @access public
629629
*/
630630
public function content_bbcode_enabled()
631631
{
632-
return ($this->data['page_content_bbcode_options'] & OPTION_FLAG_BBCODE);
632+
return isset($this->data['page_content_bbcode_options']) ? $this->data['page_content_bbcode_options'] & OPTION_FLAG_BBCODE : 0;
633633
}
634634

635635
/**
@@ -663,12 +663,12 @@ public function content_disable_bbcode()
663663
/**
664664
* Check if magic_url is enabled on the content
665665
*
666-
* @return bool
666+
* @return int
667667
* @access public
668668
*/
669669
public function content_magic_url_enabled()
670670
{
671-
return ($this->data['page_content_bbcode_options'] & OPTION_FLAG_LINKS);
671+
return isset($this->data['page_content_bbcode_options']) ? $this->data['page_content_bbcode_options'] & OPTION_FLAG_LINKS : 0;
672672
}
673673

674674
/**
@@ -702,12 +702,12 @@ public function content_disable_magic_url()
702702
/**
703703
* Check if smilies are enabled on the content
704704
*
705-
* @return bool
705+
* @return int
706706
* @access public
707707
*/
708708
public function content_smilies_enabled()
709709
{
710-
return ($this->data['page_content_bbcode_options'] & OPTION_FLAG_SMILIES);
710+
return isset($this->data['page_content_bbcode_options']) ? $this->data['page_content_bbcode_options'] & OPTION_FLAG_SMILIES : 0;
711711
}
712712

713713
/**

tests/controller/page_main_controller_test.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getDataSet()
4545
return $this->createXMLDataSet(__DIR__ . '/../entity/fixtures/page.xml');
4646
}
4747

48-
public function setUp(): void
48+
protected function setUp(): void
4949
{
5050
parent::setUp();
5151

@@ -82,7 +82,7 @@ public function setUp(): void
8282
$this->controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
8383
->disableOriginalConstructor()
8484
->getMock();
85-
$this->controller_helper->expects($this->atMost(1))
85+
$this->controller_helper->expects(self::atMost(1))
8686
->method('render')
8787
->willReturnCallback(function ($template_file, $page_title = '', $status_code = 200, $display_online_list = false) {
8888
return new \Symfony\Component\HttpFoundation\Response($template_file, $status_code);
@@ -136,9 +136,9 @@ public function test_display($route, $status_code, $page_content, $user_id)
136136
$controller = $this->get_controller();
137137

138138
$response = $controller->display($route);
139-
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
140-
$this->assertEquals($status_code, $response->getStatusCode());
141-
$this->assertEquals($page_content, $response->getContent());
139+
self::assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
140+
self::assertEquals($status_code, $response->getStatusCode());
141+
self::assertEquals($page_content, $response->getContent());
142142
}
143143

144144
/**
@@ -169,12 +169,12 @@ public function test_display_fails($route, $status_code, $page_content, $user_id
169169
try
170170
{
171171
$controller->display($route);
172-
$this->fail('The expected \phpbb\exception\http_exception was not thrown');
172+
self::fail('The expected \phpbb\exception\http_exception was not thrown');
173173
}
174174
catch (\phpbb\exception\http_exception $exception)
175175
{
176-
$this->assertEquals($status_code, $exception->getStatusCode());
177-
$this->assertEquals($page_content, $exception->getMessage());
176+
self::assertEquals($status_code, $exception->getStatusCode());
177+
self::assertEquals($page_content, $exception->getMessage());
178178
}
179179
}
180180
}

tests/entity/page_entity_base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getDataSet()
4242
return $this->createXMLDataSet(__DIR__ . '/fixtures/page.xml');
4343
}
4444

45-
public function setUp(): void
45+
protected function setUp(): void
4646
{
4747
parent::setUp();
4848

tests/entity/page_entity_content_test.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
class page_entity_content_test extends page_entity_base
1717
{
18-
public function setUp(): void
18+
protected function setUp(): void
1919
{
2020
parent::setUp();
2121

@@ -77,7 +77,7 @@ public function test_content($content)
7777
$result = $entity->set_content($content);
7878

7979
// Assert the returned value is what we expect
80-
$this->assertInstanceOf('\phpbb\pages\entity\page', $result);
80+
self::assertInstanceOf('\phpbb\pages\entity\page', $result);
8181

8282
// We start with all options set to false
8383
$enable_bbcode = $enable_magic_url = $enable_smilies = $censor_text = false;
@@ -124,9 +124,9 @@ public function test_content($content)
124124
// Get what we're expecting from
125125
$test = $this->content_test_helper($content, $enable_bbcode, $enable_magic_url, $enable_smilies, $censor_text);
126126

127-
$this->assertSame($test['edit'], $entity->get_content_for_edit());
127+
self::assertSame($test['edit'], $entity->get_content_for_edit());
128128

129-
$this->assertSame($test['display'], $entity->get_content_for_display($censor_text));
129+
self::assertSame($test['display'], $entity->get_content_for_display($censor_text));
130130

131131
// Increment the options
132132
$i++;
@@ -201,12 +201,12 @@ public function test_html_content($content)
201201
$result = $entity->set_content($encoded_content);
202202

203203
// Assert the returned value is what we expect
204-
$this->assertInstanceOf('\phpbb\pages\entity\page', $result);
204+
self::assertInstanceOf('\phpbb\pages\entity\page', $result);
205205

206206
// Assert that the content for edit matches the original encoded content
207-
$this->assertSame($encoded_content, $entity->get_content_for_edit());
207+
self::assertSame($encoded_content, $entity->get_content_for_edit());
208208

209209
// Assert that the content for display matches HTML decoded content
210-
$this->assertSame($content, $entity->get_content_for_display());
210+
self::assertSame($content, $entity->get_content_for_display());
211211
}
212212
}

tests/entity/page_entity_description_test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function test_description($description, $expected)
5050
$result = $entity->set_description($description);
5151

5252
// Assert the returned value is what we expect
53-
$this->assertInstanceOf('\phpbb\pages\entity\page', $result);
53+
self::assertInstanceOf('\phpbb\pages\entity\page', $result);
5454

5555
// Assert that the description matches what's expected
56-
$this->assertSame($expected, $entity->get_description());
56+
self::assertSame($expected, $entity->get_description());
5757
}
5858

5959
/**
@@ -77,10 +77,11 @@ public function description_fails_test_data()
7777
* Test setting invalid data on the description which should throw an exception
7878
*
7979
* @dataProvider description_fails_test_data
80-
* @expectedException \phpbb\pages\exception\base
8180
*/
8281
public function test_description_fails($description)
8382
{
83+
$this->expectException(\phpbb\pages\exception\base::class);
84+
8485
// Setup the entity class
8586
$entity = $this->get_page_entity();
8687

tests/entity/page_entity_iconfont_test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function test_icon_font($input, $expected)
4848
$result = $entity->set_icon_font($input);
4949

5050
// Assert the returned value is what we expect
51-
$this->assertInstanceOf('\phpbb\pages\entity\page', $result);
51+
self::assertInstanceOf('\phpbb\pages\entity\page', $result);
5252

5353
// Assert that the input matches what's expected
54-
$this->assertSame($expected, $entity->get_icon_font());
54+
self::assertSame($expected, $entity->get_icon_font());
5555
}
5656

5757
/**
@@ -78,10 +78,11 @@ public function icon_font_fails_test_data()
7878
* Test setting invalid icon font which should throw an exception
7979
*
8080
* @dataProvider icon_font_fails_test_data
81-
* @expectedException \phpbb\pages\exception\base
8281
*/
8382
public function test_icon_font_fails($input)
8483
{
84+
$this->expectException(\phpbb\pages\exception\base::class);
85+
8586
// Setup the entity class
8687
$entity = $this->get_page_entity();
8788

tests/entity/page_entity_id_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public function test_id($data, $expected)
5858
$entity->import($data);
5959

6060
// Assert that the id matches what is expected
61-
$this->assertEquals($expected, $entity->get_id());
61+
self::assertEquals($expected, $entity->get_id());
6262
}
6363
}

tests/entity/page_entity_import_test.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function test_import($data)
4747
$result = $entity->import($data);
4848

4949
// Assert the returned value is what we expect
50-
$this->assertInstanceOf('\phpbb\pages\entity\page', $result);
50+
self::assertInstanceOf('\phpbb\pages\entity\page', $result);
5151

5252
// Map the fields to the getters
5353
$map = array(
@@ -66,7 +66,7 @@ public function test_import($data)
6666
// what we saved
6767
foreach ($map as $field => $function)
6868
{
69-
$this->assertEquals($data[$field], $entity->$function());
69+
self::assertEquals($data[$field], $entity->$function());
7070
}
7171
}
7272

@@ -145,10 +145,11 @@ public function import_test_fail_data()
145145
* Test importing data which will cause exceptions
146146
*
147147
* @dataProvider import_test_fail_data
148-
* @expectedException \phpbb\pages\exception\base
149148
*/
150149
public function test_import_fail($data)
151150
{
151+
$this->expectException(\phpbb\pages\exception\base::class);
152+
152153
// Setup the entity class
153154
$entity = $this->get_page_entity();
154155

tests/entity/page_entity_insert_test.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ public function test_insert()
5656
;
5757

5858
// Assert the returned value is what we expect
59-
$this->assertInstanceOf('\phpbb\pages\entity\page', $result);
59+
self::assertInstanceOf('\phpbb\pages\entity\page', $result);
6060

6161
// Assert that the new page_id was created
62-
$this->assertEquals($data['page_id'], $result->get_id());
62+
self::assertEquals($data['page_id'], $result->get_id());
6363

6464
// Reload the inserted data from the db
6565
$result = $entity->load($result->get_id());
6666

6767
// Assert the returned value is what we expect
68-
$this->assertInstanceOf('\phpbb\pages\entity\page', $result);
68+
self::assertInstanceOf('\phpbb\pages\entity\page', $result);
6969

7070
// Map the fields to the getters
7171
$map = array(
@@ -85,18 +85,18 @@ public function test_insert()
8585
// what we saved
8686
foreach ($map as $field => $function)
8787
{
88-
$this->assertEquals($data[$field], $entity->$function());
88+
self::assertEquals($data[$field], $entity->$function());
8989
}
9090
}
9191

9292
/**
9393
* Try inserting a page that already exists into the database
9494
* Entities with an existing page_id will fail to insert
95-
*
96-
* @expectedException \phpbb\pages\exception\out_of_bounds
9795
*/
9896
public function test_insert_fails()
9997
{
98+
$this->expectException(\phpbb\pages\exception\out_of_bounds::class);
99+
100100
// Load some import test data
101101
$import_data = $this->get_import_data();
102102

0 commit comments

Comments
 (0)