Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage for adding stories #18

Merged
merged 4 commits into from Dec 23, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/.gitignore
@@ -0,0 +1,2 @@
*.xdebug
pear2coverage.db
33 changes: 27 additions & 6 deletions tests/Newsletter/addStory.phpt
@@ -1,15 +1,36 @@
--TEST--
Add story to newsletter test
--SKIPIF--
skip
--POST--
foo=&
--FILE--
<?php
require dirname(__FILE__) . '/../../www/config.inc.php';
$controller = new UNL_ENews_Controller();
require dirname(__FILE__) . '/../setup.inc.php';

$newsletter = new UNL_ENews_Newsletter();
$newsletter->newsroom_id = 1;
$newsletter->release_date = date('Y-m-d H:i:s', strtotime('tomorrow'));
$newsletter->subject = 'My big newsletter';

if (!$newsletter->save()) {
echo 'Should have saved and it did not';
}

// Now let's get a story
include __DIR__ . '/../Stories/insertStory.inc.php';

if (!$newsletter->addStory($story)) {
echo 'Should have added and it did not';
}

if (!$newsletter->hasStory($story)) {
echo 'Newsletter should have this story and it does not';
}

?>
===DONE===
--CLEAN--
<?php
require dirname(__FILE__) . '/../setup.inc.php';
$mysql = UNL_ENews_Controller::getDB();
$mysql->query('DELETE FROM newsletters WHERE subject="My big newsletter";');
?>
--EXPECT--
===DONE===
18 changes: 18 additions & 0 deletions tests/Stories/addStory.phpt
@@ -0,0 +1,18 @@
--TEST--
Add a story
--FILE--
<?php
require dirname(__FILE__) . '/../setup.inc.php';

include __DIR__ . '/insertStory.inc.php';

?>
===DONE===
--CLEAN--
<?php
require dirname(__FILE__) . '/../setup.inc.php';
$mysql = UNL_ENews_Controller::getDB();
$mysql->query('DELETE FROM stories WHERE title="My big news story";');
?>
--EXPECT--
===DONE===
11 changes: 11 additions & 0 deletions tests/Stories/insertStory.inc.php
@@ -0,0 +1,11 @@
<?php
$story = new UNL_ENews_Story();
$story->title = "My big news story";
$story->description = "Here's the basic info about the story";
$story->uid_created = UNL_ENews_Controller::getUser()->uid;
$story->sponsor = "Student Affairs";
$story->presentation_id = UNL_ENews_Story_Presentation::getDefault('news')->id;

if (!$story->save()) {
echo 'Should have saved and it did not';
}
9 changes: 9 additions & 0 deletions www/js/submission.js
Expand Up @@ -120,6 +120,8 @@ var submission = function($) {
var imgString = '<img onload="if(submission.announcementType != \'ad\')submission.loadImageCrop(\'4:3\');" src="'+ENEWS_HOME+'?view=file&id='+$(this).val()+'" alt="Uploaded Image" />';
$('#upload_area').html(imgString);
$('#sampleLayoutImage').html('Select Thumbnail Below');
$('#img_description_label').append('<span class="required">*</span>');
$('#file_description').addClass('required').removeAttr('disabled');
ajaxUpload.removeIframe();
});

Expand Down Expand Up @@ -166,6 +168,8 @@ var submission = function($) {
function(data,status) {
$('#sampleLayoutImage img').attr('src', '');
$('#upload_area img').attr('src', '');
$('#img_description_label span.required').remove();
$('#file_description').removeClass('required').attr('disabled','disabled');
submission.loadImageCrop();
submission.updatePreview();
}
Expand Down Expand Up @@ -445,6 +449,11 @@ var submission = function($) {
if (validate) {
var message = '';
$('input.required,textarea.required').each(function() {
if ($(this).attr('disabled') !== undefined) {
// Field is disabled, user couldn't enter text
return;
}

if (this.value == '') {
message = 'Required fields cannot be left blank';
}
Expand Down
2 changes: 1 addition & 1 deletion www/templates/email/ENews/Newsletter.tpl.php
Expand Up @@ -75,7 +75,7 @@
</tr>
<tr height="25">
<td colspan="2" style="line-height:0;" height="25">
<img src="http://www.unl.edu/wdn/templates_3.0/images/email/email2_06.gif" width="556" height="25" alt="Red bar seperator" />
<img src="http://www.unl.edu/wdn/templates_3.0/images/email/email2_06.gif" width="556" height="25" alt="Header and body separator" />
</td>
</tr>
<tr>
Expand Down
10 changes: 6 additions & 4 deletions www/templates/html/ENews/Submission/ImageForm.tpl.php
Expand Up @@ -8,14 +8,16 @@
<input id="image" name="image" type="file" />
</li>
<li>
<label for="file_description" id="img_description_label">Image Description<span class="required">*</span><span class="helper">To be used as a caption on the web view</span></label>
<label for="file_description" id="img_description_label">Image Description
<?php
$disabled = 'disabled="disabled"';
if (isset($originalImage)) {
$disabled = '';
if (!empty($originalImage)) {
$disabled = 'class="required"';
echo '<span class="required">*</span>';
}
?>
<input id="file_description" name="file_description" <?php echo $disabled; ?> type="text" class="required" value="<?php echo getValue($originalImage, 'description'); ?>" />
<span class="helper">To be used as a caption on the web view</span></label>
<input id="file_description" name="file_description" <?php echo $disabled; ?> type="text" value="<?php echo getValue($originalImage, 'description'); ?>" />
</li>
</ol>

Expand Down