[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/webroot/rsrc/externals/javelin/lib/__tests__/ -> Cookie.js (source)

   1  /**
   2   * @requires javelin-cookie
   3   */
   4  
   5  /*
   6   * These all are hope-and-pray tests because cookies have such a piss poor
   7   * API in HTTP and offer so little insight from JS. This is just a
   8   * supplement to the battle testing the cookie library has.
   9   */
  10  describe('Javelin Cookie', function() {
  11  
  12    it('should create a cookie string with the correct format', function() {
  13      var doc = { cookie : null };
  14      var c = new JX.Cookie('omnom');
  15      c.setValue('nommy');
  16      c.setDaysToLive(5);
  17      c.setTarget(doc);
  18      c.setPath('/');
  19      c.setSecure(true);
  20      c.write();
  21  
  22      // Should be something like:
  23      // omnom=nommy; path=/; expires=Sat, 10 Dec 2011 05:00:34 GMT; Secure;
  24  
  25      expect(doc.cookie).toMatch(
  26        /^omnom=nommy;\sPath=\/;\sExpires=[^;]+;\sSecure;/);
  27    });
  28  
  29    it('should properly encode and decode special chars in cookie values',
  30      function() {
  31        var value = '!@#$%^&*()?+|/=\\{}[]<>';
  32        var doc = { cookie : null };
  33        var c = new JX.Cookie('data');
  34        c.setTarget(doc);
  35        c.setValue(value);
  36        c.write();
  37  
  38        var data = doc.cookie.substr(0, doc.cookie.indexOf(';'));
  39  
  40        // Make sure the raw value is all escaped
  41        expect(data).toEqual(
  42        'data=!%40%23%24%25%5E%26*()%3F%2B%7C%2F%3D%5C%7B%7D%5B%5D%3C%3E');
  43  
  44        // Make sure the retrieved value is all unescaped
  45        expect(c.read()).toEqual(value);
  46      });
  47  
  48  });


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1