Skip to content

Commit

Permalink
Fix bad fixture in topic test, and PHP 7.4 notices.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Dec 15, 2023
1 parent fddec7b commit 8f11505
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
10 changes: 6 additions & 4 deletions classes/SectionView/SectionView.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,13 @@ protected function display_section_or_speech($args = array()) {

$data = $this->setTitleAndAlertText($data, $subsection_title);

$data['debate_time_human'] = format_time($first_speech['htime'], TIMEFORMAT);
$data['debate_day_human'] = format_date($first_speech['hdate'], LONGDATEFORMAT);
if ($first_speech) {
$data['debate_time_human'] = format_time($first_speech['htime'], TIMEFORMAT);
}
$data['debate_day_human'] = format_date($data['info']['date'], LONGDATEFORMAT);

$URL = new \MySociety\TheyWorkForYou\Url($this->list->listpage);
$URL->insert(array('d' => $first_speech['hdate']));
$URL->insert(array('d' => $data['info']['date']));
$URL->remove(array('id'));
$data['debate_day_link'] = $URL->generate();

Expand All @@ -261,7 +263,7 @@ protected function display_section_or_speech($args = array()) {
"%s %s%s %s",
$data['intro'],
$this->location,
$data['debate_time_human'] ? " at $data[debate_time_human]" : '',
isset($data['debate_time_human']) ? " at $data[debate_time_human]" : '',
$data['debate_day_human']
));

Expand Down
8 changes: 4 additions & 4 deletions tests/TopicsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testTopicPage() {
$page = $this->fetch_topic_page(array('topic' => 'nhs', 'url' => '/topic/nhs'));
$this->assertContains('NHS', $page);
$this->assertNotContains('Welfare', $page);
$this->assertContains('Test Hansard Section', $page);
$this->assertContains('Test Hansard SubSection', $page);
$this->assertNotContains('foundation hospitals', $page);
$this->assertNotContains('Sign up for email alerts', $page);
}
Expand All @@ -50,15 +50,15 @@ public function testTopicPageWithSearch() {
$page = $this->fetch_topic_page(array('topic' => 'welfare', 'url' => '/topic/welfare'));
$this->assertContains('Welfare', $page);
$this->assertNotContains('NHS', $page);
$this->assertNotContains('Test Hansard Section', $page);
$this->assertNotContains('Test Hansard SubSection', $page);
}

public function testTopicPageWithMP() {
$page = $this->fetch_topic_page(array('pc' => 'SW1 1AA', 'topic' => 'nhs', 'url' => '/topic/nhs'));
$this->assertContains('NHS', $page);
$this->assertNotContains('Welfare', $page);
$this->assertContains('Test Current-MP', $page);
$this->assertContains('Test Hansard Section', $page);
$this->assertContains('Test Hansard SubSection', $page);
$this->assertContains('foundation hospitals', $page);
}

Expand All @@ -77,6 +77,6 @@ public function testTopicPageRecentVotes() {

public function testTopicPageContent() {
$page = $this->fetch_topic_page(array('topic' => 'nhs', 'url' => '/topic/nhs'));
$this->assertContains('Test Hansard Section', $page);
$this->assertContains('Test Hansard SubSection', $page);
}
}
38 changes: 36 additions & 2 deletions tests/_fixtures/topics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
<field name="epobject_id">1</field>
<field name="body">Test Hansard Section</field>
</row>
<row>
<field name="epobject_id">2</field>
<field name="body">Test Hansard SubSection</field>
</row>
<row>
<field name="epobject_id">3</field>
<field name="body">Test Hansard Body</field>
</row>
</table_data>
<table_data name="future">
</table_data>
Expand All @@ -48,13 +56,39 @@
<row>
<field name="epobject_id">1</field>
<field name="gid">com.theyworkforyou/test/hansard/1</field>
<field name="htype">11</field>
<field name="htype">10</field>
<field name="hdate">2014-01-01</field>
<field name="htime">10:00</field>
<field name="hpos">1</field>
<field name="person_id">0</field>
<field name="major">1</field>
<field name="minor">0</field>
<field name="section_id">0</field>
<field name="subsection_id">0</field>
</row>
<row>
<field name="epobject_id">2</field>
<field name="gid">com.theyworkforyou/test/hansard/2</field>
<field name="htype">11</field>
<field name="hdate">2014-01-01</field>
<field name="htime">10:00</field>
<field name="hpos">2</field>
<field name="person_id">0</field>
<field name="major">1</field>
<field name="minor">0</field>
<field name="section_id">1</field>
<field name="subsection_id">0</field>
</row>
<row>
<field name="epobject_id">3</field>
<field name="gid">com.theyworkforyou/test/hansard/3</field>
<field name="htype">12</field>
<field name="hdate">2014-01-01</field>
<field name="htime">10:00</field>
<field name="hpos">3</field>
<field name="person_id">0</field>
<field name="major">1</field>
<field name="minor">0</field>
<field name="section_id">1</field>
<field name="subsection_id">2</field>
</row>
Expand Down Expand Up @@ -417,7 +451,7 @@
<table_data name="topic_epobjects">
<row>
<field name="topic_key">1</field>
<field name="epobject_id">1</field>
<field name="epobject_id">2</field>
</row>
</table_data>
<table_data name="users">
Expand Down
18 changes: 12 additions & 6 deletions www/includes/easyparliament/hansardlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2810,9 +2810,8 @@ public function _get_data_by_featured_gid($args=array()) {
// If this is a subsection, we're going to prepend the title
// of the parent section, so let's get that.
$parentbody = '';
if ($item_data['htype'] == 11 || $item_data['htype'] == 12) {
$r = $this->db->query("SELECT sec.body as sec_body, sec.title as sec_title,
sub.body as sub_body, sub.title as sub_title
if ($item_data['htype'] == 12) {
$r = $this->db->query("SELECT sec.body as sec_body, sub.body as sub_bod
FROM epobject sec, epobject sub
WHERE sec.epobject_id = :section_id
AND sub.epobject_id = :subsection_id",
Expand All @@ -2821,13 +2820,20 @@ public function _get_data_by_featured_gid($args=array()) {
':subsection_id' => $item_data['subsection_id'],
)
)->first();
$section_body = $r['sec_body'];
$section_body = $r['sec_body'];
$subsection_body = $r['sub_body'];
if ( $section_body && $subsection_body ) {
if ( $section_body != $subsection_body ) {
$parentbody = "$section_body : $subsection_body";
} else {
$parentbody = "$section_body$subsection_body";
$parentbody = $section_body;
}
} elseif ($item_data['htype'] == 11) {
$r = $this->db->query("SELECT body FROM epobject WHERE epobject_id = :section_id",
array(
':section_id' => $item_data['section_id'],
)
)->first();
$parentbody = $r['body'];
} else if ( $item_data['htype'] == 10 ) {
$parentbody = $body;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<h1><?= $heading ?></h1>
<p class="lead">
<?= $intro ?> <?= $location ?>
<?php if ($debate_time_human) {
<?php if (isset($debate_time_human)) {
printf(gettext("at %s"), $debate_time_human);
}
print ' ';
Expand Down

0 comments on commit 8f11505

Please sign in to comment.