Skip to content

Loading…

Improve test coverage for adding stories #18

Merged
merged 4 commits into from

1 participant

@saltybeagle
University of Nebraska–Lincoln member

This improves test coverage by completing the test for adding a story and a new test for adding a story to a newsletter.

@saltybeagle saltybeagle merged commit 0b0276f into unl:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 30, 2011
  1. @saltybeagle

    Add test for adding a story

    saltybeagle committed
  2. @saltybeagle

    Implement ->addStory test

    saltybeagle committed
Commits on Dec 22, 2011
  1. @saltybeagle
  2. @saltybeagle
View
2 tests/.gitignore
@@ -0,0 +1,2 @@
+*.xdebug
+pear2coverage.db
View
33 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===
View
18 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===
View
11 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';
+}
View
9 www/js/submission.js
@@ -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();
});
@@ -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();
}
@@ -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';
}
View
2 www/templates/email/ENews/Newsletter.tpl.php
@@ -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>
View
10 www/templates/html/ENews/Submission/ImageForm.tpl.php
@@ -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>
Something went wrong with that request. Please try again.