Skip to content

Commit

Permalink
Fixed problem with Expires getting null value when publishing. Now if…
Browse files Browse the repository at this point in the history
… Expires has a value it will be set unless re-publishing an expired item.
  • Loading branch information
staryd authored and bherila committed Nov 18, 2017
1 parent 0d806dc commit 60cb5fb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
Expand Up @@ -15,8 +15,12 @@ public override void Process(CommandContext state)
state.Content.Published = Utility.CurrentTime();
}

if (state.Content.Expires.HasValue)
state.Content.Expires = null;
if (Binding.GetUpdatedDetails(state).Contains("Expires"))
return;

if (state.Content.Expires.HasValue && state.Content.Expires.Value < Utility.CurrentTime())
state.Content.Expires = null;

}
}
}
}
36 changes: 36 additions & 0 deletions src/Framework/Tests/Workflow/CommandFactory_PublishingTests.cs
Expand Up @@ -85,6 +85,42 @@ public void CanMoveItem_ToBefore_Item()
Assert.That(item.Children[1], Is.EqualTo(child));
}

[Test]
public void Expires_IsClearedIfExpiresHasPassed()
{
item.Expires = N2.Utility.CurrentTime().AddDays(-1);
var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);
var command = CreateCommand(context);
dispatcher.Execute(command, context);

Assert.That(context.Content.Expires, Is.Null);
}

[Test]
public void Expires_IsNotClearedIfExpiresInFuture()
{
var expireDate = N2.Utility.CurrentTime().AddDays(10);
item.Expires = expireDate;
var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);
var command = CreateCommand(context);
dispatcher.Execute(command, context);

Assert.That(context.Content.Expires, Is.EqualTo(expireDate));
}

[Test]
public void Expires_IsNotClearedIfExpiresHasPassedButIsEdited()
{
var expireDate = N2.Utility.CurrentTime().AddDays(-1);
item.Expires = expireDate;
var context = new CommandContext(definitions.GetDefinition(item.GetContentType()), item, Interfaces.Editing, CreatePrincipal("admin"), nullBinder, nullValidator);
context.Parameters.Add("UpdatedDetailsKey", new System.Collections.Generic.List<string> { "Expires" });
var command = CreateCommand(context);
dispatcher.Execute(command, context);

Assert.That(context.Content.Expires, Is.EqualTo(expireDate));
}

//What's the point, really?
//[Test]
//public void Sets_PublishedDate()
Expand Down

0 comments on commit 60cb5fb

Please sign in to comment.